Esempio n. 1
0
        public Task <IWithCreate> GenerateVmTemplateAsync(string vmNameBase, Region location, string groupName, string imageId, string user, string password, string ssh, VirtualMachineSizeTypes vmSize, INetworkInterface networkInterface, IAvailabilitySet availabilitySet = null, int i = 0)
        {
            Console.WriteLine($"Create Vm Teamlate: {vmNameBase + Convert.ToString(i)}");
            var option = _azure.VirtualMachines.Define(vmNameBase + Convert.ToString(i))
                         .WithRegion(location)
                         .WithExistingResourceGroup(groupName)
                         .WithExistingPrimaryNetworkInterface(networkInterface)
                         //.WithPopularLinuxImage(KnownLinuxVirtualMachineImage.UbuntuServer16_04_Lts)
                         .WithLinuxCustomImage(imageId)
                         .WithRootUsername(user)
                         .WithRootPassword(password)
                         .WithSsh(ssh)
                         .WithComputerName(vmNameBase + Convert.ToString(i));

            IWithCreate creator = null;

            if (availabilitySet != null)
            {
                creator = option.WithExistingAvailabilitySet(availabilitySet);
            }
            else
            {
                creator = option;
            }
            var vm = creator.WithSize(vmSize);

            return(Task.FromResult(vm));
        }
Esempio n. 2
0
        protected override Task ExecuteCreateAsync()
        {
            INewAppServicePlanWithGroup definition = Azure
                                                     .WithSubscription(Options.SubscriptionId)
                                                     .AppServices.FunctionApps
                                                     .Define(AppName)
                                                     .WithRegion(Options.Region);

            IWithCreate create = Options.UseExistingResourceGroup
                ? definition.WithExistingResourceGroup(Options.ResourceGroupName)
                : definition.WithNewResourceGroup(Options.ResourceGroupName);

            return(create.CreateAsync());
        }
Esempio n. 3
0
        protected override Task ExecuteCreateAsync()
        {
            var definition = Azure
                             .WithSubscription(Options.SubscriptionId)
                             .StorageAccounts.Define(AccountName)
                             .WithRegion(Options.Region);

            IWithCreate create = Options.UseExistingResourceGroup
                ? definition.WithExistingResourceGroup(Options.ResourceGroupName)
                : definition.WithNewResourceGroup(Options.ResourceGroupName);

            return(create.WithBlobStorageAccountKind()
                   .CreateAsync());
        }
Esempio n. 4
0
        protected override ICreatable <IVirtualMachine> ToCreatableIntern(IAzure azure)
        {
            var withRegion  = azure.VirtualMachines.Define(DeriveName("vm"));
            var withGroup   = withRegion.WithRegion(this.Region);
            var withNetwork = SetResourceGroupAndTags(withGroup);

            IWithPrivateIP withPrivateIP;

            if (this.NewPrimaryNetwork != null)
            {
                withPrivateIP = withNetwork.WithNewPrimaryNetwork(this.NewPrimaryNetwork.GetCreatable());
            }
            else if (this.ExistingPrimaryNetwork != null)
            {
                withPrivateIP = withNetwork.WithExistingPrimaryNetwork(this.ExistingPrimaryNetwork.GetResource())
                                .WithSubnet(this.ExistingPrimaryNetwork.SubnetName);
            }
            else
            {
                withPrivateIP = withNetwork.WithNewPrimaryNetwork("10.0.0.0/28");
            }

            IWithPublicIPAddress withPublicIPAddress;

            if (this.PrimaryStaticPrivateIPAddress != null)
            {
                withPublicIPAddress = withPrivateIP.WithPrimaryPrivateIPAddressStatic(this.PrimaryStaticPrivateIPAddress);
            }
            else
            {
                withPublicIPAddress = withPrivateIP.WithPrimaryPrivateIPAddressDynamic();
            }

            IWithOS withOS;

            if (this.NewPrimaryPublicIPAddress != null)
            {
                withOS = withPublicIPAddress.WithNewPrimaryPublicIPAddress(this.NewPrimaryPublicIPAddress.GetCreatable());
            }
            else if (this.ExistingPrimaryPublicIPAddress != null)
            {
                withOS = withPublicIPAddress.WithExistingPrimaryPublicIPAddress(this.ExistingPrimaryPublicIPAddress.GetResource());
            }
            else
            {
                withOS = withPublicIPAddress.WithoutPrimaryPublicIPAddress();
            }

            IWithCreate withCreate = null;

            if (this.Linux != null)
            {
                var image = this.Linux.VirtualMachineImage();
                if (image.CustomImageId != null)
                {
                    var withLinuxRootUserNameManaged = withOS.WithLinuxCustomImage(image.CustomImageId);
                    withCreate = withLinuxRootUserNameManaged
                                 .WithRootUsername(this.Linux.Credentials.UserName)
                                 .WithRootPassword(this.Linux.Credentials.Password);
                }
                else
                {
                    var withLinuxRootUserNameManagedOrUnManaged = withOS.WithSpecificLinuxImageVersion(image.ImageReference);
                    withCreate = withLinuxRootUserNameManagedOrUnManaged
                                 .WithRootUsername(this.Linux.Credentials.UserName)
                                 .WithRootPassword(this.Linux.Credentials.Password);
                }
            }
            else if (this.Windows != null)
            {
                var image = this.Windows.VirtualMachineImage();
                if (image.CustomImageId != null)
                {
                    var withWindowsAdminUserNameManaged = withOS.WithWindowsCustomImage(image.CustomImageId);
                    withCreate = withWindowsAdminUserNameManaged
                                 .WithAdminUsername(this.Windows.Credentials.UserName)
                                 .WithAdminPassword(this.Windows.Credentials.Password);
                }
                else
                {
                    var withWindowsAdminUserNameManagedOrUnManaged = withOS.WithSpecificWindowsImageVersion(image.ImageReference);
                    withCreate = withWindowsAdminUserNameManagedOrUnManaged
                                 .WithAdminUsername(this.Windows.Credentials.UserName)
                                 .WithAdminPassword(this.Windows.Credentials.Password);
                }
            }
            if (this.BootDiagnostics != null)
            {
                if (this.BootDiagnostics.Enabled.Value)
                {
                    if (this.BootDiagnostics.NewStorageAccount != null)
                    {
                        withCreate.WithBootDiagnostics(this.BootDiagnostics.NewStorageAccount.GetCreatable());
                    }
                    else if (this.BootDiagnostics.ExistingStorageAccount != null)
                    {
                        withCreate.WithBootDiagnostics(this.BootDiagnostics.ExistingStorageAccount.GetResource());
                    }
                    else
                    {
                        withCreate.WithBootDiagnostics();
                    }
                }
            }

            if (withCreate == null)
            {
                throw new NullReferenceException("DevError: VirtualMachine::withCreate");
            }
            return(withCreate);
        }