Пример #1
0
        /// <summary>
        ///     Create hosted service
        /// </summary>
        /// <param name="hostedServiceName"></param>
        /// <returns></returns>
        public string CreateHostedService(string hostedServiceName = "")
        {
            if (string.IsNullOrEmpty(hostedServiceName))
            {
                hostedServiceName = Dependencies.TestResourcesCollector.GetUniqueHostedServiceName();
            }

            const string affinityGroup = AzureServiceConstants.DefaultAffinityGroup;

            return(CreateHostedService(new HostedServiceCreateParameters
            {
                ServiceName = hostedServiceName,
                Label = Base64EncodingHelper.EncodeToBase64String(AzureServiceConstants.DefaultLabel),
                Description = "",
                AffinityGroup = affinityGroup
            }));
        }
        /// <summary>
        ///     Create storage service
        /// </summary>
        /// <param name="storageServiceName"></param>
        /// <returns></returns>
        public StorageAccount CreateStorageService(string storageServiceName = "")
        {
            if (string.IsNullOrEmpty(storageServiceName))
            {
                // notice that we reuse our default storage service since, usually number of
                // storage services is limited and we can't create them for each test.
                storageServiceName = Dependencies.Subscription.DefaultStorageName;
            }

            return(CreateStorageService(new StorageAccountCreateParameters
            {
                Name = storageServiceName,
                Label = Base64EncodingHelper.EncodeToBase64String(AzureServiceConstants.DefaultLabel),
                Description = "",
                AffinityGroup = AzureServiceConstants.DefaultAffinityGroup,
                GeoReplicationEnabled = false,
            }));
        }
        /// <summary>
        ///     Create virtual machine
        /// </summary>
        /// <param name="hostedServiceName"></param>
        /// <param name="osVirtualHardDisk"></param>
        /// <param name="configurationSets"></param>
        /// <param name="dataVirtualHardDisks"></param>
        /// <param name="virtualMachineName"></param>
        /// <param name="deploymentName"></param>
        /// <returns></returns>
        public string CreateVirtualMachine(
            string hostedServiceName,
            OSVirtualHardDisk osVirtualHardDisk,
            IList <ConfigurationSet> configurationSets,
            IList <DataVirtualHardDisk> dataVirtualHardDisks = null,
            string virtualMachineName = "",
            string deploymentName     = "")
        {
            if (string.IsNullOrEmpty(deploymentName))
            {
                deploymentName = Dependencies.TestResourcesCollector.GetUniqueDeploymentName();
            }

            if (string.IsNullOrEmpty(virtualMachineName))
            {
                virtualMachineName = Dependencies.TestResourcesCollector.GetUniqueVirtualMachineName();
            }

            var csm = new AzureCloudServiceManager();

            csm.CreateOrUpdateDeployment(hostedServiceName, new DeploymentCreateParameters {
                Name = deploymentName
            });

            var vmDeployment = csm.CreateOrUpdateDeployment(hostedServiceName, new DeploymentCreateParameters {
                Name  = deploymentName,
                Label = Base64EncodingHelper.EncodeToBase64String(AzureServiceConstants.DefaultLabel)
            });

            var vmRole = new Role
            {
                RoleName             = virtualMachineName,
                RoleType             = "PersistentVMRole",
                OSVirtualHardDisk    = osVirtualHardDisk,
                ConfigurationSets    = configurationSets,
                DataVirtualHardDisks = dataVirtualHardDisks
            };

            vmDeployment.Roles.Add(vmRole);

            return(CreateVirtualMachine(hostedServiceName, vmDeployment, virtualMachineName));
        }