// Create is a function that creates a new object or replaces an existing object. func Create(c *gophercloud.ServiceClient, containerName, objectName string, content io.Reader, opts CreateOptsBuilder) CreateResult { var res CreateResult url := createURL(c, containerName, objectName) h := c.AuthenticatedHeaders() if opts != nil { headers, query, err := opts.ToObjectCreateParams() if err != nil { res.Err = err return res } for k, v := range headers { h[k] = v } url += query } contentType := h["Content-Type"] resp, err := perigee.Request("PUT", url, perigee.Options{ ContentType: contentType, ReqBody: content, MoreHeaders: h, OkCodes: []int{201, 202}, }) res.Header = resp.HttpResponse.Header res.Err = err return res }
// Update is a function that creates, updates, or deletes an object's metadata. func Update(c *gophercloud.ServiceClient, containerName, objectName string, opts UpdateOptsBuilder) UpdateResult { var res UpdateResult h := c.AuthenticatedHeaders() if opts != nil { headers, err := opts.ToObjectUpdateMap() if err != nil { res.Err = err return res } for k, v := range headers { h[k] = v } } url := updateURL(c, containerName, objectName) resp, err := perigee.Request("POST", url, perigee.Options{ MoreHeaders: h, OkCodes: []int{202}, }) res.Header = resp.HttpResponse.Header res.Err = err return res }
// Update allows floating IP resources to be updated. Currently, the only way to // "update" a floating IP is to associate it with a new internal port, or // disassociated it from all ports. See UpdateOpts for instructions of how to // do this. func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) UpdateResult { type floatingIP struct { PortID *string `json:"port_id"` } type request struct { FloatingIP floatingIP `json:"floatingip"` } var portID *string if opts.PortID == "" { portID = nil } else { portID = &opts.PortID } reqBody := request{FloatingIP: floatingIP{PortID: portID}} // Send request to API var res UpdateResult _, res.Err = perigee.Request("PUT", resourceURL(c, id), perigee.Options{ MoreHeaders: c.AuthenticatedHeaders(), ReqBody: &reqBody, Results: &res.Body, OkCodes: []int{200}, }) return res }
// Create accepts a CreateOpts struct and uses the values to create a new // logical router. When it is created, the router does not have an internal // interface - it is not associated to any subnet. // // You can optionally specify an external gateway for a router using the // GatewayInfo struct. The external gateway for the router must be plugged into // an external network (it is external if its `router:external' field is set to // true). func Create(c *gophercloud.ServiceClient, opts CreateOpts) CreateResult { type router struct { Name *string `json:"name,omitempty"` AdminStateUp *bool `json:"admin_state_up,omitempty"` TenantID *string `json:"tenant_id,omitempty"` GatewayInfo *GatewayInfo `json:"external_gateway_info,omitempty"` } type request struct { Router router `json:"router"` } reqBody := request{Router: router{ Name: gophercloud.MaybeString(opts.Name), AdminStateUp: opts.AdminStateUp, TenantID: gophercloud.MaybeString(opts.TenantID), }} if opts.GatewayInfo != nil { reqBody.Router.GatewayInfo = opts.GatewayInfo } var res CreateResult _, res.Err = perigee.Request("POST", rootURL(c), perigee.Options{ MoreHeaders: c.AuthenticatedHeaders(), ReqBody: &reqBody, Results: &res.Body, OkCodes: []int{201}, }) return res }
// Create accepts a CreateOpts struct and uses the values to create a new // load balancer pool. func Create(c *gophercloud.ServiceClient, opts CreateOpts) CreateResult { type pool struct { Name string `json:"name"` TenantID string `json:"tenant_id,omitempty"` Protocol string `json:"protocol"` SubnetID string `json:"subnet_id"` LBMethod string `json:"lb_method"` } type request struct { Pool pool `json:"pool"` } reqBody := request{Pool: pool{ Name: opts.Name, TenantID: opts.TenantID, Protocol: opts.Protocol, SubnetID: opts.SubnetID, LBMethod: opts.LBMethod, }} var res CreateResult _, res.Err = perigee.Request("POST", rootURL(c), perigee.Options{ MoreHeaders: c.AuthenticatedHeaders(), ReqBody: &reqBody, Results: &res.Body, OkCodes: []int{201}, }) return res }
// Create is an operation which provisions a new security group with default // security group rules for the IPv4 and IPv6 ether types. func Create(c *gophercloud.ServiceClient, opts CreateOpts) CreateResult { var res CreateResult // Validate required opts if opts.Name == "" { res.Err = errNameRequired return res } type secgroup struct { Name string `json:"name"` Description string `json:"description,omitempty"` } type request struct { SecGroup secgroup `json:"security_group"` } reqBody := request{SecGroup: secgroup{ Name: opts.Name, Description: opts.Description, }} _, res.Err = perigee.Request("POST", rootURL(c), perigee.Options{ MoreHeaders: c.AuthenticatedHeaders(), ReqBody: &reqBody, Results: &res.Body, OkCodes: []int{201}, }) return res }
// Enable is a function that enables/disables a CDN container. func Enable(c *gophercloud.ServiceClient, containerName string, opts EnableOptsBuilder) EnableResult { var res EnableResult h := c.AuthenticatedHeaders() if opts != nil { headers, err := opts.ToCDNContainerEnableMap() if err != nil { res.Err = err return res } for k, v := range headers { h[k] = v } } resp, err := c.Request("PUT", enableURL(c, containerName), gophercloud.RequestOpts{ MoreHeaders: h, OkCodes: []int{201, 202, 204}, }) if resp != nil { res.Header = resp.Header } res.Err = err return res }
// Update changes an existing endpoint with new data. // All fields are optional in the provided EndpointOpts. func Update(client *gophercloud.ServiceClient, endpointID string, opts EndpointOpts) UpdateResult { type endpoint struct { Interface *string `json:"interface,omitempty"` Name *string `json:"name,omitempty"` Region *string `json:"region,omitempty"` URL *string `json:"url,omitempty"` ServiceID *string `json:"service_id,omitempty"` } type request struct { Endpoint endpoint `json:"endpoint"` } reqBody := request{Endpoint: endpoint{}} reqBody.Endpoint.Interface = gophercloud.MaybeString(string(opts.Availability)) reqBody.Endpoint.Name = gophercloud.MaybeString(opts.Name) reqBody.Endpoint.Region = gophercloud.MaybeString(opts.Region) reqBody.Endpoint.URL = gophercloud.MaybeString(opts.URL) reqBody.Endpoint.ServiceID = gophercloud.MaybeString(opts.ServiceID) var result UpdateResult _, result.Err = perigee.Request("PATCH", endpointURL(client, endpointID), perigee.Options{ MoreHeaders: client.AuthenticatedHeaders(), ReqBody: &reqBody, Results: &result.Body, OkCodes: []int{200}, }) return result }
// Update allows routers to be updated. You can update the name, administrative // state, and the external gateway. For more information about how to set the // external gateway for a router, see Create. This operation does not enable // the update of router interfaces. To do this, use the AddInterface and // RemoveInterface functions. func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) UpdateResult { type router struct { Name *string `json:"name,omitempty"` AdminStateUp *bool `json:"admin_state_up,omitempty"` GatewayInfo *GatewayInfo `json:"external_gateway_info,omitempty"` } type request struct { Router router `json:"router"` } reqBody := request{Router: router{ Name: gophercloud.MaybeString(opts.Name), AdminStateUp: opts.AdminStateUp, }} if opts.GatewayInfo != nil { reqBody.Router.GatewayInfo = opts.GatewayInfo } // Send request to API var res UpdateResult _, res.Err = perigee.Request("PUT", resourceURL(c, id), perigee.Options{ MoreHeaders: c.AuthenticatedHeaders(), ReqBody: &reqBody, Results: &res.Body, OkCodes: []int{200}, }) return res }
// Copy is a function that copies one object to another. func Copy(c *gophercloud.ServiceClient, containerName, objectName string, opts CopyOptsBuilder) CopyResult { var res CopyResult h := c.AuthenticatedHeaders() headers, err := opts.ToObjectCopyMap() if err != nil { res.Err = err return res } for k, v := range headers { h[k] = v } url := copyURL(c, containerName, objectName) resp, err := c.Request("COPY", url, gophercloud.RequestOpts{ MoreHeaders: h, OkCodes: []int{201}, }) if resp != nil { res.Header = resp.Header } res.Err = err return res }
// Update is a function that creates, updates, or deletes an object's metadata. func Update(c *gophercloud.ServiceClient, containerName, objectName string, opts UpdateOptsBuilder) UpdateResult { var res UpdateResult h := c.AuthenticatedHeaders() if opts != nil { headers, err := opts.ToObjectUpdateMap() if err != nil { res.Err = err return res } for k, v := range headers { h[k] = v } } url := updateURL(c, containerName, objectName) resp, err := c.Request("POST", url, gophercloud.RequestOpts{ MoreHeaders: h, }) if resp != nil { res.Header = resp.Header } res.Err = err return res }
// Get is a function that retrieves an account's metadata. To extract just the // custom metadata, call the ExtractMetadata method on the GetResult. To extract // all the headers that are returned (including the metadata), call the // ExtractHeader method on the GetResult. func Get(c *gophercloud.ServiceClient, opts GetOptsBuilder) GetResult { var res GetResult h := c.AuthenticatedHeaders() if opts != nil { headers, err := opts.ToAccountGetMap() if err != nil { res.Err = err return res } for k, v := range headers { h[k] = v } } resp, err := c.Request("HEAD", getURL(c), gophercloud.RequestOpts{ MoreHeaders: h, OkCodes: []int{204}, }) if resp != nil { res.Header = resp.Header } res.Err = err return res }
// Download is a function that retrieves the content and metadata for an object. // To extract just the content, pass the DownloadResult response to the // ExtractContent function. func Download(c *gophercloud.ServiceClient, containerName, objectName string, opts DownloadOptsBuilder) DownloadResult { var res DownloadResult url := downloadURL(c, containerName, objectName) h := c.AuthenticatedHeaders() if opts != nil { headers, query, err := opts.ToObjectDownloadParams() if err != nil { res.Err = err return res } for k, v := range headers { h[k] = v } url += query } resp, err := c.Request("GET", url, gophercloud.RequestOpts{ MoreHeaders: h, OkCodes: []int{200, 304}, }) if resp != nil { res.Header = resp.Header res.Body = resp.Body } res.Err = err return res }
// Create accepts a CreateOpts struct and uses the values to create a new // load balancer pool member. func Create(c *gophercloud.ServiceClient, opts CreateOpts) CreateResult { type member struct { TenantID string `json:"tenant_id"` ProtocolPort int `json:"protocol_port"` Address string `json:"address"` PoolID string `json:"pool_id"` } type request struct { Member member `json:"member"` } reqBody := request{Member: member{ Address: opts.Address, TenantID: opts.TenantID, ProtocolPort: opts.ProtocolPort, PoolID: opts.PoolID, }} var res CreateResult _, res.Err = perigee.Request("POST", rootURL(c), perigee.Options{ MoreHeaders: c.AuthenticatedHeaders(), ReqBody: &reqBody, Results: &res.Body, OkCodes: []int{201}, }) return res }
// Delete will delete objects or containers in bulk. func Delete(c *gophercloud.ServiceClient, opts DeleteOptsBuilder) DeleteResult { var res DeleteResult if opts == nil { return res } reqString, err := opts.ToBulkDeleteBody() if err != nil { res.Err = err return res } reqBody := strings.NewReader(reqString) resp, err := perigee.Request("DELETE", deleteURL(c), perigee.Options{ ContentType: "text/plain", MoreHeaders: c.AuthenticatedHeaders(), OkCodes: []int{200}, ReqBody: reqBody, Results: &res.Body, }) res.Header = resp.HttpResponse.Header res.Err = err return res }
// AddInterface attaches a subnet to an internal router interface. You must // specify either a SubnetID or PortID in the request body. If you specify both, // the operation will fail and an error will be returned. // // If you specify a SubnetID, the gateway IP address for that particular subnet // is used to create the router interface. Alternatively, if you specify a // PortID, the IP address associated with the port is used to create the router // interface. // // If you reference a port that is associated with multiple IP addresses, or // if the port is associated with zero IP addresses, the operation will fail and // a 400 Bad Request error will be returned. // // If you reference a port already in use, the operation will fail and a 409 // Conflict error will be returned. // // The PortID that is returned after using Extract() on the result of this // operation can either be the same PortID passed in or, on the other hand, the // identifier of a new port created by this operation. After the operation // completes, the device ID of the port is set to the router ID, and the // device owner attribute is set to `network:router_interface'. func AddInterface(c *gophercloud.ServiceClient, id string, opts InterfaceOpts) InterfaceResult { var res InterfaceResult // Validate if (opts.SubnetID == "" && opts.PortID == "") || (opts.SubnetID != "" && opts.PortID != "") { res.Err = errInvalidInterfaceOpts return res } type request struct { SubnetID string `json:"subnet_id,omitempty"` PortID string `json:"port_id,omitempty"` } body := request{SubnetID: opts.SubnetID, PortID: opts.PortID} _, res.Err = perigee.Request("PUT", addInterfaceURL(c, id), perigee.Options{ MoreHeaders: c.AuthenticatedHeaders(), ReqBody: &body, Results: &res.Body, OkCodes: []int{200}, }) return res }
// Delete will delete the volume type with the provided ID. func Delete(client *gophercloud.ServiceClient, id string) DeleteResult { var res DeleteResult _, res.Err = client.Request("DELETE", deleteURL(client, id), gophercloud.RequestOpts{ MoreHeaders: client.AuthenticatedHeaders(), OkCodes: []int{202}, }) return res }
// DisassociateMonitor will disassociate a health monitor with a particular // pool. When dissociation is successful, the health monitor will no longer // check for the health of the members of the pool. func DisassociateMonitor(c *gophercloud.ServiceClient, poolID, monitorID string) AssociateResult { var res AssociateResult _, res.Err = perigee.Request("DELETE", disassociateURL(c, poolID, monitorID), perigee.Options{ MoreHeaders: c.AuthenticatedHeaders(), OkCodes: []int{204}, }) return res }
// Delete removes an endpoint from the service catalog. func Delete(client *gophercloud.ServiceClient, endpointID string) DeleteResult { var res DeleteResult _, res.Err = perigee.Request("DELETE", endpointURL(client, endpointID), perigee.Options{ MoreHeaders: client.AuthenticatedHeaders(), OkCodes: []int{204}, }) return res }
// Delete will permanently delete a particular router based on its unique ID. func Delete(c *gophercloud.ServiceClient, id string) DeleteResult { var res DeleteResult _, res.Err = perigee.Request("DELETE", resourceURL(c, id), perigee.Options{ MoreHeaders: c.AuthenticatedHeaders(), OkCodes: []int{204}, }) return res }
// Get requests details on a single server, by ID. func Get(client *gophercloud.ServiceClient, id string) GetResult { var result GetResult _, result.Err = perigee.Request("GET", getURL(client, id), perigee.Options{ Results: &result.Body, MoreHeaders: client.AuthenticatedHeaders(), }) return result }
// Get returns additional information about a service, given its ID. func Get(client *gophercloud.ServiceClient, serviceID string) GetResult { var result GetResult _, result.Err = perigee.Request("GET", serviceURL(client, serviceID), perigee.Options{ MoreHeaders: client.AuthenticatedHeaders(), Results: &result.Body, OkCodes: []int{200}, }) return result }
// Update requests that various attributes of the indicated server be changed. func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) UpdateResult { var result UpdateResult _, result.Err = perigee.Request("PUT", updateURL(client, id), perigee.Options{ Results: &result.Body, ReqBody: opts.ToServerUpdateMap(), MoreHeaders: client.AuthenticatedHeaders(), }) return result }
// Get retrieves a particular router based on its unique ID. func Get(c *gophercloud.ServiceClient, id string) GetResult { var res GetResult _, res.Err = perigee.Request("GET", resourceURL(c, id), perigee.Options{ MoreHeaders: c.AuthenticatedHeaders(), Results: &res.Body, OkCodes: []int{200}, }) return res }
// Create is an operation which provisions a new security group with default // security group rules for the IPv4 and IPv6 ether types. func Create(c *gophercloud.ServiceClient, opts CreateOpts) CreateResult { var res CreateResult // Validate required opts if opts.Direction != DirIngress && opts.Direction != DirEgress { res.Err = errValidDirectionRequired return res } if opts.EtherType != Ether4 && opts.EtherType != Ether6 { res.Err = errValidEtherTypeRequired return res } if opts.SecGroupID == "" { res.Err = errSecGroupIDRequired return res } if opts.Protocol != "" && opts.Protocol != ProtocolTCP && opts.Protocol != ProtocolUDP && opts.Protocol != ProtocolICMP { res.Err = errValidProtocolRequired return res } type secrule struct { Direction string `json:"direction"` EtherType string `json:"ethertype"` SecGroupID string `json:"security_group_id"` PortRangeMax int `json:"port_range_max,omitempty"` PortRangeMin int `json:"port_range_min,omitempty"` Protocol string `json:"protocol,omitempty"` RemoteGroupID string `json:"remote_group_id,omitempty"` RemoteIPPrefix string `json:"remote_ip_prefix,omitempty"` } type request struct { SecRule secrule `json:"security_group_rule"` } reqBody := request{SecRule: secrule{ Direction: opts.Direction, EtherType: opts.EtherType, SecGroupID: opts.SecGroupID, PortRangeMax: opts.PortRangeMax, PortRangeMin: opts.PortRangeMin, Protocol: opts.Protocol, RemoteGroupID: opts.RemoteGroupID, RemoteIPPrefix: opts.RemoteIPPrefix, }} _, res.Err = perigee.Request("POST", rootURL(c), perigee.Options{ MoreHeaders: c.AuthenticatedHeaders(), ReqBody: &reqBody, Results: &res.Body, OkCodes: []int{201}, }) return res }
// Get is a function that retrieves the metadata of a container. To extract just // the custom metadata, pass the GetResult response to the ExtractMetadata // function. func Get(c *gophercloud.ServiceClient, containerName string) GetResult { var res GetResult resp, err := perigee.Request("HEAD", getURL(c, containerName), perigee.Options{ MoreHeaders: c.AuthenticatedHeaders(), OkCodes: []int{200, 204}, }) res.Header = resp.HttpResponse.Header res.Err = err return res }
// Get will retrieve the volume type with the provided ID. To extract the volume // type from the result, call the Extract method on the GetResult. func Get(client *gophercloud.ServiceClient, id string) GetResult { var res GetResult _, err := client.Request("GET", getURL(client, id), gophercloud.RequestOpts{ MoreHeaders: client.AuthenticatedHeaders(), OkCodes: []int{200}, JSONResponse: &res.Body, }) res.Err = err return res }
// Get will retrieve the volume type with the provided ID. To extract the volume // type from the result, call the Extract method on the GetResult. func Get(client *gophercloud.ServiceClient, id string) GetResult { var res GetResult _, err := perigee.Request("GET", getURL(client, id), perigee.Options{ MoreHeaders: client.AuthenticatedHeaders(), OkCodes: []int{200}, Results: &res.Body, }) res.Err = err return res }
// RevertResize cancels a previous resize operation on a server. // See Resize() for more details. func RevertResize(client *gophercloud.ServiceClient, id string) ActionResult { var res ActionResult _, res.Err = perigee.Request("POST", actionURL(client, id), perigee.Options{ ReqBody: map[string]interface{}{"revertResize": nil}, MoreHeaders: client.AuthenticatedHeaders(), OkCodes: []int{202}, }) return res }
// Request performs a Perigee request and extracts the http.Response from the result. func Request(client *gophercloud.ServiceClient, headers map[string]string, url string) (http.Response, error) { h := client.AuthenticatedHeaders() for key, value := range headers { h[key] = value } resp, err := perigee.Request("GET", url, perigee.Options{ MoreHeaders: h, OkCodes: []int{200, 204}, }) if err != nil { return http.Response{}, err } return resp.HttpResponse, nil }