Пример #1
0
        /// <author>Bart</author>
        /// <summary>
        /// Deze methode wordt gebruikt om nieuwe CloudServices aan te maken in Azure. Location of Affinitygroup mag null zijn.
        /// </summary>
        /// <param name="cloudServiceName">Is de naam die de CloudService gaat hebben.</param>
        /// <param name="location">Is de geografische lokatie die de CloudService zal hebben.</param>
        /// <param name="affinityGroupName">Is de groep waar deze CloudService bij hoort.</param>
        /// <returns>Een true of false respectiefelijk aan of de actie geslaagt is of niet.</returns>
        public Boolean CreateCloudService(string cloudServiceName, string location, string affinityGroupName = null)
        {
            ComputeManagementClient client = new ComputeManagementClient(cloudCredentials);
            HostedServiceCreateParameters hostedServiceCreateParams = new HostedServiceCreateParameters();

            if (location != null)
            {
                hostedServiceCreateParams = new HostedServiceCreateParameters
                {
                    ServiceName = cloudServiceName,
                    Location = location,
                    Label = EncodeToBase64(cloudServiceName),
                };
            }
            else if (affinityGroupName != null)
            {
                hostedServiceCreateParams = new HostedServiceCreateParameters
                {
                    ServiceName = cloudServiceName,
                    AffinityGroup = affinityGroupName,
                    Label = EncodeToBase64(cloudServiceName),
                };
            }
            try
            {
                client.HostedServices.Create(hostedServiceCreateParams);
                return true;
            }
            catch (CloudException)
            {
                return false;
            }
        }
 public static void CreateCloudService()
 {
     ComputeManagementClient client = Util.getComputeManagementClient();
     HostedServiceCreateParameters param = new HostedServiceCreateParameters();
     param.ServiceName = "rd-TestService";
     param.Location = "East Asia";
     OperationResponse response = client.HostedServices.Create(param);
     Console.WriteLine("Status Code : " + response.StatusCode);
 }
Пример #3
0
        /// <summary>
        /// Creates a service specification (configuration?) entry in Azure's database.
        /// This reserves the (Azure-unique) DNS prefix name used to access the service.
        /// </summary>
        /// <remarks>
        /// Note that this does not deploy and start the service.
        /// </remarks>
        /// <param name="serviceName">Name of the cloud service.</param>
        /// <param name="location">Geographical region where the service should be hosted.</param>
        public void CreateServiceSpecification(string serviceName, string location)
        {
            // Required: Label, ServiceName.
            // One Required (but not both): AffinityGroup, Location.
            // Optional: Description, ExtendedProperties,
            HostedServiceCreateParameters parameters = new HostedServiceCreateParameters();
            parameters.Label = serviceName;
            parameters.ServiceName = serviceName;
            parameters.Location = location;

            this.computeManager.HostedServices.Create(parameters);
        }
        /// <summary>
        ///     Create hosted service
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public string CreateHostedService(HostedServiceCreateParameters input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            if (HostedServiceExists(input.ServiceName)) return input.ServiceName;

            var affinityGroupManager = new AzureAffinityGroupManager();
            affinityGroupManager.EnsureAffinityGroupExists(input.AffinityGroup);

            ComputeManagementClient.HostedServices.CreateAsync(input, new CancellationToken()).Wait();

            Dependencies.TestResourcesCollector.Remember(AzureResourceType.HostedService, input.ServiceName, input.ServiceName);

            return input.ServiceName;
        }
Пример #5
0
 public static void createCloudServiceByAffinityGroup(string cloudServiceName, string affinityGroupName)
 {
     ComputeManagementClient client = new ComputeManagementClient(getCredentials());
     HostedServiceCreateParameters hostedServiceCreateParams = new HostedServiceCreateParameters
     {
         ServiceName = cloudServiceName,
         AffinityGroup = affinityGroupName,
         Label = EncodeToBase64(cloudServiceName),
     };
     try
     {
         client.HostedServices.Create(hostedServiceCreateParams);
     }
     catch (CloudException e)
     {
         throw e;
     }
 }
Пример #6
0
        public void ExecuteCommand()
        {
            var parameter = new HostedServiceCreateParameters()
            {
                ServiceName = this.ServiceName,
                Label = string.IsNullOrEmpty(this.Label) ? this.ServiceName : this.Label,
                ReverseDnsFqdn = this.ReverseDnsFqdn,
                Description = this.Description,
                AffinityGroup =  this.AffinityGroup,
                Location = this.Location
            };

            ExecuteClientActionNewSM(null,
                CommandRuntime.ToString(),
                () => this.ComputeClient.HostedServices.Create(parameter));
        }
        public void NewAzureVMProcess()
        {
            AzureSubscription currentSubscription = Profile.Context.Subscription;
            CloudStorageAccount currentStorage = null;
            try
            {
                currentStorage = currentSubscription.GetCloudStorageAccount(Profile);
            }
            catch (Exception ex) // couldn't access
            {
                throw new ArgumentException(Resources.CurrentStorageAccountIsNotAccessible, ex);
            }
            if (currentStorage == null) // not set
            {
                throw new ArgumentException(Resources.CurrentStorageAccountIsNotSet);
            }

            bool serviceExists = DoesCloudServiceExist(this.ServiceName);

            if (!string.IsNullOrEmpty(this.Location))
            {
                if (serviceExists)
                {
                    HostedServiceGetResponse existingSvc = null;
                    try
                    {
                        existingSvc = ComputeClient.HostedServices.Get(this.ServiceName);
                    }
                    catch
                    {
                        throw new ApplicationException(Resources.ServiceExistsLocationCanNotBeSpecified);
                    }

                    if (existingSvc == null ||
                        existingSvc.Properties == null ||
                        !this.Location.Equals(existingSvc.Properties.Location))
                    {
                        throw new ApplicationException(Resources.ServiceExistsLocationCanNotBeSpecified);
                    }
                }
            }

            if (!string.IsNullOrEmpty(this.AffinityGroup))
            {
                if (serviceExists)
                {
                    HostedServiceGetResponse existingSvc = null;
                    try
                    {
                        existingSvc = ComputeClient.HostedServices.Get(this.ServiceName);
                    }
                    catch
                    {
                        throw new ApplicationException(Resources.ServiceExistsAffinityGroupCanNotBeSpecified);
                    }

                    if (existingSvc == null ||
                        existingSvc.Properties == null ||
                        !this.AffinityGroup.Equals(existingSvc.Properties.AffinityGroup))
                    {
                        throw new ApplicationException(Resources.ServiceExistsAffinityGroupCanNotBeSpecified);
                    }
                }
            }

            if (!string.IsNullOrEmpty(this.ReverseDnsFqdn))
            {
                if (serviceExists)
                {
                    throw new ApplicationException(Resources.ServiceExistsReverseDnsFqdnCanNotBeSpecified);
                }
            }

            if (!serviceExists)
            {
                try
                {
                    //Implicitly created hosted service2012-05-07 23:12 

                    // Create the Cloud Service when
                    // Location or Affinity Group is Specified
                    // or VNET is specified and the service doesn't exist
                    var parameter = new HostedServiceCreateParameters
                    {
                        AffinityGroup = this.AffinityGroup,
                        Location = this.Location,
                        ServiceName = this.ServiceName,
                        Description = String.Format("Implicitly created hosted service{0}", DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd HH:mm")),
                        Label = this.ServiceName,
                        ReverseDnsFqdn = this.ReverseDnsFqdn
                    };

                    ExecuteClientActionNewSM(
                        parameter,
                        CommandRuntime + Resources.QuickVMCreateCloudService,
                        () => this.ComputeClient.HostedServices.Create(parameter));
                }
                catch (CloudException ex)
                {
                    WriteExceptionError(ex);
                    return;
                }
            }

            if (ParameterSetName.Equals(WindowsParamSet, StringComparison.OrdinalIgnoreCase))
            {
                if (WinRMCertificate != null)
                {
                    if (!CertUtilsNewSM.HasExportablePrivateKey(WinRMCertificate))
                    {
                        throw new ArgumentException(Resources.WinRMCertificateDoesNotHaveExportablePrivateKey);
                    }

                    var operationDescription = string.Format(Resources.QuickVMUploadingWinRMCertificate, CommandRuntime, WinRMCertificate.Thumbprint);
                    var parameters = CertUtilsNewSM.Create(WinRMCertificate);

                    ExecuteClientActionNewSM(
                        null,
                        operationDescription,
                        () => this.ComputeClient.ServiceCertificates.Create(this.ServiceName, parameters),
                        (s, r) => ContextFactory<OperationStatusResponse, ManagementOperationContext>(r, s));
                }

                if (X509Certificates != null)
                {
                    var certificateFilesWithThumbprint = from c in X509Certificates
                                                         select new
                                                         {
                                                             c.Thumbprint,
                                                             CertificateFile = CertUtilsNewSM.Create(c, this.NoExportPrivateKey.IsPresent)
                                                         };
                    foreach (var current in certificateFilesWithThumbprint.ToList())
                    {
                        var operationDescription = string.Format(Resources.QuickVMUploadingCertificate, CommandRuntime, current.Thumbprint);
                        ExecuteClientActionNewSM(
                            null,
                            operationDescription,
                            () => this.ComputeClient.ServiceCertificates.Create(this.ServiceName, current.CertificateFile),
                            (s, r) => ContextFactory<OperationStatusResponse, ManagementOperationContext>(r, s));
                    }
                }
            }

            var vm = CreatePersistenVMRole(currentStorage);

            try
            {
                if (CurrentDeploymentNewSM == null)
                {
                    // If the current deployment doesn't exist set it create it
                    var parameters = new VirtualMachineCreateDeploymentParameters
                    {
                        DeploymentSlot     = DeploymentSlot.Production,
                        Name               = this.ServiceName,
                        Label              = this.ServiceName,
                        VirtualNetworkName = this.VNetName,
                        Roles              = { vm },
                        ReservedIPName     = this.ReservedIPName,
                        DnsSettings        = this.DnsSettings == null ? null : new Microsoft.WindowsAzure.Management.Compute.Models.DnsSettings
                                             {
                                                 DnsServers = (from dns in this.DnsSettings
                                                               select new Management.Compute.Models.DnsServer
                                                               {
                                                                   Name = dns.Name,
                                                                   Address = dns.Address
                                                               }).ToList()
                                             }
                    };

                    ExecuteClientActionNewSM(
                        parameters,
                        string.Format(Resources.QuickVMCreateDeploymentWithVM, CommandRuntime, vm.RoleName),
                        () => this.ComputeClient.VirtualMachines.CreateDeployment(this.ServiceName, parameters));
                }
                else
                {
                    if (!string.IsNullOrEmpty(VNetName) || DnsSettings != null)
                    {
                        WriteWarning(Resources.VNetNameOrDnsSettingsCanOnlyBeSpecifiedOnNewDeployments);
                    }

                    // Only create the VM when a new VM was added and it was not created during the deployment phase.
                    ExecuteClientActionNewSM(
                        vm,
                        string.Format(Resources.QuickVMCreateVM, CommandRuntime, vm.RoleName),
                        () => this.ComputeClient.VirtualMachines.Create(
                            this.ServiceName,
                            this.ServiceName,
                            new VirtualMachineCreateParameters
                            {
                                AvailabilitySetName         = vm.AvailabilitySetName,
                                OSVirtualHardDisk           = vm.OSVirtualHardDisk,
                                DataVirtualHardDisks        = vm.DataVirtualHardDisks,
                                RoleName                    = vm.RoleName,
                                RoleSize                    = vm.RoleSize,
                                VMImageName                 = vm.VMImageName,
                                MediaLocation               = vm.MediaLocation,
                                ProvisionGuestAgent         = vm.ProvisionGuestAgent,
                                ResourceExtensionReferences = vm.ResourceExtensionReferences,
                                ConfigurationSets           = vm.ConfigurationSets
                            }));
                }

                if (WaitForBoot.IsPresent)
                {
                    WaitForRoleToBoot(vm.RoleName);
                }
            }
            catch (CloudException ex)
            {
                if (ex.Response.StatusCode == HttpStatusCode.NotFound)
                {
                    throw new Exception(Resources.ServiceDoesNotExistSpecifyLocationOrAffinityGroup);
                }

                WriteExceptionError(ex);
            }
        }
 /// <summary>
 /// The Create Hosted Service operation creates a new cloud service in
 /// Azure.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/gg441304.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Compute.IHostedServiceOperations.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Create Hosted Service
 /// operation.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static Task<AzureOperationResponse> CreateAsync(this IHostedServiceOperations operations, HostedServiceCreateParameters parameters)
 {
     return operations.CreateAsync(parameters, CancellationToken.None);
 }
 /// <summary>
 /// The Create Hosted Service operation creates a new cloud service in
 /// Azure.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/gg441304.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Compute.IHostedServiceOperations.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Create Hosted Service
 /// operation.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static AzureOperationResponse Create(this IHostedServiceOperations operations, HostedServiceCreateParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IHostedServiceOperations)s).CreateAsync(parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
Пример #10
0
        public void NewAzureVMProcess()
        {
            AzureSubscription currentSubscription = Profile.Context.Subscription;
            CloudStorageAccount currentStorage = null;
            try
            {
                currentStorage = currentSubscription.GetCloudStorageAccount(Profile);
            }
            catch (Exception ex) // couldn't access
            {
                throw new ArgumentException(Resources.CurrentStorageAccountIsNotAccessible, ex);
            }

            if (currentStorage == null) // not set
            {
                throw new ArgumentException(Resources.CurrentStorageAccountIsNotSet);
            }

            if (this.ParameterSetName.Equals("CreateService", StringComparison.OrdinalIgnoreCase))
            {
                var parameter = new HostedServiceCreateParameters
                {
                    AffinityGroup = this.AffinityGroup,
                    Location = this.Location,
                    ServiceName = this.ServiceName,
                    Description = this.ServiceDescription ?? String.Format(
                                      "Implicitly created hosted service{0}",
                                      DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd HH:mm")),
                    Label = this.ServiceLabel ?? this.ServiceName,
                    ReverseDnsFqdn = this.ReverseDnsFqdn
                };

                try
                {
                    this.ComputeClient.HostedServices.Create(parameter);
                }
                catch (CloudException ex)
                {
                    if (string.Equals(ex.Error.Code, "ConflictError"))
                    {
                        HostedServiceGetResponse existingService = this.ComputeClient.HostedServices.Get(this.ServiceName);

                        if (existingService == null || existingService.Properties == null)
                        {
                            // The same service name is already used by another subscription.
                            WriteExceptionError(ex);
                            return;
                        }
                        else if ((string.IsNullOrEmpty(existingService.Properties.Location) &&
                            string.Compare(existingService.Properties.AffinityGroup, this.AffinityGroup, StringComparison.InvariantCultureIgnoreCase) == 0)
                            || (string.IsNullOrEmpty(existingService.Properties.AffinityGroup) &&
                            string.Compare(existingService.Properties.Location, this.Location, StringComparison.InvariantCultureIgnoreCase) == 0))
                        {
                            // The same service name is already created under the same subscription,
                            // and its affinity group or location is matched with the given parameter.
                            this.WriteWarning(ex.Error.Message);
                        }
                        else
                        {
                            // The same service name is already created under the same subscription,
                            // but its affinity group or location is not matched with the given parameter.
                            this.WriteWarning("Location or AffinityGroup name is not matched with the existing service");
                            WriteExceptionError(ex);
                            return;
                        }
                    }
                    else
                    {
                        WriteExceptionError(ex);
                        return;
                    }
                }
            }

            foreach (var vm in from v in VMs let configuration = v.ConfigurationSets.OfType<Model.WindowsProvisioningConfigurationSet>().FirstOrDefault() where configuration != null select v)
            {
                if (vm.WinRMCertificate != null)
                {
                    if(!CertUtilsNewSM.HasExportablePrivateKey(vm.WinRMCertificate))
                    {
                        throw new ArgumentException(Resources.WinRMCertificateDoesNotHaveExportablePrivateKey);
                    }

                    var operationDescription = string.Format(Resources.AzureVMUploadingWinRMCertificate, CommandRuntime, vm.WinRMCertificate.Thumbprint);
                    var parameters = CertUtilsNewSM.Create(vm.WinRMCertificate);

                    ExecuteClientActionNewSM(
                        null,
                        operationDescription,
                        () => this.ComputeClient.ServiceCertificates.Create(this.ServiceName, parameters),
                        (s, r) => ContextFactory<OperationStatusResponse, ManagementOperationContext>(r, s));

                }

                var certificateFilesWithThumbprint = from c in vm.X509Certificates
                    select new
                           {
                               c.Thumbprint,
                               CertificateFile = CertUtilsNewSM.Create(c, vm.NoExportPrivateKey)
                           };

                foreach (var current in certificateFilesWithThumbprint.ToList())
                {
                    var operationDescription = string.Format(Resources.AzureVMCommandUploadingCertificate, CommandRuntime, current.Thumbprint);
                    ExecuteClientActionNewSM(
                        null,
                        operationDescription,
                        () => this.ComputeClient.ServiceCertificates.Create(this.ServiceName, current.CertificateFile),
                        (s, r) => ContextFactory<OperationStatusResponse, ManagementOperationContext>(r, s));
                }
            }

            var persistentVMs = this.VMs.Select((vm, index) => CreatePersistentVMRole(VMTuples[index], currentStorage)).ToList();

            // If the current deployment doesn't exist set it create it
            if (CurrentDeploymentNewSM == null)
            {
                try
                {
                    var parameters = new VirtualMachineCreateDeploymentParameters
                    {
                        DeploymentSlot = DeploymentSlot.Production,
                        Name = this.DeploymentName ?? this.ServiceName,
                        Label = this.DeploymentLabel ?? this.ServiceName,
                        VirtualNetworkName = this.VNetName,
                        Roles = { persistentVMs[0] },
                        ReservedIPName = ReservedIPName
                    };

                    if (this.DnsSettings != null)
                    {
                        parameters.DnsSettings = new Management.Compute.Models.DnsSettings();

                        foreach (var dns in this.DnsSettings)
                        {
                            parameters.DnsSettings.DnsServers.Add(
                                new Microsoft.WindowsAzure.Management.Compute.Models.DnsServer
                                {
                                    Name = dns.Name,
                                    Address = dns.Address
                                });
                        }
                    }

                    if (this.InternalLoadBalancerConfig != null)
                    {
                        parameters.LoadBalancers = new LoadBalancer[1]
                        {
                            new LoadBalancer
                            {
                                Name = this.InternalLoadBalancerConfig.InternalLoadBalancerName,
                                FrontendIPConfiguration = new FrontendIPConfiguration
                                {
                                    Type = FrontendIPConfigurationType.Private,
                                    SubnetName = this.InternalLoadBalancerConfig.SubnetName,
                                    StaticVirtualNetworkIPAddress = this.InternalLoadBalancerConfig.IPAddress
                                }
                            }
                        };
                    }

                    var operationDescription = string.Format(Resources.AzureVMCommandCreateDeploymentWithVM, CommandRuntime, persistentVMs[0].RoleName);
                    ExecuteClientActionNewSM(
                        parameters,
                        operationDescription,
                        () => this.ComputeClient.VirtualMachines.CreateDeployment(this.ServiceName, parameters));

                    if(this.WaitForBoot.IsPresent)
                    {
                        WaitForRoleToBoot(persistentVMs[0].RoleName);
                    }
                }
                catch (CloudException ex)
                {
                    if (ex.Response.StatusCode == HttpStatusCode.NotFound)
                    {
                        throw new Exception(Resources.ServiceDoesNotExistSpecifyLocationOrAffinityGroup);
                    }
                    else
                    {
                        WriteExceptionError(ex);
                    }

                    return;
                }

                this.createdDeployment = true;
            }
            else
            {
                if (this.VNetName != null || this.DnsSettings != null || !string.IsNullOrEmpty(this.DeploymentLabel) || !string.IsNullOrEmpty(this.DeploymentName))
                {
                    WriteWarning(Resources.VNetNameDnsSettingsDeploymentLabelDeploymentNameCanBeSpecifiedOnNewDeployments);
                }
            }

            if (this.createdDeployment == false && CurrentDeploymentNewSM != null)
            {
                this.DeploymentName = CurrentDeploymentNewSM.Name;
            }

            int startingVM = this.createdDeployment ? 1 : 0;

            for (int i = startingVM; i < persistentVMs.Count; i++)
            {
                var operationDescription = string.Format(Resources.AzureVMCommandCreateVM, CommandRuntime, persistentVMs[i].RoleName);
                
                var parameter = new VirtualMachineCreateParameters
                {
                    AvailabilitySetName = persistentVMs[i].AvailabilitySetName,
                    OSVirtualHardDisk = VMTuples[i].Item3 ? null : persistentVMs[i].OSVirtualHardDisk,
                    RoleName = persistentVMs[i].RoleName,
                    RoleSize = persistentVMs[i].RoleSize,
                    ProvisionGuestAgent = persistentVMs[i].ProvisionGuestAgent,
                    ResourceExtensionReferences = persistentVMs[i].ProvisionGuestAgent != null && persistentVMs[i].ProvisionGuestAgent.Value ? persistentVMs[i].ResourceExtensionReferences : null,
                    VMImageName = VMTuples[i].Item3 ? persistentVMs[i].VMImageName : null,
                    MediaLocation = VMTuples[i].Item3 ? persistentVMs[i].MediaLocation : null
                };

                if (parameter.OSVirtualHardDisk != null)
                {
                    parameter.OSVirtualHardDisk.IOType = null;
                }

                if (persistentVMs[i].DataVirtualHardDisks != null && persistentVMs[i].DataVirtualHardDisks.Any())
                {
                    persistentVMs[i].DataVirtualHardDisks.ForEach(c => parameter.DataVirtualHardDisks.Add(c));
                    parameter.DataVirtualHardDisks.ForEach(d => d.IOType = null);
                }

                persistentVMs[i].ConfigurationSets.ForEach(c => parameter.ConfigurationSets.Add(c));

                ExecuteClientActionNewSM(
                    persistentVMs[i],
                    operationDescription,
                    () => this.ComputeClient.VirtualMachines.Create(this.ServiceName, this.DeploymentName ?? this.ServiceName, parameter));
            }

            if(this.WaitForBoot.IsPresent)
            {
                for (int i = startingVM; i < persistentVMs.Count; i++)
                {
                    WaitForRoleToBoot(persistentVMs[i].RoleName);
                }
            }
        }
        /// <summary>
        /// Checks for the existence of a specific Cloud Service, if it doesn't exist it will create it.
        /// </summary>
        /// <param name="client">The <see cref="ComputeManagementClient"/> that is performing the operation.</param>
        /// <param name="parameters">The <see cref="HostedServiceCreateParameters"/> that define the service we want to create.</param>
        /// <returns>The async <see cref="Task"/> wrapper.</returns>
        public static async Task CreateServiceIfNotExistsAsync(this ComputeManagementClient client, HostedServiceCreateParameters parameters)
        {
            Contract.Requires(client != null);
            Contract.Requires(parameters != null);

            HostedServiceGetResponse service = null;
            FlexStreams.BuildEventsObserver.OnNext(new CheckIfExistsEvent(AzureResource.CloudService, parameters.ServiceName));

            try
            {
                service = await client.HostedServices.GetAsync(parameters.ServiceName);
            }
            catch (CloudException cex)
            {
                if (cex.Error.Code != "ResourceNotFound") throw;
            }

            if (service != null)
            {
                FlexStreams.BuildEventsObserver.OnNext(new FoundExistingEvent(AzureResource.CloudService, parameters.ServiceName));
                return;
            }

            await client.HostedServices.CreateAsync(parameters);
            FlexStreams.BuildEventsObserver.OnNext(new ProvisionEvent(AzureResource.CloudService, parameters.ServiceName));
        }
Пример #12
0
        /// <summary>
        /// Creates cloud service if it does not exist.
        /// </summary>
        /// <param name="name">The cloud service name</param>
        /// <param name="label">The cloud service label</param>
        /// <param name="location">The location to create the cloud service in.</param>
        /// <param name="affinityGroup">Affinity group name for cloud service</param>
        public void CreateCloudServiceIfNotExist(
            string name,
            string label = null,
            string location = null,
            string affinityGroup = null)
        {
            if (!CloudServiceExists(name))
            {
                WriteVerboseWithTimestamp(Resources.PublishCreatingServiceMessage);

                var createParameters = new HostedServiceCreateParameters
                {
                    ServiceName = name,
                    Label = label
                };

                if (!string.IsNullOrEmpty(affinityGroup))
                {
                    createParameters.AffinityGroup = affinityGroup;
                }
                else
                {
                    location = string.IsNullOrEmpty(location) ? GetDefaultLocation() : location;
                    createParameters.Location = location;
                }

                ComputeClient.HostedServices.Create(createParameters);

                WriteVerboseWithTimestamp(Resources.PublishCreatedServiceMessage, name);
            }
        }
        protected PSArgument[] CreateHostedServiceCreateParameters()
        {
            HostedServiceCreateParameters parameters = new HostedServiceCreateParameters();

            return ConvertFromObjectsToArguments(new string[] { "Parameters" }, new object[] { parameters });
        }
 /// <summary>
 /// The Create Hosted Service operation creates a new cloud service in
 /// Windows Azure.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/gg441304.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Compute.IHostedServiceOperations.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the Create Hosted Service operation.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static OperationResponse Create(this IHostedServiceOperations operations, HostedServiceCreateParameters parameters)
 {
     try
     {
         return operations.CreateAsync(parameters).Result;
     }
     catch (AggregateException ex)
     {
         if (ex.InnerExceptions.Count > 1)
         {
             throw;
         }
         else
         {
             throw ex.InnerException;
         }
     }
 }
        public async Task Test_CheckCreateCloudService_WithNewService()
        {
            using (var client = ManagementClient.CreateComputeClient())
            {
                var parameters =
                    new HostedServiceCreateParameters
                    {
                        Label = "Integration Test",
                        Location = LocationNames.NorthEurope,
                        ServiceName = "fct-" + Guid.NewGuid().ToString().Split('-').Last()
                    };

                try
                {
                    await client.CreateServiceIfNotExistsAsync(parameters);

                    var service = await client.HostedServices.GetAsync(parameters.ServiceName);
                    Assert.IsNotNull(service);
                }
                finally
                {
                    client.HostedServices.Delete(parameters.ServiceName);
                }
            }
        }