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
}
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
}
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
}
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
}
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
}
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
}
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
}
예제 #8
0
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
}
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
}
예제 #10
0
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
}
예제 #11
0
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
func (slvgs *softLayer_Virtual_Guest_Service) SetTags(instanceId int, tags []string) (bool, error) {
	var tagStringBuffer bytes.Buffer
	for i, tag := range tags {
		tagStringBuffer.WriteString(tag)
		if i != len(tags)-1 {
			tagStringBuffer.WriteString(", ")
		}
	}

	setTagsParameters := datatypes.SoftLayer_Virtual_Guest_SetTags_Parameters{
		Parameters: []string{tagStringBuffer.String()},
	}

	requestBody, err := json.Marshal(setTagsParameters)
	if err != nil {
		return false, err
	}

	response, errorCode, err := slvgs.client.GetHttpClient().DoRawHttpRequest(fmt.Sprintf("%s/%d/setTags.json", slvgs.GetName(), instanceId), "POST", bytes.NewBuffer(requestBody))
	if err != nil {
		return false, err
	}

	if common.IsHttpErrorCode(errorCode) {
		errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Virtual_Guest#setTags, HTTP error code: '%d'", errorCode)
		return false, errors.New(errorMessage)
	}

	if res := string(response[:]); res != "true" {
		return false, errors.New(fmt.Sprintf("Failed to setTags for instance with id '%d', got '%s' as response from the API.", instanceId, res))
	}

	return true, nil
}
func (slvgs *softLayer_Virtual_Guest_Service) CreateArchiveTransaction(instanceId int, groupName string, blockDevices []datatypes.SoftLayer_Virtual_Guest_Block_Device, note string) (datatypes.SoftLayer_Provisioning_Version1_Transaction, error) {
	groupName = url.QueryEscape(groupName)
	note = url.QueryEscape(note)

	parameters := datatypes.SoftLayer_Virtual_GuestInitParameters{
		Parameters: []interface{}{groupName, blockDevices, note},
	}

	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/createArchiveTransaction.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#createArchiveTransaction, 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
}
func (slvgs *softLayer_Virtual_Guest_Service) EditObject(instanceId int, template datatypes.SoftLayer_Virtual_Guest) (bool, error) {
	parameters := datatypes.SoftLayer_Virtual_Guest_Parameters{
		Parameters: []datatypes.SoftLayer_Virtual_Guest{template},
	}

	requestBody, err := json.Marshal(parameters)
	if err != nil {
		return false, err
	}

	response, errorCode, err := slvgs.client.GetHttpClient().DoRawHttpRequest(fmt.Sprintf("%s/%d/editObject.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 edit virtual guest 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#editObject, HTTP error code: '%d'", errorCode)
		return false, errors.New(errorMessage)
	}

	return true, err
}
func (sldr *SoftLayer_Dns_Domain_ResourceRecord_Service) CreateObject(template datatypes.SoftLayer_Dns_Domain_ResourceRecord_Template) (datatypes.SoftLayer_Dns_Domain_ResourceRecord, error) {
	parameters := datatypes.SoftLayer_Dns_Domain_ResourceRecord_Template_Parameters{
		Parameters: []datatypes.SoftLayer_Dns_Domain_ResourceRecord_Template{
			template,
		},
	}

	requestBody, err := json.Marshal(parameters)
	if err != nil {
		return datatypes.SoftLayer_Dns_Domain_ResourceRecord{}, err
	}

	response, errorCode, err := sldr.client.GetHttpClient().DoRawHttpRequest(fmt.Sprintf("%s/createObject", sldr.getNameByType(template.Type)), "POST", bytes.NewBuffer(requestBody))
	if err != nil {
		return datatypes.SoftLayer_Dns_Domain_ResourceRecord{}, err
	}

	if common.IsHttpErrorCode(errorCode) {
		errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Dns_Domain_ResourceRecord#createObject, HTTP error code: '%d'", errorCode)
		return datatypes.SoftLayer_Dns_Domain_ResourceRecord{}, errors.New(errorMessage)
	}

	err = sldr.client.GetHttpClient().CheckForHttpResponseErrors(response)
	if err != nil {
		return datatypes.SoftLayer_Dns_Domain_ResourceRecord{}, err
	}

	dns_record := datatypes.SoftLayer_Dns_Domain_ResourceRecord{}
	err = json.Unmarshal(response, &dns_record)
	if err != nil {
		return datatypes.SoftLayer_Dns_Domain_ResourceRecord{}, err
	}

	return dns_record, nil
}
func (slhs *softLayer_Hardware_Service) CreateObject(template datatypes.SoftLayer_Hardware_Template) (datatypes.SoftLayer_Hardware, error) {
	parameters := datatypes.SoftLayer_Hardware_Template_Parameters{
		Parameters: []datatypes.SoftLayer_Hardware_Template{
			template,
		},
	}

	requestBody, err := json.Marshal(parameters)
	if err != nil {
		return datatypes.SoftLayer_Hardware{}, err
	}

	response, errorCode, err := slhs.client.GetHttpClient().DoRawHttpRequest(fmt.Sprintf("%s.json", slhs.GetName()), "POST", bytes.NewBuffer(requestBody))
	if err != nil {
		return datatypes.SoftLayer_Hardware{}, err
	}

	if common.IsHttpErrorCode(errorCode) {
		errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Hardware#createObject, HTTP error code: '%d'", errorCode)
		return datatypes.SoftLayer_Hardware{}, errors.New(errorMessage)
	}

	err = slhs.client.GetHttpClient().CheckForHttpResponseErrors(response)
	if err != nil {
		return datatypes.SoftLayer_Hardware{}, err
	}

	hardware := datatypes.SoftLayer_Hardware{}
	err = json.Unmarshal(response, &hardware)
	if err != nil {
		return datatypes.SoftLayer_Hardware{}, err
	}

	return hardware, nil
}
예제 #26
0
func (slas *softLayer_Account_Service) GetIscsiNetworkStorageWithFilter(filter string) ([]datatypes.SoftLayer_Network_Storage, error) {
	path := fmt.Sprintf("%s/%s", slas.GetName(), "getIscsiNetworkStorage.json")

	objectMasks := []string{
		"username",
		"accountId",
		"capacityGb",
		"id",
		"billingItem.id",
		"billingItem.orderItem.order.id",
	}

	responseBytes, errorCode, err := slas.client.GetHttpClient().DoRawHttpRequestWithObjectFilterAndObjectMask(path, objectMasks, filter, "GET", &bytes.Buffer{})
	if err != nil {
		errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Account#getIscsiNetworkStorage, error message '%s'", err.Error())
		return []datatypes.SoftLayer_Network_Storage{}, errors.New(errorMessage)
	}

	if common.IsHttpErrorCode(errorCode) {
		errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Account#getIscsiNetworkStorage, HTTP error code: '%d'", errorCode)
		return []datatypes.SoftLayer_Network_Storage{}, errors.New(errorMessage)
	}

	networkStorage := []datatypes.SoftLayer_Network_Storage{}
	err = json.Unmarshal(responseBytes, &networkStorage)
	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_Network_Storage{}, err
	}

	return networkStorage, nil
}
예제 #27
0
func (slpp *softLayer_Product_Package_Service) GetItems(packageId int) ([]datatypes.SoftLayer_Product_Item, error) {
	objectMasks := []string{
		"id",
		"capacity",
		"description",
		"prices.id",
		"prices.categories.id",
		"prices.categories.name",
	}

	response, errorCode, err := slpp.client.GetHttpClient().DoRawHttpRequestWithObjectMask(fmt.Sprintf("%s/%d/getItems.json", slpp.GetName(), packageId), objectMasks, "GET", new(bytes.Buffer))
	if err != nil {
		return []datatypes.SoftLayer_Product_Item{}, err
	}

	if common.IsHttpErrorCode(errorCode) {
		errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Product_Package#getItems, HTTP error code: '%d'", errorCode)
		return []datatypes.SoftLayer_Product_Item{}, errors.New(errorMessage)
	}

	productItems := []datatypes.SoftLayer_Product_Item{}
	err = json.Unmarshal(response, &productItems)
	if err != nil {
		return []datatypes.SoftLayer_Product_Item{}, err
	}

	return productItems, nil
}
func (slvgbdtg *softLayer_Virtual_Guest_Block_Device_Template_Group_Service) GetGlobalIdentifier(id int) (string, error) {
	response, errorCode, err := slvgbdtg.client.GetHttpClient().DoRawHttpRequest(fmt.Sprintf("%s/%d/getGlobalIdentifier.json", slvgbdtg.GetName(), id), "GET", new(bytes.Buffer))

	if common.IsHttpErrorCode(errorCode) {
		errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Virtual_Guest_Block_Device_Template_Group#getGlobalIdentifier, HTTP error code: '%d'", errorCode)
		return "", errors.New(errorMessage)
	}

	return string(strings.TrimSpace(string(response))), err
}
func (slhs *softLayer_Hardware_Service) GetAttachedNetworkStorages(id int, nasType string) ([]datatypes.SoftLayer_Network_Storage, error) {

	nasTypeParameters := datatypes.SoftLayer_Hardware_String_Parameters{
		Parameters: []string{nasType},
	}

	requestBody, err := json.Marshal(nasTypeParameters)
	if err != nil {
		return []datatypes.SoftLayer_Network_Storage{}, err
	}

	objectMask := []string{
		"accountId",
		"capacityGb",
		"createDate",
		"guestId",
		"hardwareId",
		"hostId",
		"id",
		"fullyQualifiedDomainName",
		"nasType",
		"notes",
		"Password",
		"serviceProviderId",
		"upgradableFlag",
		"username",
		"billingItem.id",
		"billingItem.orderItem.order.id",
		"lunId",
		"serviceResourceBackendIpAddress",
	}

	response, errorCode, err := slhs.client.GetHttpClient().DoRawHttpRequestWithObjectMask(fmt.Sprintf("%s/%d/getAttachedNetworkStorages.json", slhs.GetName(), id), objectMask, "POST", bytes.NewBuffer(requestBody))
	if err != nil {
		return []datatypes.SoftLayer_Network_Storage{}, err
	}

	if common.IsHttpErrorCode(errorCode) {
		errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Hardware#getAttachedNetworkStorages, HTTP error code: '%d'", errorCode)
		return []datatypes.SoftLayer_Network_Storage{}, errors.New(errorMessage)
	}

	err = slhs.client.GetHttpClient().CheckForHttpResponseErrors(response)
	if err != nil {
		return []datatypes.SoftLayer_Network_Storage{}, err
	}

	storageList := []datatypes.SoftLayer_Network_Storage{}
	err = json.Unmarshal(response, &storageList)
	if err != nil {
		return []datatypes.SoftLayer_Network_Storage{}, err
	}

	return storageList, nil
}
func (slhs *softLayer_Hardware_Service) GetPrimaryBackendIpAddress(id int) (string, error) {
	response, errorCode, err := slhs.client.GetHttpClient().DoRawHttpRequest(fmt.Sprintf("%s/%d/getPrimaryBackendIpAddress.json", slhs.GetName(), id), "GET", new(bytes.Buffer))
	if err != nil {
		return "", err
	}

	if common.IsHttpErrorCode(errorCode) {
		errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Hardware#getPrimaryBackendIpAddress, HTTP error code: '%d'", errorCode)
		return "", errors.New(errorMessage)
	}

	return string(response[:]), nil
}