本文整理汇总了Golang中github.com/maximilien/softlayer-go/common.IsHttpErrorCode函数的典型用法代码示例。如果您正苦于以下问题:Golang IsHttpErrorCode函数的具体用法?Golang IsHttpErrorCode怎么用?Golang IsHttpErrorCode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsHttpErrorCode函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: CreateBaremetals
func (bc *bmpClient) CreateBaremetals(createBaremetalsInfo CreateBaremetalsInfo, dryRun bool) (CreateBaremetalsResponse, error) {
requestBody, err := json.Marshal(createBaremetalsInfo)
if err != nil {
errorMessage := fmt.Sprintf("bmp: failed to encode Json File, error message '%s'", err.Error())
return CreateBaremetalsResponse{}, errors.New(errorMessage)
}
path := "baremetals"
if dryRun {
path = "baremetals/dryrun"
}
responseBytes, errorCode, err := bc.httpClient.DoRawHttpRequest(path, "POST", bytes.NewBuffer(requestBody))
if err != nil {
errorMessage := fmt.Sprintf("bmp: could not calls /baremetals on BMP server, error message %s", err.Error())
return CreateBaremetalsResponse{}, errors.New(errorMessage)
}
if slcommon.IsHttpErrorCode(errorCode) {
errorMessage := fmt.Sprintf("bmp: could not call /baremetals on BMP server, HTTP error code: %d", errorCode)
return CreateBaremetalsResponse{}, errors.New(errorMessage)
}
response := CreateBaremetalsResponse{}
err = json.Unmarshal(responseBytes, &response)
if err != nil {
errorMessage := fmt.Sprintf("bmp: failed to decode JSON response, err message '%s'", err.Error())
return CreateBaremetalsResponse{}, errors.New(errorMessage)
}
return response, nil
}
开发者ID:cloudfoundry-community,项目名称:bosh-softlayer-tools,代码行数:32,代码来源:bmp_client.go
示例2: CreateObject
func (slssks *softLayer_Security_Ssh_Key_Service) CreateObject(template datatypes.SoftLayer_Security_Ssh_Key) (datatypes.SoftLayer_Security_Ssh_Key, error) {
parameters := datatypes.SoftLayer_Shh_Key_Parameters{
Parameters: []datatypes.SoftLayer_Security_Ssh_Key{
template,
},
}
requestBody, err := json.Marshal(parameters)
if err != nil {
return datatypes.SoftLayer_Security_Ssh_Key{}, err
}
data, errorCode, err := slssks.client.GetHttpClient().DoRawHttpRequest(fmt.Sprintf("%s/createObject", slssks.GetName()), "POST", bytes.NewBuffer(requestBody))
if err != nil {
return datatypes.SoftLayer_Security_Ssh_Key{}, err
}
if common.IsHttpErrorCode(errorCode) {
errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Security_Ssh_Key#createObject, HTTP error code: '%d'", errorCode)
return datatypes.SoftLayer_Security_Ssh_Key{}, errors.New(errorMessage)
}
err = slssks.client.GetHttpClient().CheckForHttpResponseErrors(data)
if err != nil {
return datatypes.SoftLayer_Security_Ssh_Key{}, err
}
softLayer_Ssh_Key := datatypes.SoftLayer_Security_Ssh_Key{}
err = json.Unmarshal(data, &softLayer_Ssh_Key)
if err != nil {
return datatypes.SoftLayer_Security_Ssh_Key{}, err
}
return softLayer_Ssh_Key, nil
}
开发者ID:RezaDKhan,项目名称:terraform,代码行数:35,代码来源:softlayer_security_ssh_key.go
示例3: AttachNetworkStorageToHardware
func (slns *softLayer_Network_Storage_Service) AttachNetworkStorageToHardware(hardware datatypes.SoftLayer_Hardware, volumeId int) (bool, error) {
parameters := datatypes.SoftLayer_Hardware_Parameters{
Parameters: []datatypes.SoftLayer_Hardware{
hardware,
},
}
requestBody, err := json.Marshal(parameters)
if err != nil {
return false, err
}
resp, errorCode, err := slns.client.GetHttpClient().DoRawHttpRequest(fmt.Sprintf("%s/%d/allowAccessFromHardware.json", slns.GetName(), volumeId), "PUT", bytes.NewBuffer(requestBody))
if err != nil {
return false, err
}
if common.IsHttpErrorCode(errorCode) {
errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Network_Storage#attachNetworkStorageToHardware, HTTP error code: '%d'", errorCode)
return false, errors.New(errorMessage)
}
allowable, err := strconv.ParseBool(string(resp[:]))
if err != nil {
return false, nil
}
return allowable, nil
}
开发者ID:mattcui,项目名称:softlayer-go,代码行数:29,代码来源:softlayer_network_storage.go
示例4: HasAllowedHardware
func (slns *softLayer_Network_Storage_Service) HasAllowedHardware(volumeId int, vmId int) (bool, error) {
filter := string(`{"allowedVirtualGuests":{"id":{"operation":"` + strconv.Itoa(vmId) + `"}}}`)
response, errorCode, err := slns.client.GetHttpClient().DoRawHttpRequestWithObjectFilterAndObjectMask(fmt.Sprintf("%s/%d/getAllowedHardware.json", slns.GetName(), volumeId), []string{"id"}, fmt.Sprintf(string(filter)), "GET", new(bytes.Buffer))
if err != nil {
return false, errors.New(fmt.Sprintf("Cannot check authentication for volume %d in vm %d", volumeId, vmId))
}
if common.IsHttpErrorCode(errorCode) {
errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Network_Storage#hasAllowedHardware, HTTP error code: '%d'", errorCode)
return false, errors.New(errorMessage)
}
hardware := []datatypes.SoftLayer_Hardware{}
err = json.Unmarshal(response, &hardware)
if err != nil {
return false, errors.New(fmt.Sprintf("Failed to unmarshal response of checking authentication for volume %d in vm %d", volumeId, vmId))
}
if len(hardware) > 0 {
return true, nil
}
return false, nil
}
开发者ID:mattcui,项目名称:softlayer-go,代码行数:25,代码来源:softlayer_network_storage.go
示例5: CreateObject
func (slbicr *softLayer_Billing_Item_Cancellation_Request_Service) CreateObject(request datatypes.SoftLayer_Billing_Item_Cancellation_Request) (datatypes.SoftLayer_Billing_Item_Cancellation_Request, error) {
parameters := datatypes.SoftLayer_Billing_Item_Cancellation_Request_Parameters{
Parameters: []datatypes.SoftLayer_Billing_Item_Cancellation_Request{
request,
},
}
requestBody, err := json.Marshal(parameters)
if err != nil {
return datatypes.SoftLayer_Billing_Item_Cancellation_Request{}, err
}
responseBytes, errorCode, err := slbicr.client.GetHttpClient().DoRawHttpRequest(fmt.Sprintf("%s/createObject.json", slbicr.GetName()), "POST", bytes.NewBuffer(requestBody))
if err != nil {
return datatypes.SoftLayer_Billing_Item_Cancellation_Request{}, err
}
if common.IsHttpErrorCode(errorCode) {
errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Billing_Item_Cancellation_Request#createObject TTP error code: '%d'", errorCode)
return datatypes.SoftLayer_Billing_Item_Cancellation_Request{}, errors.New(errorMessage)
}
result := datatypes.SoftLayer_Billing_Item_Cancellation_Request{}
err = json.Unmarshal(responseBytes, &result)
if err != nil {
return datatypes.SoftLayer_Billing_Item_Cancellation_Request{}, err
}
return result, nil
}
开发者ID:Zordrak,项目名称:terraform,代码行数:30,代码来源:softlayer_billing_item_cancellation_request.go
示例6: GetObject
func (slssks *softLayer_Security_Ssh_Key_Service) GetObject(sshKeyId int) (datatypes.SoftLayer_Security_Ssh_Key, error) {
objectMask := []string{
"createDate",
"fingerprint",
"id",
"key",
"label",
"modifyDate",
"notes",
}
response, errorCode, err := slssks.client.GetHttpClient().DoRawHttpRequestWithObjectMask(fmt.Sprintf("%s/%d/getObject.json", slssks.GetName(), sshKeyId), objectMask, "GET", new(bytes.Buffer))
if err != nil {
return datatypes.SoftLayer_Security_Ssh_Key{}, err
}
if common.IsHttpErrorCode(errorCode) {
errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Security_Ssh_Key#getObject, HTTP error code: '%d'", errorCode)
return datatypes.SoftLayer_Security_Ssh_Key{}, errors.New(errorMessage)
}
sshKey := datatypes.SoftLayer_Security_Ssh_Key{}
err = json.Unmarshal(response, &sshKey)
if err != nil {
return datatypes.SoftLayer_Security_Ssh_Key{}, err
}
return sshKey, nil
}
开发者ID:RezaDKhan,项目名称:terraform,代码行数:29,代码来源:softlayer_security_ssh_key.go
示例7: SetAvailableLocations
func (slvgbdtg *softLayer_Virtual_Guest_Block_Device_Template_Group_Service) SetAvailableLocations(id int, locations []datatypes.SoftLayer_Location) (bool, error) {
parameters := datatypes.SoftLayer_Virtual_Guest_Block_Device_Template_Group_LocationsInitParameters{
Parameters: datatypes.SoftLayer_Virtual_Guest_Block_Device_Template_Group_LocationsInitParameter{
Locations: locations,
},
}
requestBody, err := json.Marshal(parameters)
if err != nil {
return false, err
}
response, errorCode, err := slvgbdtg.client.GetHttpClient().DoRawHttpRequest(fmt.Sprintf("%s/%d/setAvailableLocations.json", slvgbdtg.GetName(), id), "POST", bytes.NewBuffer(requestBody))
if err != nil {
return false, err
}
if common.IsHttpErrorCode(errorCode) {
errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Virtual_Guest_Block_Device_Template_Group#setAvailableLocations, HTTP error code: '%d'", errorCode)
return false, errors.New(errorMessage)
}
if res := string(response[:]); res != "true" {
return false, errors.New(fmt.Sprintf("Failed to set available locations access to VGDBTG with ID: %d", id))
}
return true, nil
}
开发者ID:cloudfoundry-community,项目名称:bosh-softlayer-tools,代码行数:28,代码来源:softLayer_virtual_guest_block_device_template_group.go
示例8: GetBlockDeviceTemplateGroupsWithFilter
func (slas *softLayer_Account_Service) GetBlockDeviceTemplateGroupsWithFilter(filters string) ([]datatypes.SoftLayer_Virtual_Guest_Block_Device_Template_Group, error) {
isJson, err := common.ValidateJson(filters)
if !isJson || err != nil {
errorMessage := fmt.Sprintf("softlayer-go: filters string %s is not a valid Json formatted string, error message '%s'", filters, err.Error())
return []datatypes.SoftLayer_Virtual_Guest_Block_Device_Template_Group{}, errors.New(errorMessage)
}
path := fmt.Sprintf("%s/%s", slas.GetName(), "getBlockDeviceTemplateGroups.json")
responseBytes, errorCode, err := slas.client.GetHttpClient().DoRawHttpRequestWithObjectFilter(path, filters, "GET", &bytes.Buffer{})
if err != nil {
errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Account#getBlockDeviceTemplateGroups, error message '%s'", err.Error())
return []datatypes.SoftLayer_Virtual_Guest_Block_Device_Template_Group{}, errors.New(errorMessage)
}
if common.IsHttpErrorCode(errorCode) {
errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Account#getBlockDeviceTemplateGroups, HTTP error code: '%d'", errorCode)
return []datatypes.SoftLayer_Virtual_Guest_Block_Device_Template_Group{}, errors.New(errorMessage)
}
vgbdtGroups := []datatypes.SoftLayer_Virtual_Guest_Block_Device_Template_Group{}
err = json.Unmarshal(responseBytes, &vgbdtGroups)
if err != nil {
errorMessage := fmt.Sprintf("softlayer-go: failed to decode JSON response, err message '%s'", err.Error())
err := errors.New(errorMessage)
return []datatypes.SoftLayer_Virtual_Guest_Block_Device_Template_Group{}, err
}
return vgbdtGroups, nil
}
开发者ID:mattcui,项目名称:softlayer-go,代码行数:29,代码来源:softLayer_account.go
示例9: GetPackagesByType
func (slpp *softLayer_Product_Package_Service) GetPackagesByType(packageType string) ([]datatypes.Softlayer_Product_Package, error) {
objectMasks := []string{
"id",
"name",
"description",
"isActive",
"type.keyName",
}
filterObject := string(`{"type":{"keyName":{"operation":"` + packageType + `"}}}`)
response, errorCode, err := slpp.client.GetHttpClient().DoRawHttpRequestWithObjectFilterAndObjectMask(fmt.Sprintf("%s/getAllObjects.json", slpp.GetName()), objectMasks, filterObject, "GET", new(bytes.Buffer))
if err != nil {
return []datatypes.Softlayer_Product_Package{}, err
}
if common.IsHttpErrorCode(errorCode) {
errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Product_Package#getPackagesByType, HTTP error code: '%d'", errorCode)
return []datatypes.Softlayer_Product_Package{}, errors.New(errorMessage)
}
productPackages := []*datatypes.Softlayer_Product_Package{}
err = json.Unmarshal(response, &productPackages)
if err != nil {
return []datatypes.Softlayer_Product_Package{}, err
}
// Remove packages designated as OUTLET
// See method "#get_packages_of_type" in SoftLayer Python client for details: https://github.com/softlayer/softlayer-python/blob/master/SoftLayer/managers/ordering.py
nonOutletPackages := slpp.filterProducts(productPackages, func(productPackage *datatypes.Softlayer_Product_Package) bool {
return !strings.Contains(productPackage.Description, OUTLET_PACKAGE) && !strings.Contains(productPackage.Name, OUTLET_PACKAGE)
})
return nonOutletPackages, nil
}
开发者ID:mattcui,项目名称:softlayer-go,代码行数:35,代码来源:softlayer_product_package.go
示例10: GetObject
func (sldds *softLayer_Dns_Domain_Service) GetObject(dnsId int) (datatypes.SoftLayer_Dns_Domain, error) {
objectMask := []string{
"id",
"name",
"serial",
"updateDate",
"account",
"managedResourceFlag",
"resourceRecordCount",
"resourceRecords",
"secondary",
}
response, errorCode, err := sldds.client.GetHttpClient().DoRawHttpRequestWithObjectMask(fmt.Sprintf("%s/%d/getObject.json", sldds.GetName(), dnsId), objectMask, "GET", new(bytes.Buffer))
if err != nil {
return datatypes.SoftLayer_Dns_Domain{}, err
}
if common.IsHttpErrorCode(errorCode) {
errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Dns_Domain#getObject, HTTP error code: '%d'", errorCode)
return datatypes.SoftLayer_Dns_Domain{}, errors.New(errorMessage)
}
dns_domain := datatypes.SoftLayer_Dns_Domain{}
err = json.Unmarshal(response, &dns_domain)
if err != nil {
return datatypes.SoftLayer_Dns_Domain{}, err
}
return dns_domain, nil
}
开发者ID:mattcui,项目名称:softlayer-go,代码行数:31,代码来源:softlayer_dns_domain.go
示例11: PlaceContainerOrderVirtualGuestUpgrade
func (slpo *softLayer_Product_Order_Service) PlaceContainerOrderVirtualGuestUpgrade(order datatypes.SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade) (datatypes.SoftLayer_Container_Product_Order_Receipt, error) {
parameters := datatypes.SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade_Parameters{
Parameters: []datatypes.SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade{
order,
},
}
requestBody, err := json.Marshal(parameters)
if err != nil {
return datatypes.SoftLayer_Container_Product_Order_Receipt{}, err
}
responseBytes, errorCode, err := slpo.client.GetHttpClient().DoRawHttpRequest(fmt.Sprintf("%s/placeOrder.json", slpo.GetName()), "POST", bytes.NewBuffer(requestBody))
if err != nil {
return datatypes.SoftLayer_Container_Product_Order_Receipt{}, err
}
if common.IsHttpErrorCode(errorCode) {
errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Product_Order#placeOrder, HTTP error code: '%d'", errorCode)
return datatypes.SoftLayer_Container_Product_Order_Receipt{}, errors.New(errorMessage)
}
receipt := datatypes.SoftLayer_Container_Product_Order_Receipt{}
err = json.Unmarshal(responseBytes, &receipt)
if err != nil {
return datatypes.SoftLayer_Container_Product_Order_Receipt{}, err
}
return receipt, nil
}
开发者ID:Zordrak,项目名称:terraform,代码行数:30,代码来源:softlayer_product_order.go
示例12: DenySharingAccess
func (slvgbdtg *softLayer_Virtual_Guest_Block_Device_Template_Group_Service) DenySharingAccess(id int, accountId int) (bool, error) {
parameters := datatypes.SoftLayer_Virtual_Guest_Block_Device_Template_GroupInitParameters{
Parameters: datatypes.SoftLayer_Virtual_Guest_Block_Device_Template_GroupInitParameter{
AccountId: accountId,
},
}
requestBody, err := json.Marshal(parameters)
if err != nil {
return false, err
}
response, errorCode, err := slvgbdtg.client.GetHttpClient().DoRawHttpRequest(fmt.Sprintf("%s/%d/denySharingAccess.json", slvgbdtg.GetName(), id), "POST", bytes.NewBuffer(requestBody))
if err != nil {
return false, err
}
if common.IsHttpErrorCode(errorCode) {
errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Virtual_Guest_Block_Device_Template_Group#denySharingAccess, HTTP error code: '%d'", errorCode)
return false, errors.New(errorMessage)
}
if res := string(response[:]); res != "true" {
return false, errors.New(fmt.Sprintf("Failed to permit sharing access to VGDBTG with ID: %d to account ID: %d", id, accountId))
}
return true, nil
}
开发者ID:cloudfoundry-community,项目名称:bosh-softlayer-tools,代码行数:28,代码来源:softLayer_virtual_guest_block_device_template_group.go
示例13: CopyToExternalSource
func (slvgbdtg *softLayer_Virtual_Guest_Block_Device_Template_Group_Service) CopyToExternalSource(configuration datatypes.SoftLayer_Container_Virtual_Guest_Block_Device_Template_Configuration) (bool, error) {
parameters := datatypes.SoftLayer_Container_Virtual_Guest_Block_Device_Template_Configuration_Parameters{
Parameters: []datatypes.SoftLayer_Container_Virtual_Guest_Block_Device_Template_Configuration{configuration},
}
requestBody, err := json.Marshal(parameters)
if err != nil {
return false, err
}
response, errorCode, err := slvgbdtg.client.GetHttpClient().DoRawHttpRequest(fmt.Sprintf("%s/copyToExternalSource.json", slvgbdtg.GetName()), "POST", bytes.NewBuffer(requestBody))
if err != nil {
return false, err
}
if common.IsHttpErrorCode(errorCode) {
errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Virtual_Guest_Block_Device_Template_Group#copyToExternalSource, HTTP error code: '%d'", errorCode)
return false, errors.New(errorMessage)
}
if res := string(response[:]); res != "true" {
return false, errors.New(fmt.Sprintf("Failed to create virtual guest block device template group, got '%s' as response from the API.", res))
}
return true, nil
}
开发者ID:cloudfoundry-community,项目名称:bosh-softlayer-tools,代码行数:26,代码来源:softLayer_virtual_guest_block_device_template_group.go
示例14: CreateFromExternalSource
func (slvgbdtg *softLayer_Virtual_Guest_Block_Device_Template_Group_Service) CreateFromExternalSource(configuration datatypes.SoftLayer_Container_Virtual_Guest_Block_Device_Template_Configuration) (datatypes.SoftLayer_Virtual_Guest_Block_Device_Template_Group, error) {
parameters := datatypes.SoftLayer_Container_Virtual_Guest_Block_Device_Template_Configuration_Parameters{
Parameters: []datatypes.SoftLayer_Container_Virtual_Guest_Block_Device_Template_Configuration{configuration},
}
requestBody, err := json.Marshal(parameters)
if err != nil {
return datatypes.SoftLayer_Virtual_Guest_Block_Device_Template_Group{}, err
}
response, errorCode, err := slvgbdtg.client.GetHttpClient().DoRawHttpRequest(fmt.Sprintf("%s/createFromExternalSource.json", slvgbdtg.GetName()), "POST", bytes.NewBuffer(requestBody))
if err != nil {
return datatypes.SoftLayer_Virtual_Guest_Block_Device_Template_Group{}, err
}
if common.IsHttpErrorCode(errorCode) {
errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Virtual_Guest_Block_Device_Template_Group#createFromExternalSource, HTTP error code: '%d'", errorCode)
return datatypes.SoftLayer_Virtual_Guest_Block_Device_Template_Group{}, errors.New(errorMessage)
}
vgbdtGroup := datatypes.SoftLayer_Virtual_Guest_Block_Device_Template_Group{}
err = json.Unmarshal(response, &vgbdtGroup)
if err != nil {
return datatypes.SoftLayer_Virtual_Guest_Block_Device_Template_Group{}, err
}
return vgbdtGroup, err
}
开发者ID:cloudfoundry-community,项目名称:bosh-softlayer-tools,代码行数:28,代码来源:softLayer_virtual_guest_block_device_template_group.go
示例15: CreatePublicArchiveTransaction
func (slvgbdtg *softLayer_Virtual_Guest_Block_Device_Template_Group_Service) CreatePublicArchiveTransaction(id int, groupName string, summary string, note string, locations []datatypes.SoftLayer_Location) (int, error) {
groupName = url.QueryEscape(groupName)
summary = url.QueryEscape(summary)
note = url.QueryEscape(note)
parameters := datatypes.SoftLayer_Virtual_Guest_Block_Device_Template_GroupInitParameters2{
Parameters: []interface{}{groupName, summary, note, locations},
}
requestBody, err := json.Marshal(parameters)
if err != nil {
return 0, err
}
response, errorCode, err := slvgbdtg.client.GetHttpClient().DoRawHttpRequest(fmt.Sprintf("%s/%d/createPublicArchiveTransaction.json", slvgbdtg.GetName(), id), "POST", bytes.NewBuffer(requestBody))
if err != nil {
return 0, err
}
if common.IsHttpErrorCode(errorCode) {
errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Virtual_Guest_Block_Device_Template_Group#createPublicArchiveTransaction, HTTP error code: '%d'", errorCode)
return 0, errors.New(errorMessage)
}
transactionId, err := strconv.Atoi(string(response[:]))
if err != nil {
return 0, errors.New(fmt.Sprintf("Failed to createPublicArchiveTransaction for ID: %d, error: %s", id, string(response[:])))
}
return transactionId, nil
}
开发者ID:cloudfoundry-community,项目名称:bosh-softlayer-tools,代码行数:31,代码来源:softLayer_virtual_guest_block_device_template_group.go
示例16: AllowAccessToNetworkStorage
func (slhs *softLayer_Hardware_Service) AllowAccessToNetworkStorage(id int, storage datatypes.SoftLayer_Network_Storage) (bool, error) {
parameters := datatypes.SoftLayer_Hardware_NetworkStorage_Parameters{
Parameters: storage,
}
requestBody, err := json.Marshal(parameters)
if err != nil {
return false, err
}
response, errorCode, err := slhs.client.GetHttpClient().DoRawHttpRequest(fmt.Sprintf("%s/%d/allowAccessToNetworkStorage.json", slhs.GetName(), id), "POST", bytes.NewBuffer(requestBody))
if err != nil {
return false, err
}
if common.IsHttpErrorCode(errorCode) {
errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Hardware#allowAccessToNetworkStorage, HTTP error code: '%d'", errorCode)
return false, errors.New(errorMessage)
}
if res := string(response[:]); res != "true" {
return false, errors.New(fmt.Sprintf("Failed to allowAccessToNetworkStorage with id '%d', got '%s' as response from the API.", id, res))
}
return true, nil
}
开发者ID:TheWeatherCompany,项目名称:softlayer-go,代码行数:26,代码来源:softlayer_hardware.go
示例17: DetachDiskImage
func (slvgs *softLayer_Virtual_Guest_Service) DetachDiskImage(instanceId int, imageId int) (datatypes.SoftLayer_Provisioning_Version1_Transaction, error) {
parameters := datatypes.SoftLayer_Virtual_GuestInit_ImageId_Parameters{
Parameters: datatypes.ImageId_Parameter{
ImageId: imageId,
},
}
requestBody, err := json.Marshal(parameters)
if err != nil {
return datatypes.SoftLayer_Provisioning_Version1_Transaction{}, err
}
response, errorCode, err := slvgs.client.GetHttpClient().DoRawHttpRequest(fmt.Sprintf("%s/%d/detachDiskImage.json", slvgs.GetName(), instanceId), "POST", bytes.NewBuffer(requestBody))
if err != nil {
return datatypes.SoftLayer_Provisioning_Version1_Transaction{}, err
}
if common.IsHttpErrorCode(errorCode) {
errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Virtual_Guest#detachDiskImage, HTTP error code: '%d'", errorCode)
return datatypes.SoftLayer_Provisioning_Version1_Transaction{}, errors.New(errorMessage)
}
transaction := datatypes.SoftLayer_Provisioning_Version1_Transaction{}
err = json.Unmarshal(response, &transaction)
if err != nil {
return datatypes.SoftLayer_Provisioning_Version1_Transaction{}, err
}
return transaction, nil
}
开发者ID:TheWeatherCompany,项目名称:softlayer-go,代码行数:30,代码来源:softlayer_virtual_guest.go
示例18: ReloadOperatingSystem
func (slvgs *softLayer_Virtual_Guest_Service) ReloadOperatingSystem(instanceId int, template datatypes.Image_Template_Config) error {
parameter := [2]interface{}{"FORCE", template}
parameters := map[string]interface{}{
"parameters": parameter,
}
requestBody, err := json.Marshal(parameters)
if err != nil {
return err
}
response, errorCode, err := slvgs.client.GetHttpClient().DoRawHttpRequest(fmt.Sprintf("%s/%d/reloadOperatingSystem.json", slvgs.GetName(), instanceId), "POST", bytes.NewBuffer(requestBody))
if err != nil {
return err
}
if common.IsHttpErrorCode(errorCode) {
errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Virtual_Guest#reloadOperatingSystem, HTTP error code: '%d'", errorCode)
return errors.New(errorMessage)
}
if res := string(response[:]); res != `"1"` {
return errors.New(fmt.Sprintf("Failed to reload OS on instance with id '%d', got '%s' as response from the API.", instanceId, res))
}
return nil
}
开发者ID:TheWeatherCompany,项目名称:softlayer-go,代码行数:27,代码来源:softlayer_virtual_guest.go
示例19: EditObject
func (sldr *SoftLayer_Dns_Domain_ResourceRecord_Service) EditObject(recordId int, template datatypes.SoftLayer_Dns_Domain_ResourceRecord) (bool, error) {
parameters := datatypes.SoftLayer_Dns_Domain_ResourceRecord_Parameters{
Parameters: []datatypes.SoftLayer_Dns_Domain_ResourceRecord{
template,
},
}
requestBody, err := json.Marshal(parameters)
if err != nil {
return false, err
}
response, errorCode, err := sldr.client.GetHttpClient().DoRawHttpRequest(fmt.Sprintf("%s/%d/editObject.json", sldr.getNameByType(template.Type), recordId), "POST", bytes.NewBuffer(requestBody))
if res := string(response[:]); res != "true" {
return false, errors.New(fmt.Sprintf("Failed to edit DNS Domain Record with id: %d, got '%s' as response from the API.", recordId, res))
}
if common.IsHttpErrorCode(errorCode) {
errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Dns_Domain_ResourceRecord#editObject, HTTP error code: '%d'", errorCode)
return false, errors.New(errorMessage)
}
return true, err
}
开发者ID:Zordrak,项目名称:terraform,代码行数:25,代码来源:softlayer_dns_domain_resource_record.go
示例20: SetMetadata
func (slvgs *softLayer_Virtual_Guest_Service) SetMetadata(instanceId int, metadata string) (bool, error) {
dataBytes := []byte(metadata)
base64EncodedMetadata := base64.StdEncoding.EncodeToString(dataBytes)
parameters := datatypes.SoftLayer_SetUserMetadata_Parameters{
Parameters: []datatypes.UserMetadataArray{
[]datatypes.UserMetadata{datatypes.UserMetadata(base64EncodedMetadata)},
},
}
requestBody, err := json.Marshal(parameters)
if err != nil {
return false, err
}
response, errorCode, err := slvgs.client.GetHttpClient().DoRawHttpRequest(fmt.Sprintf("%s/%d/setUserMetadata.json", slvgs.GetName(), instanceId), "POST", bytes.NewBuffer(requestBody))
if err != nil {
return false, err
}
if res := string(response[:]); res != "true" {
return false, errors.New(fmt.Sprintf("Failed to setUserMetadata for instance with id '%d', got '%s' as response from the API.", instanceId, res))
}
if common.IsHttpErrorCode(errorCode) {
errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Virtual_Guest#setUserMetadata, HTTP error code: '%d'", errorCode)
return false, errors.New(errorMessage)
}
return true, err
}
开发者ID:TheWeatherCompany,项目名称:softlayer-go,代码行数:31,代码来源:softlayer_virtual_guest.go
注:本文中的github.com/maximilien/softlayer-go/common.IsHttpErrorCode函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论