Beispiel #1
0
func CreateAzureVM(azureVMConfiguration *Role, dnsName, location string) error {
	if azureVMConfiguration == nil {
		return fmt.Errorf(azure.ParamNotSpecifiedError, "azureVMConfiguration")
	}
	if len(dnsName) == 0 {
		return fmt.Errorf(azure.ParamNotSpecifiedError, "dnsName")
	}
	if len(location) == 0 {
		return fmt.Errorf(azure.ParamNotSpecifiedError, "location")
	}

	err := verifyDNSname(dnsName)
	if err != nil {
		return err
	}

	requestId, err := CreateHostedService(dnsName, location)
	if err != nil {
		return err
	}

	azure.WaitAsyncOperation(requestId)

	if azureVMConfiguration.UseCertAuth {
		err = uploadServiceCert(dnsName, azureVMConfiguration.CertPath)
		if err != nil {
			DeleteHostedService(dnsName)
			return err
		}
	}

	vMDeployment := createVMDeploymentConfig(azureVMConfiguration)
	vMDeploymentBytes, err := xml.Marshal(vMDeployment)
	if err != nil {
		DeleteHostedService(dnsName)
		return err
	}

	requestURL := fmt.Sprintf(azureDeploymentListURL, azureVMConfiguration.RoleName)
	requestId, err = azure.SendAzurePostRequest(requestURL, vMDeploymentBytes)
	if err != nil {
		DeleteHostedService(dnsName)
		return err
	}

	azure.WaitAsyncOperation(requestId)

	return nil
}
func CreateStorageService(name, location string) (*StorageService, error) {
	if len(name) == 0 {
		return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "name")
	}
	if len(location) == 0 {
		return nil, fmt.Errorf(azure.ParamNotSpecifiedError, "location")
	}

	storageDeploymentConfig := createStorageServiceDeploymentConf(name, location)
	deploymentBytes, err := xml.Marshal(storageDeploymentConfig)
	if err != nil {
		return nil, err
	}

	requestId, err := azure.SendAzurePostRequest(azureStorageServiceListURL, deploymentBytes)
	if err != nil {
		return nil, err
	}

	azure.WaitAsyncOperation(requestId)
	storageService, err := GetStorageServiceByName(storageDeploymentConfig.ServiceName)
	if err != nil {
		return nil, err
	}

	return storageService, nil
}
Beispiel #3
0
func RestartRole(cloudserviceName, deploymentName, roleName string) error {
	if len(cloudserviceName) == 0 {
		return fmt.Errorf(azure.ParamNotSpecifiedError, "cloudserviceName")
	}
	if len(deploymentName) == 0 {
		return fmt.Errorf(azure.ParamNotSpecifiedError, "deploymentName")
	}
	if len(roleName) == 0 {
		return fmt.Errorf(azure.ParamNotSpecifiedError, "roleName")
	}

	restartRoleOperation := createRestartRoleOperation()

	restartRoleOperationBytes, err := xml.Marshal(restartRoleOperation)
	if err != nil {
		return err
	}

	requestURL := fmt.Sprintf(azureOperationsURL, cloudserviceName, deploymentName, roleName)
	requestId, azureErr := azure.SendAzurePostRequest(requestURL, restartRoleOperationBytes)
	if azureErr != nil {
		return azureErr
	}

	azure.WaitAsyncOperation(requestId)
	return nil
}
Beispiel #4
0
func DeleteDisk(diskName string) error {
	if len(diskName) == 0 {
		return fmt.Errorf(azure.ParamNotSpecifiedError, "diskName")
	}

	requestURL := fmt.Sprintf(azureVMDiskURL, diskName)
	requestId, err := azure.SendAzureDeleteRequest(requestURL)
	if err != nil {
		return err
	}

	azure.WaitAsyncOperation(requestId)
	return nil
}
Beispiel #5
0
func DeleteVMDeployment(cloudserviceName, deploymentName string) error {
	if len(cloudserviceName) == 0 {
		return fmt.Errorf(azure.ParamNotSpecifiedError, "cloudserviceName")
	}
	if len(deploymentName) == 0 {
		return fmt.Errorf(azure.ParamNotSpecifiedError, "deploymentName")
	}

	requestURL := fmt.Sprintf(deleteAzureDeploymentURL, cloudserviceName, deploymentName)
	requestId, err := azure.SendAzureDeleteRequest(requestURL)
	if err != nil {
		return err
	}

	azure.WaitAsyncOperation(requestId)

	return nil
}
Beispiel #6
0
func DeleteHostedService(dnsName string) error {
	if len(dnsName) == 0 {
		return fmt.Errorf(azure.ParamNotSpecifiedError, "dnsName")
	}

	err := verifyDNSname(dnsName)
	if err != nil {
		return err
	}

	requestURL := fmt.Sprintf(deleteAzureHostedServiceURL, dnsName)
	requestId, err := azure.SendAzureDeleteRequest(requestURL)
	if err != nil {
		return err
	}

	azure.WaitAsyncOperation(requestId)
	return nil
}
Beispiel #7
0
func uploadServiceCert(dnsName, certPath string) error {
	certificateConfig, err := createServiceCertDeploymentConf(certPath)
	if err != nil {
		return err
	}

	certificateConfigBytes, err := xml.Marshal(certificateConfig)
	if err != nil {
		return err
	}

	requestURL := fmt.Sprintf(azureCertificatListURL, dnsName)
	requestId, azureErr := azure.SendAzurePostRequest(requestURL, certificateConfigBytes)
	if azureErr != nil {
		return azureErr
	}

	err = azure.WaitAsyncOperation(requestId)
	return err
}