-
Notifications
You must be signed in to change notification settings - Fork 152
Added _ips #196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Added _ips #196
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -434,6 +434,25 @@ type ScalewayGetSecurityGroup struct { | |
SecurityGroups ScalewaySecurityGroups `json:"security_group"` | ||
} | ||
|
||
type ScalewayIPDefinition struct { | ||
Organization string `json:"organization"` | ||
Reverse string `json:"reverse"` | ||
ID string `json:"id"` | ||
Server struct { | ||
Identifier string `json:"id,omitempty"` | ||
Name string `json:"name,omitempty"` | ||
} `json:"server,omitempty"` | ||
Address string `json:"address"` | ||
} | ||
|
||
type ScalewayGetIPS struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported type ScalewayGetIPS should have comment or be unexported |
||
IPS []ScalewayIPDefinition `json:"ips"` | ||
} | ||
|
||
type ScalewayGetIP struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported type ScalewayGetIP should have comment or be unexported |
||
IP ScalewayIPDefinition `json:"ip"` | ||
} | ||
|
||
// ScalewaySecurityGroup represents a Scaleway security group | ||
type ScalewaySecurityGroup struct { | ||
// Identifier is a unique identifier for the security group | ||
|
@@ -1872,6 +1891,133 @@ func (s *ScalewayAPI) GetASecurityGroup(groupsID string) (*ScalewayGetSecurityGr | |
return &securityGroups, nil | ||
} | ||
|
||
// GetIPS returns a ScalewayGetIPS | ||
func (s *ScalewayAPI) GetIPS() (*ScalewayGetIPS, error) { | ||
resp, err := s.GetResponse("ips") | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer resp.Body.Close() | ||
|
||
var ips ScalewayGetIPS | ||
decoder := json.NewDecoder(resp.Body) | ||
err = decoder.Decode(&ips) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &ips, nil | ||
} | ||
|
||
// NewIP returns a new IP | ||
func (s *ScalewayAPI) NewIP() (*ScalewayGetIP, error) { | ||
var orga struct { | ||
Organization string `json:"organization"` | ||
} | ||
orga.Organization = s.Organization | ||
resp, err := s.PostResponse("ips", orga) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer resp.Body.Close() | ||
|
||
// Succeed POST code | ||
if resp.StatusCode == 201 { | ||
var ip ScalewayGetIP | ||
decoder := json.NewDecoder(resp.Body) | ||
err = decoder.Decode(&ip) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &ip, nil | ||
} | ||
var error ScalewayAPIError | ||
decoder := json.NewDecoder(resp.Body) | ||
err = decoder.Decode(&error) | ||
if err != nil { | ||
return nil, err | ||
} | ||
error.StatusCode = resp.StatusCode | ||
error.Debug() | ||
return nil, error | ||
} | ||
|
||
// AttachIP attachs an IP to a server | ||
func (s *ScalewayAPI) AttachIP(ipID, serverID string) error { | ||
var update struct { | ||
Address string `json:"address"` | ||
ID string `json:"id"` | ||
Reverse *string `json:"reverse"` | ||
Organization string `json:"organization"` | ||
Server string `json:"server"` | ||
} | ||
|
||
ip, err := s.GetIP(idIP) | ||
if err != nil { | ||
return err | ||
} | ||
update.Address = ip.IP.Address | ||
update.ID = ip.IP.ID | ||
update.Organization = ip.IP.Organization | ||
update.Server = serverID | ||
resp, err := s.PutResponse(fmt.Sprintf("ips/%s", ipID), update) | ||
if err != nil { | ||
return err | ||
} | ||
if resp.StatusCode == 200 { | ||
return nil | ||
} | ||
var error ScalewayAPIError | ||
decoder := json.NewDecoder(resp.Body) | ||
err = decoder.Decode(&error) | ||
if err != nil { | ||
return err | ||
} | ||
error.StatusCode = resp.StatusCode | ||
error.Debug() | ||
return error | ||
} | ||
|
||
// DeleteIP deletes an IP | ||
func (s *ScalewayAPI) DeleteIP(ipID string) error { | ||
resp, err := s.DeleteResponse(fmt.Sprintf("ips/%s", ipID)) | ||
if err != nil { | ||
return err | ||
} | ||
defer resp.Body.Close() | ||
|
||
// Succeed PUT code | ||
if resp.StatusCode == 204 { | ||
return nil | ||
} | ||
|
||
var error ScalewayAPIError | ||
decoder := json.NewDecoder(resp.Body) | ||
err = decoder.Decode(&error) | ||
if err != nil { | ||
return err | ||
} | ||
error.StatusCode = resp.StatusCode | ||
error.Debug() | ||
return error | ||
} | ||
|
||
// GetIP returns a ScalewayGetIP | ||
func (s *ScalewayAPI) GetIP(ipID string) (*ScalewayGetIP, error) { | ||
resp, err := s.GetResponse(fmt.Sprintf("ips/%s", ipID)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer resp.Body.Close() | ||
|
||
var ip ScalewayGetIP | ||
decoder := json.NewDecoder(resp.Body) | ||
err = decoder.Decode(&ip) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &ip, nil | ||
} | ||
|
||
// GetBootscriptID returns exactly one bootscript matching or dies | ||
func (s *ScalewayAPI) GetBootscriptID(needle string) string { | ||
// Parses optional type prefix, i.e: "bootscript:name" -> "name" | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,4 +46,5 @@ var Commands = []*Command{ | |
cmdFlushCache, | ||
cmdPatch, | ||
cmdSecurityGroups, | ||
cmdIPS, | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported type ScalewayIPDefinition should have comment or be unexported