本文整理匯總了Golang中github.com/rackspace/gophercloud.ServiceClient.Post方法的典型用法代碼示例。如果您正苦於以下問題:Golang ServiceClient.Post方法的具體用法?Golang ServiceClient.Post怎麽用?Golang ServiceClient.Post使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/rackspace/gophercloud.ServiceClient
的用法示例。
在下文中一共展示了ServiceClient.Post方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Create
// Create member for specific image
//
// Preconditions
// The specified images must exist.
// You can only add a new member to an image which 'visibility' attribute is private.
// You must be the owner of the specified image.
// Synchronous Postconditions
// With correct permissions, you can see the member status of the image as pending through API calls.
//
// More details here: http://developer.openstack.org/api-ref-image-v2.html#createImageMember-v2
func Create(client *gophercloud.ServiceClient, id string, member string) CreateMemberResult {
var res CreateMemberResult
body := map[string]interface{}{}
body["member"] = member
response, err := client.Post(imageMembersURL(client, id), body, &res.Body,
&gophercloud.RequestOpts{OkCodes: []int{200, 409, 403}})
//some problems in http stack or lower
if err != nil {
res.Err = err
return res
}
// membership conflict
if response.StatusCode == 409 {
res.Err = fmt.Errorf("Given tenant '%s' is already member for image '%s'.", member, id)
return res
}
// visibility conflict
if response.StatusCode == 403 {
res.Err = fmt.Errorf("You can only add a new member to an image "+
"which 'visibility' attribute is private (image '%s')", id)
return res
}
return res
}
示例2: Create
// Create accepts a CreateOpts struct and uses the values provided to create a
// new floating IP resource. You can create floating IPs on external networks
// only. If you provide a FloatingNetworkID which refers to a network that is
// not external (i.e. its `router:external' attribute is False), the operation
// will fail and return a 400 error.
//
// If you do not specify a FloatingIP address value, the operation will
// automatically allocate an available address for the new resource. If you do
// choose to specify one, it must fall within the subnet range for the external
// network - otherwise the operation returns a 400 error. If the FloatingIP
// address is already in use, the operation returns a 409 error code.
//
// You can associate the new resource with an internal port by using the PortID
// field. If you specify a PortID that is not valid, the operation will fail and
// return 404 error code.
//
// You must also configure an IP address for the port associated with the PortID
// you have provided - this is what the FixedIP refers to: an IP fixed to a port.
// Because a port might be associated with multiple IP addresses, you can use
// the FixedIP field to associate a particular IP address rather than have the
// API assume for you. If you specify an IP address that is not valid, the
// operation will fail and return a 400 error code. If the PortID and FixedIP
// are already associated with another resource, the operation will fail and
// returns a 409 error code.
func Create(c *gophercloud.ServiceClient, opts CreateOpts) CreateResult {
var res CreateResult
// Validate
if opts.FloatingNetworkID == "" {
res.Err = errFloatingNetworkIDRequired
return res
}
// Define structures
type floatingIP struct {
FloatingNetworkID string `json:"floating_network_id"`
FloatingIP string `json:"floating_ip_address,omitempty"`
PortID string `json:"port_id,omitempty"`
FixedIP string `json:"fixed_ip_address,omitempty"`
TenantID string `json:"tenant_id,omitempty"`
}
type request struct {
FloatingIP floatingIP `json:"floatingip"`
}
// Populate request body
reqBody := request{FloatingIP: floatingIP{
FloatingNetworkID: opts.FloatingNetworkID,
FloatingIP: opts.FloatingIP,
PortID: opts.PortID,
FixedIP: opts.FixedIP,
TenantID: opts.TenantID,
}}
_, res.Err = c.Post(rootURL(c), reqBody, &res.Body, nil)
return res
}
示例3: Create
// 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"`
Provider string `json:"provider,omitempty"`
}
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,
Provider: opts.Provider,
}}
var res CreateResult
_, res.Err = c.Post(rootURL(c), reqBody, &res.Body, nil)
return res
}
示例4: Create
// 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 = c.Post(rootURL(c), reqBody, &res.Body, nil)
return res
}
示例5: Create
// 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"`
TenantID string `json:"tenant_id,omitempty"`
Description string `json:"description,omitempty"`
}
type request struct {
SecGroup secgroup `json:"security_group"`
}
reqBody := request{SecGroup: secgroup{
Name: opts.Name,
TenantID: opts.TenantID,
Description: opts.Description,
}}
_, res.Err = c.Post(rootURL(c), reqBody, &res.Body, nil)
return res
}
示例6: Migrate
// Migrate is the admin operation to migrate a Compute Server.
func Migrate(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult {
var req struct {
Migrate string `json:"migrate"`
}
var res gophercloud.ErrResult
_, res.Err = client.Post(actionURL(client, id), req, nil, nil)
return res
}
示例7: InjectNetworkInfo
// InjectNetworkInfo is the admin operation which injects network info into a Compute Server.
func InjectNetworkInfo(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult {
var req struct {
InjectNetworkInfo string `json:"injectNetworkInfo"`
}
var res gophercloud.ErrResult
_, res.Err = client.Post(actionURL(client, id), req, nil, nil)
return res
}
示例8: ResetNetwork
// ResetNetwork is the admin operation to reset the network on a Compute Server.
func ResetNetwork(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult {
var req struct {
ResetNetwork string `json:"resetNetwork"`
}
var res gophercloud.ErrResult
_, res.Err = client.Post(actionURL(client, id), req, nil, nil)
return res
}
示例9: ConfirmResize
// ConfirmResize confirms a previous resize operation on a server.
// See Resize() for more details.
func ConfirmResize(client *gophercloud.ServiceClient, id string) ActionResult {
var res ActionResult
reqBody := map[string]interface{}{"confirmResize": nil}
_, res.Err = client.Post(actionURL(client, id), reqBody, nil, &gophercloud.RequestOpts{
OkCodes: []int{201, 202, 204},
})
return res
}
示例10: Disassociate
// Disassociate decouples an allocated floating IP from an instance
func Disassociate(client *gophercloud.ServiceClient, serverId, fip string) DisassociateResult {
var res DisassociateResult
removeFloatingIp := make(map[string]interface{})
removeFloatingIp["address"] = fip
reqBody := map[string]interface{}{"removeFloatingIp": removeFloatingIp}
_, res.Err = client.Post(disassociateURL(client, serverId), reqBody, nil, nil)
return res
}
示例11: Execute
// Execute requests the given policy be executed immediately.
func Execute(client *gophercloud.ServiceClient, groupID, policyID string) ExecuteResult {
var result ExecuteResult
url := executeURL(client, groupID, policyID)
_, result.Err = client.Post(url, nil, &result.Body, &gophercloud.RequestOpts{
OkCodes: []int{202},
})
return result
}
示例12: ForceDelete
func ForceDelete(client *gophercloud.ServiceClient, id string) ActionResult {
var req struct {
ForceDelete string `json:"forceDelete"`
}
var res ActionResult
_, res.Err = client.Post(actionURL(client, id), req, nil, nil)
return res
}
示例13: OpenstackPost
//OpenstackPost posts a resource using OpenStack API
func OpenstackPost(client *gophercloud.ServiceClient, url string, data interface{}) (interface{}, error) {
var response interface{}
_, err := client.Post(url, data, &response, &gophercloud.RequestOpts{
OkCodes: []int{200, 201, 202},
})
if err != nil {
return nil, err
}
return response, nil
}
示例14: Create
// Create adds a public IP to the server with the given serverID.
func Create(c *gophercloud.ServiceClient, serverID string) CreateResult {
var res CreateResult
reqBody := map[string]interface{}{
"cloud_server": map[string]string{
"id": serverID,
},
}
_, res.Err = c.Post(createURL(c), reqBody, &res.Body, nil)
return res
}
示例15: Create
// Create adds a new service of the requested type to the catalog.
func Create(client *gophercloud.ServiceClient, serviceType string) CreateResult {
type request struct {
Type string `json:"type"`
}
req := request{Type: serviceType}
var result CreateResult
_, result.Err = client.Post(listURL(client), req, &result.Body, nil)
return result
}