func (gsp *genericServersProvider) CreateFloatingIp(pool string) (FloatingIp, error) { fip := new(FloatingIp) err := gsp.context.WithReauth(gsp.access, func() error { url := gsp.endpoint + "/os-floating-ips" return perigee.Post(url, perigee.Options{ CustomClient: gsp.context.httpClient, ReqBody: map[string]string{ "pool": pool, }, Results: &struct { FloatingIp **FloatingIp `json:"floating_ip"` }{&fip}, MoreHeaders: map[string]string{ "X-Auth-Token": gsp.access.AuthToken(), }, }) }) if fip.Ip == "" { return *fip, errors.New("Error creating floating IP") } return *fip, err }
// papersPlease contains the common logic between authentication and re-authentication. // The name, obviously a joke on the process of authentication, was chosen because // of how many other entities exist in the program containing the word Auth or Authorization. // I didn't need another one. func (c *Context) papersPlease(p Provider, options AuthOptions) (*Access, error) { var access *Access if (options.Username == "") || (options.Password == "" && options.ApiKey == "") { return nil, ErrCredentials } err := perigee.Post(p.AuthEndpoint, perigee.Options{ CustomClient: c.httpClient, ReqBody: &AuthContainer{ Auth: getAuthCredentials(options), }, Results: &struct { Access **Access `json:"access"` }{ &access, }, }) if err == nil { access.options = options access.provider = p access.context = c } return access, err }
// See the CloudServersProvider interface for details func (gsp *genericServersProvider) UnrescueServer(id string) error { return gsp.context.WithReauth(gsp.access, func() error { url := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id) return perigee.Post(url, perigee.Options{ ReqBody: &struct { Unrescue *int `json:"unrescue"` }{nil}, MoreHeaders: map[string]string{ "X-Auth-Token": gsp.access.AuthToken(), }, OkCodes: []int{202}, }) }) }
func (gsp *genericServersProvider) AssociateFloatingIp(serverId string, ip FloatingIp) error { return gsp.context.WithReauth(gsp.access, func() error { ep := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, serverId) return perigee.Post(ep, perigee.Options{ CustomClient: gsp.context.httpClient, ReqBody: map[string](map[string]string){ "addFloatingIp": map[string]string{"address": ip.Ip}, }, MoreHeaders: map[string]string{ "X-Auth-Token": gsp.access.AuthToken(), }, OkCodes: []int{202}, }) }) }
// See the CloudServersProvider interface for details. func (gsp *genericServersProvider) CreateDefaultSGRule(r SGRule) (*SGRule, error) { var sgr *SGRule err := gsp.context.WithReauth(gsp.access, func() error { ep := fmt.Sprintf("%s/os-security-group-default-rules", gsp.endpoint) return perigee.Post(ep, perigee.Options{ MoreHeaders: map[string]string{ "X-Auth-Token": gsp.access.AuthToken(), }, Results: &struct{ Security_group_default_rule **SGRule }{&sgr}, ReqBody: struct { Security_group_default_rule SGRule `json:"security_group_default_rule"` }{r}, }) }) return sgr, err }
func (gsp *genericServersProvider) CreateKeyPair(nkp NewKeyPair) (KeyPair, error) { var kp KeyPair err := gsp.context.WithReauth(gsp.access, func() error { url := gsp.endpoint + "/os-keypairs" return perigee.Post(url, perigee.Options{ ReqBody: &struct { KeyPair *NewKeyPair `json:"keypair"` }{&nkp}, CustomClient: gsp.context.httpClient, Results: &struct{ KeyPair *KeyPair }{&kp}, MoreHeaders: map[string]string{ "X-Auth-Token": gsp.access.AuthToken(), }, }) }) return kp, err }
// See the CloudServersProvider interface for details. func (gsp *genericServersProvider) CreateSecurityGroup(desired SecurityGroup) (*SecurityGroup, error) { var actual *SecurityGroup err := gsp.context.WithReauth(gsp.access, func() error { ep := fmt.Sprintf("%s/os-security-groups", gsp.endpoint) return perigee.Post(ep, perigee.Options{ ReqBody: struct { AddSecurityGroup SecurityGroup `json:"security_group"` }{desired}, MoreHeaders: map[string]string{ "X-Auth-Token": gsp.access.AuthToken(), }, Results: &struct { SecurityGroup **SecurityGroup `json:"security_group"` }{&actual}, }) }) return actual, err }
// See the CloudServersProvider interface for details. func (gsp *genericServersProvider) RebuildServer(id string, ns NewServer) (*Server, error) { var s *Server err := gsp.context.WithReauth(gsp.access, func() error { ep := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id) return perigee.Post(ep, perigee.Options{ ReqBody: &struct { Rebuild *NewServer `json:"rebuild"` }{&ns}, Results: &struct{ Server **Server }{&s}, MoreHeaders: map[string]string{ "X-Auth-Token": gsp.access.AuthToken(), }, OkCodes: []int{202}, }) }) return s, err }
// See the CloudServersProvider interface for details func (gsp *genericServersProvider) RescueServer(id string) (string, error) { var pw *string err := gsp.context.WithReauth(gsp.access, func() error { url := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id) return perigee.Post(url, perigee.Options{ ReqBody: &struct { Rescue string `json:"rescue"` }{"none"}, MoreHeaders: map[string]string{ "X-Auth-Token": gsp.access.AuthToken(), }, Results: &struct { AdminPass **string `json:"adminPass"` }{&pw}, }) }) return *pw, err }
// See the CloudServersProvider interface for details. func (gsp *genericServersProvider) CreateServer(ns NewServer) (*NewServer, error) { var s *NewServer err := gsp.context.WithReauth(gsp.access, func() error { ep := gsp.endpoint + "/servers" return perigee.Post(ep, perigee.Options{ ReqBody: &struct { Server *NewServer `json:"server"` }{&ns}, Results: &struct{ Server **NewServer }{&s}, MoreHeaders: map[string]string{ "X-Auth-Token": gsp.access.AuthToken(), }, OkCodes: []int{202}, }) }) return s, err }
// See the CloudServersProvider interface for details. func (gsp *genericServersProvider) ResizeServer(id, newName, newFlavor, newDiskConfig string) error { err := gsp.context.WithReauth(gsp.access, func() error { url := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id) rr := ResizeRequest{ Name: newName, FlavorRef: newFlavor, DiskConfig: newDiskConfig, } return perigee.Post(url, perigee.Options{ ReqBody: &struct { Resize ResizeRequest `json:"resize"` }{rr}, OkCodes: []int{202}, MoreHeaders: map[string]string{ "X-Auth-Token": gsp.access.AuthToken(), }, }) }) return err }
// See the CloudServersProvider interface for details func (gsp *genericServersProvider) RebootServer(id string, hard bool) error { return gsp.context.WithReauth(gsp.access, func() error { url := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id) types := map[bool]string{false: "SOFT", true: "HARD"} return perigee.Post(url, perigee.Options{ ReqBody: &struct { Reboot struct { Type string `json:"type"` } `json:"reboot"` }{ struct { Type string `json:"type"` }{types[hard]}, }, OkCodes: []int{202}, MoreHeaders: map[string]string{ "X-Auth-Token": gsp.access.AuthToken(), }, }) }) }
// See the CloudServersProvider interface for details. func (gsp *genericServersProvider) SetAdminPassword(id, pw string) error { err := gsp.context.WithReauth(gsp.access, func() error { url := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id) return perigee.Post(url, perigee.Options{ ReqBody: &struct { ChangePassword struct { AdminPass string `json:"adminPass"` } `json:"changePassword"` }{ struct { AdminPass string `json:"adminPass"` }{pw}, }, OkCodes: []int{202}, MoreHeaders: map[string]string{ "X-Auth-Token": gsp.access.AuthToken(), }, }) }) return err }