當前位置: 首頁>>代碼示例>>Golang>>正文


Golang gophercloud.ServiceClient類代碼示例

本文整理匯總了Golang中github.com/gophercloud/gophercloud.ServiceClient的典型用法代碼示例。如果您正苦於以下問題:Golang ServiceClient類的具體用法?Golang ServiceClient怎麽用?Golang ServiceClient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ServiceClient類的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) (r CreateResult) {
	b := map[string]interface{}{"member": member}
	_, r.Err = client.Post(createMemberURL(client, id), b, &r.Body, &gophercloud.RequestOpts{
		OkCodes: []int{200, 409, 403},
	})
	return
}
開發者ID:jrperritt,項目名稱:gophercloud-1,代碼行數:17,代碼來源:requests.go

示例2: Download

// 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) (r DownloadResult) {
	url := downloadURL(c, containerName, objectName)
	h := make(map[string]string)
	if opts != nil {
		headers, query, err := opts.ToObjectDownloadParams()
		if err != nil {
			r.Err = err
			return
		}
		for k, v := range headers {
			h[k] = v
		}
		url += query
	}

	resp, err := c.Get(url, nil, &gophercloud.RequestOpts{
		MoreHeaders: h,
		OkCodes:     []int{200, 304},
	})
	if resp != nil {
		r.Header = resp.Header
		r.Body = resp.Body
	}
	r.Err = err
	return
}
開發者ID:jrperritt,項目名稱:gophercloud-1,代碼行數:29,代碼來源:requests.go

示例3: BeginDetaching

// BeginDetach will mark the volume as detaching
func BeginDetaching(client *gophercloud.ServiceClient, id string) (r BeginDetachingResult) {
	b := map[string]interface{}{"os-begin_detaching": make(map[string]interface{})}
	_, r.Err = client.Post(beginDetachingURL(client, id), b, nil, &gophercloud.RequestOpts{
		OkCodes: []int{202},
	})
	return
}
開發者ID:jrperritt,項目名稱:gophercloud-1,代碼行數:8,代碼來源:requests.go

示例4: Create

// Create is a function that creates a new object or replaces an existing object. If the returned response's ETag
// header fails to match the local checksum, the failed request will automatically be retried up to a maximum of 3 times.
func Create(c *gophercloud.ServiceClient, containerName, objectName string, opts CreateOptsBuilder) (r CreateResult) {
	url := createURL(c, containerName, objectName)
	h := make(map[string]string)
	var b io.Reader
	if opts != nil {
		tmpB, headers, query, err := opts.ToObjectCreateParams()
		if err != nil {
			r.Err = err
			return
		}
		for k, v := range headers {
			h[k] = v
		}
		url += query
		b = tmpB
	}

	resp, err := c.Put(url, nil, nil, &gophercloud.RequestOpts{
		RawBody:     b,
		MoreHeaders: h,
	})
	r.Err = err
	if resp != nil {
		r.Header = resp.Header
	}
	return
}
開發者ID:jrperritt,項目名稱:gophercloud-1,代碼行數:29,代碼來源:requests.go

示例5: Upload

// Upload uploads image file
func Upload(client *gophercloud.ServiceClient, id string, data io.ReadSeeker) (r UploadResult) {
	_, r.Err = client.Put(uploadURL(client, id), data, nil, &gophercloud.RequestOpts{
		MoreHeaders: map[string]string{"Content-Type": "application/octet-stream"},
		OkCodes:     []int{204},
	})
	return
}
開發者ID:jrperritt,項目名稱:gophercloud-1,代碼行數:8,代碼來源:requests.go

示例6: Reserve

// Reserve will reserve a volume based on volume id.
func Reserve(client *gophercloud.ServiceClient, id string) (r ReserveResult) {
	b := map[string]interface{}{"os-reserve": make(map[string]interface{})}
	_, r.Err = client.Post(reserveURL(client, id), b, nil, &gophercloud.RequestOpts{
		OkCodes: []int{200, 201, 202},
	})
	return
}
開發者ID:jrperritt,項目名稱:gophercloud-1,代碼行數:8,代碼來源:requests.go

示例7: RemoveRule

func RemoveRule(c *gophercloud.ServiceClient, id, ruleID string) (r RemoveRuleResult) {
	b := map[string]interface{}{"firewall_rule_id": ruleID}
	_, r.Err = c.Put(removeURL(c, id), b, &r.Body, &gophercloud.RequestOpts{
		OkCodes: []int{200},
	})
	return
}
開發者ID:jrperritt,項目名稱:gophercloud-1,代碼行數:7,代碼來源:requests.go

示例8: Abandon

// Abandon deletes the stack with the provided stackName and stackID, but leaves its
// resources intact, and returns data describing the stack and its resources.
func Abandon(c *gophercloud.ServiceClient, stackName, stackID string) (r AbandonResult) {
	_, r.Err = c.Delete(abandonURL(c, stackName, stackID), &gophercloud.RequestOpts{
		JSONResponse: &r.Body,
		OkCodes:      []int{200},
	})
	return
}
開發者ID:jrperritt,項目名稱:gophercloud-1,代碼行數:9,代碼來源:requests.go

示例9: Ping

// Ping retrieves a ping to the server.
func Ping(c *gophercloud.ServiceClient) (r PingResult) {
	_, r.Err = c.Get(pingURL(c), nil, &gophercloud.RequestOpts{
		OkCodes:     []int{204},
		MoreHeaders: map[string]string{"Accept": ""},
	})
	return
}
開發者ID:jrperritt,項目名稱:gophercloud-1,代碼行數:8,代碼來源:requests.go

示例10: Update

// Update will modify an existing configuration group by performing a merge
// between new and existing values. If the key already exists, the new value
// will overwrite. All other keys will remain unaffected.
func Update(client *gophercloud.ServiceClient, configID string, opts UpdateOptsBuilder) (r UpdateResult) {
	b, err := opts.ToConfigUpdateMap()
	if err != nil {
		r.Err = err
		return
	}
	_, r.Err = client.Patch(resourceURL(client, configID), &b, nil, nil)
	return
}
開發者ID:jrperritt,項目名稱:gophercloud-1,代碼行數:12,代碼來源:requests.go

示例11: Download

// Download retrieves file
func Download(client *gophercloud.ServiceClient, id string) (r DownloadResult) {
	var resp *http.Response
	resp, r.Err = client.Get(downloadURL(client, id), nil, nil)
	if resp != nil {
		r.Body = resp.Body
		r.Header = resp.Header
	}
	return
}
開發者ID:jrperritt,項目名稱:gophercloud-1,代碼行數:10,代碼來源:requests.go

示例12: CreateMember

// CreateMember will create and associate a Member with a particular Pool.
func CreateMember(c *gophercloud.ServiceClient, poolID string, opts CreateMemberOpts) (r CreateMemberResult) {
	b, err := opts.ToMemberCreateMap()
	if err != nil {
		r.Err = err
		return
	}
	_, r.Err = c.Post(memberRootURL(c, poolID), b, &r.Body, nil)
	return
}
開發者ID:jrperritt,項目名稱:gophercloud-1,代碼行數:10,代碼來源:requests.go

示例13: Create

// Create accepts a CreateOpts struct and uses the values to create a new firewall rule
func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
	b, err := opts.ToRuleCreateMap()
	if err != nil {
		r.Err = err
		return
	}
	_, r.Err = c.Post(rootURL(c), b, &r.Body, nil)
	return
}
開發者ID:mhlias,項目名稱:terraform,代碼行數:10,代碼來源:requests.go

示例14: ChangeAdminPassword

// ChangeAdminPassword alters the administrator or root password for a specified server.
func ChangeAdminPassword(client *gophercloud.ServiceClient, id, newPassword string) (r ActionResult) {
	b := map[string]interface{}{
		"changePassword": map[string]string{
			"adminPass": newPassword,
		},
	}
	_, r.Err = client.Post(actionURL(client, id), b, nil, nil)
	return
}
開發者ID:jrperritt,項目名稱:gophercloud-1,代碼行數:10,代碼來源:requests.go

示例15: Rebuild

// Rebuild will reprovision the server according to the configuration options
// provided in the RebuildOpts struct.
func Rebuild(client *gophercloud.ServiceClient, id string, opts RebuildOptsBuilder) (r RebuildResult) {
	b, err := opts.ToServerRebuildMap()
	if err != nil {
		r.Err = err
		return
	}
	_, r.Err = client.Post(actionURL(client, id), b, &r.Body, nil)
	return
}
開發者ID:jrperritt,項目名稱:gophercloud-1,代碼行數:11,代碼來源:requests.go


注:本文中的github.com/gophercloud/gophercloud.ServiceClient類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。