コード例 #1
0
        //*********************************************************************
        ///
        // PUT odata/VmDeployments(5)
        /// <summary>
        ///
        /// </summary>
        /// <param name="key"></param>
        /// <param name="vmdeploymentrequest"></param>
        /// <returns></returns>
        ///
        //*********************************************************************

        //[Authorize]
        public async Task <IHttpActionResult> Put([FromODataUri] int key,
                                                  CmpInterfaceModel.Models.VmDeploymentRequest vmdeploymentrequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (key != vmdeploymentrequest.ID)
            {
                return(BadRequest());
            }

            /*db.Entry(vmdeploymentrequest).State = EntityState.Modified;
             *
             * try
             * {
             *  await db.SaveChangesAsync();
             * }
             * catch (DbUpdateConcurrencyException)
             * {
             *  if (!VmDeploymentRequestExists(key))
             *  {
             *      return NotFound();
             *  }
             *  else
             *  {
             *      throw;
             *  }
             * }*/

            return(Updated(vmdeploymentrequest));
        }
コード例 #2
0
        public void BuildVerificationTest_01()
        {
            //Initialize values
            var vmList = VmDeploymentSetup();
            // starting CMP service
            var cmpService = StartCmpServiceTest();

            // Create VM as Async Tasks
            Task[] taskArray = new Task[vmList.Count];
            for (int i = 0; i < vmList.Count; i++)
            {
                // Start VM Provisioning
                int depId = CreateVmTest(_eventLog, vmList[i]);

                taskArray[i] = Task.Factory.StartNew((Object obj) =>
                {
                    VmDeploymentRequest vmd = obj as VmDeploymentRequest;
                    // Check VM Provisioning Status
                    var cmpi     = new VMServiceRepository(_eventLog);
                    var vmDepReq = cmpi.FetchCmpRequest(depId);

                    string statusCode = null;
                    while (!vmDepReq.Status.Equals("Complete") && !vmDepReq.Status.Equals("Exception"))
                    {
                        vmDepReq   = cmpi.FetchCmpRequest(depId);
                        statusCode = vmDepReq.Status;
                    }
                    if (vmd != null)
                    {
                        vmd.Status        = statusCode;
                        vmd.StatusMessage = vmDepReq.StatusMessage;
                    }
                }, new VmDeploymentRequest()
                {
                });
            }
            Task.WaitAll(taskArray);

            //Assert

            foreach (var task in taskArray)
            {
                var data = task.AsyncState as VmDeploymentRequest;
                Assert.AreNotEqual(data.Status, null);
                Assert.AreNotEqual(data.Status, "Exception", data.StatusMessage);
                Assert.AreEqual(data.Status, "Complete", data.StatusMessage);
            }


            DeleteVmTest(_eventLog, vmList);

            // Stop CMP Service
            StopCmpServiceTest(cmpService);
        }
コード例 #3
0
        //*********************************************************************
        ///
        /// <summary>
        ///
        /// </summary>
        /// <param name="vmdeploymentrequest"></param>
        /// <returns></returns>
        ///
        //*********************************************************************

        CmpInterfaceModel.Models.VmDeploymentRequest ServToInt(
            CmpServiceLib.Models.VmDeploymentRequest vmdeploymentrequest)
        {
            if (null == vmdeploymentrequest)
            {
                return(null);
            }

            var ret = new CmpInterfaceModel.Models.VmDeploymentRequest
            {
                ID = vmdeploymentrequest.ID,
                ExceptionMessage          = vmdeploymentrequest.ExceptionMessage,
                LastStatusUpdate          = CmpServiceLib.Utilities.GetDbDateTime(vmdeploymentrequest.LastStatusUpdate),
                ParentAppName             = vmdeploymentrequest.ParentAppName,
                RequestDescription        = vmdeploymentrequest.RequestDescription,
                RequestName               = vmdeploymentrequest.RequestName,
                SourceServerName          = vmdeploymentrequest.SourceServerName,
                SourceVhdFilesCSV         = vmdeploymentrequest.SourceVhdFilesCSV,
                Status                    = vmdeploymentrequest.StatusCode,
                TagData                   = vmdeploymentrequest.TagData,
                TargetLocation            = vmdeploymentrequest.TargetLocation,
                TargetLocationType        = vmdeploymentrequest.TargetLocationType,
                TargetVmName              = vmdeploymentrequest.TargetVmName,
                TargetServiceName         = vmdeploymentrequest.TargetServicename,
                VmSize                    = vmdeploymentrequest.VmSize,
                WhenRequested             = CmpServiceLib.Utilities.GetDbDateTime(vmdeploymentrequest.WhenRequested),
                WhoRequested              = vmdeploymentrequest.WhoRequested,
                Active                    = CmpServiceLib.Utilities.GetDbBool(vmdeploymentrequest.Active),
                AftsID                    = CmpServiceLib.Utilities.GetDbInt(vmdeploymentrequest.AftsID),
                Config                    = vmdeploymentrequest.Config,
                ParentAppID               = vmdeploymentrequest.ParentAppID,
                RequestType               = vmdeploymentrequest.RequestType,
                StatusMessage             = vmdeploymentrequest.StatusMessage,
                TargetAccount             = vmdeploymentrequest.TargetAccount,
                TargetAccountCreds        = vmdeploymentrequest.TargetAccountCreds,
                TargetAccountType         = vmdeploymentrequest.TargetAccountType,
                TargetServiceProviderType = vmdeploymentrequest.TargetServiceProviderType,
                TagID                          = CmpServiceLib.Utilities.GetDbInt(vmdeploymentrequest.TagID),
                ExceptionTypeCode              = vmdeploymentrequest.ExceptionTypeCode,
                SourceServerRegion             = vmdeploymentrequest.SourceServerRegion,
                ValidationResults              = vmdeploymentrequest.ValidationResults,
                TargetServiceProviderAccountID = NonNull(vmdeploymentrequest.ServiceProviderAccountID)
            };

            return(ret);
        }
コード例 #4
0
ファイル: VmDeployment.cs プロジェクト: vrosnet/Phoenix
        //*************************************************************************
        ///
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        ///
        //*************************************************************************

        public static VmConfig CreateSampleRdfe()
        {
            var vmDepReqList = new List <VmDeploymentRequest>();
            var vmDepReq     = new VmDeploymentRequest {
                ID = 1
            };

            var vmDep = new AzureVmDeployment {
                Name  = "TheName",
                Label = "TheLabel", DeploymentSlot = "Production", VirtualNetworkName = "TheVM"
            };

            //***

            var dvd = new DataVirtualHardDisk {
                DiskLabel           = "DL",
                DiskName            = "DN",
                HostCaching         = "HostCaching",
                LogicalDiskSizeInGB = "100",
                Lun       = "1",
                MediaLink = "ML"
            };
            var dvdList = new List <DataVirtualHardDisk>();

            dvdList.Add(dvd);

            var ovd = new OsVirtualHardDisk {
                DiskLabel       = "DL",
                DiskName        = "DN",
                HostCaching     = "HostCaching",
                MediaLink       = "ML",
                SourceImageName = "SIN"
            };

            //***

            var dns = new DnsServer {
                Name = "DnsName", Address = "DnsAddress"
            };

            vmDep.Dns            = new DnsServerList();
            vmDep.Dns.DnsServers = new List <DnsServer>();
            vmDep.Dns.DnsServers.Add(dns);

            //***

            var creds = new Credentials {
                Domain   = "CredDomain",
                Username = "******", Password = "******"
            };
            var DJ = new DomainJoin {
                JoinDomain      = "TheDomain",
                MachineObjectOU = "MOU", Credentials = creds
            };

            var CertSet = new CertificateSetting {
                StoreLocation = "StoreLoc",
                StoreName     = "StoreName", Thumbprint = "TP"
            };
            var CertSetList = new List <CertificateSetting>();

            CertSetList.Add(CertSet);

            //Listener List = new Listener { CertificateThumbprint = "CertThumb", Type = "T" };
            var List = new Listener {
                CertificateThumbprint = "CertThumb", Protocol = "Https"
            };
            var ListList = new List <Listener>();

            ListList.Add(List);
            var WRM = new WinRM {
                Listeners = ListList
            };

            ConfigurationSet CS = new WindowsProvisioningConfigurationSet {
                AdminPassword             = "******",
                AdminUsername             = "******", ComputerName = "CN",
                ConfigurationSetType      = "WindowsProvisioningConfiguration",
                DomainJoin                = DJ, EnableAutomaticUpdates = "True",
                StoredCertificateSettings = CertSetList,
                TimeZone = "TZ",
                WinRM    = WRM
            };
            var CsList = new List <ConfigurationSet>();

            CsList.Add(CS);

            //***

            var LBP = new LoadBalancerProbe {
                IntervalInSeconds = "100",
                Path = "ThePath", Port = "4321", Protocol = "Prot", TimeoutInSeconds = "200"
            };
            var IE = new InputEndpoint {
                LoadBalancedEndpointSetName = "LBESN",
                LoadBalancerProbe           = LBP, LocalPort = "LP", Name = "N", Port = "1234", Protocol = "Prot"
            };
            var IeList = new List <InputEndpoint>();

            IeList.Add(IE);

            var SN = new SubnetNames {
                SubnetName = "XX"
            };
            var SubNameList = new List <SubnetNames>();

            SubNameList.Add(SN);

            /*ConfigurationSet CS2 = new NetworkConfigurationSet { ConfigurationSetType = "NetworkConfiguration",
             *  SubnetNames = SubNameList, InputEndpoints = IeList };
             * CsList.Add(CS2);*/

            //***

            Role R = new PersistentVMRole
            {
                AvailabilitySetName  = "AsName",
                ConfigurationSets    = CsList,
                DataVirtualHardDisks = dvdList,
                OSVirtualHardDisk    = ovd,
                RoleName             = "RN",
                RoleSize             = "RS",
                RoleType             = "RT"
            }
            ;

            vmDep.RoleList = new List <Role>();
            vmDep.RoleList.Add(R);

            var VMC = new VmConfig {
                AzureVmConfig = vmDep
            };

            return(VMC);
        }
コード例 #5
0
ファイル: VmDeployment.cs プロジェクト: vrosnet/Phoenix
        //*********************************************************************
        ///
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        ///
        //*********************************************************************

        public static VmConfig CreateSampleArm()
        {
            var vmDepReqList = new List <VmDeploymentRequest>();
            var vmDepReq     = new VmDeploymentRequest {
                ID = 1
            };

            /*var armParams = new ArmParameters()
             * {
             *  adminPassword = new ArmAdminpassword(){value = "123abc!"},
             *  adminUsername = new ArmAdminusername(){value = "markw"},
             *  dnsNameForPublicIP = new ArmDnsnameforpublicip() { value = "armTestN27" },
             *  newStorageAccountName = new ArmNewstorageaccountname(){value = "armTestN27"},
             *  windowsOSVersion = new ArmWindowsosversion() { value = "2012-R2-Datacenter" }
             * };*/

            var armVars = new ArmVariables()
            {
                location                      = "West US",
                imagePublisher                = "MicrosoftWindowsServer",
                imageOffer                    = "WindowsServer",
                OSDiskName                    = "osdiskforwindowssimple",
                nicName                       = "myvmnic",
                addressPrefix                 = "10.0.0.0/16",
                subnetName                    = "Subnet",
                subnetPrefix                  = "10.0.0.0/24",
                storageAccountType            = "Standard_LRS",
                publicIPAddressName           = "mypublicip",
                publicIPAddressType           = "Dynamic",
                vmStorageAccountContainerName = "vhds",
                vmName             = "mywindowsvm",
                vmSize             = "Standard_D1",
                virtualNetworkName = "myvnet",
                vnetID             = "[resourceId('Microsoft.Network/virtualNetworks',variables('virtualNetworkName'))]",
                subnetRef          = "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]",
                //*** ***
                adminPassword         = "******",
                adminUsername         = "******",
                dnsNameForPublicIP    = "armtestn27",
                newStorageAccountName = "armtestn27",
                windowsOSVersion      = "2012-R2-Datacenter"
            };

            var armResources = new ArmResource[5];
            int index        = 0;

            //*** Storage account ***

            armResources[index++] = new ArmResource()
            {
                apiVersion = "2015-05-01-preview",
                type       = "Microsoft.Storage/storageAccounts",
                name       = "[variables('newStorageAccountName')]",
                location   = "[variables('location')]",
                tags       = new ArmTags()
                {
                    displayName = "StorageAccount"
                },
                properties = new ArmResourceProperties()
                {
                    accountType = "[variables('storageAccountType')]"
                }
            };

            //*** Public IP Address ***

            armResources[index++] = new ArmResource()
            {
                apiVersion = "2015-05-01-preview",
                type       = "Microsoft.Network/publicIPAddresses",
                name       = "[variables('publicIPAddressName')]",
                location   = "[variables('location')]",
                tags       = new ArmTags()
                {
                    displayName = "PublicIPAddress"
                },
                properties = new ArmResourceProperties()
                {
                    publicIPAllocationMethod = "[variables('publicIPAddressType')]",
                    dnsSettings = new ArmDnssettings()
                    {
                        domainNameLabel = "[variables('dnsNameForPublicIP')]"
                    }
                }
            };

            //*** Virtual Network ***

            armResources[index++] = new ArmResource()
            {
                apiVersion = "2015-05-01-preview",
                type       = "Microsoft.Network/virtualNetworks",
                name       = "[variables('virtualNetworkName')]",
                location   = "[variables('location')]",
                tags       = new ArmTags()
                {
                    displayName = "VirtualNetwork"
                },
                properties = new ArmResourceProperties()
                {
                    addressSpace = new ArmAddressspace()
                    {
                        addressPrefixes = new string[] { "[variables('addressPrefix')]" }
                    },
                    subnets = new ArmSubnet[]
                    {
                        new ArmSubnet()
                        {
                            name       = "[variables('subnetName')]",
                            properties = new ArmSubnetProperties()
                            {
                                addressPrefix = "[variables('subnetPrefix')]"
                            }
                        }
                    }
                }
            };

            //*** Network Interface ***

            armResources[index++] = new ArmResource()
            {
                apiVersion = "2015-05-01-preview",
                type       = "Microsoft.Network/networkInterfaces",
                name       = "[variables('nicName')]",
                location   = "[variables('location')]",
                tags       = new ArmTags()
                {
                    displayName = "NetworkInterface"
                },
                dependsOn = new string[]
                {
                    "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]",
                    "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
                },
                properties = new ArmResourceProperties()
                {
                    ipConfigurations = new ArmIpconfiguration[]
                    {
                        new ArmIpconfiguration()
                        {
                            name       = "ipconfig",
                            properties = new ArmIpconfigurationProperties()
                            {
                                privateIPAllocationMethod = "Dynamic",
                                publicIPAddress           = new ArmIpconfigurationPropertiesPublicipaddress()
                                {
                                    id = "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"
                                },
                                subnet = new ArmIpconfigurationPropertiesSubnet()
                                {
                                    id = "[variables('subnetRef')]"
                                }
                            }
                        }
                    }
                }
            };

            //*** Virtual Machine ***

            armResources[index++] = new ArmResource()
            {
                apiVersion = "2015-05-01-preview",
                type       = "Microsoft.Compute/virtualMachines",
                name       = "[variables('vmName')]",
                location   = "[variables('location')]",
                tags       = new ArmTags()
                {
                    displayName = "VirtualMachine"
                },
                dependsOn = new string[]
                {
                    "[concat('Microsoft.Storage/storageAccounts/', variables('newStorageAccountName'))]",
                    "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
                },
                properties = new ArmResourceProperties()
                {
                    hardwareProfile = new ArmHardwareprofile()
                    {
                        vmSize = "[variables('vmSize')]"
                    },
                    osProfile = new ArmOsprofile()
                    {
                        computername         = "[variables('vmName')]",
                        adminUsername        = "******",
                        adminPassword        = "******",
                        windowsConfiguration = new Windowsconfiguration()
                        {
                            provisionVMAgent       = true,
                            enableAutomaticUpdates = false/*,
                                                           * winRM = new Winrm()
                                                           * {
                                                           * listeners = new Listener[1]
                                                           * {
                                                           * new Listener() { Protocol = "http" }
                                                           * }
                                                           * }*/
                        }
                    },
                    storageProfile = new ArmStorageprofile()
                    {
                        imageReference = new ArmStorageprofileImagereference()
                        {
                            publisher = "[variables('imagePublisher')]",
                            offer     = "[variables('imageOffer')]",
                            sku       = "[variables('windowsOSVersion')]",
                            version   = "latest"
                        },
                        osDisk = new ArmStorageprofileOsdisk()
                        {
                            name         = "osdisk",
                            caching      = "ReadWrite",
                            createOption = "FromImage",
                            vhd          = new ArmStorageprofileOsdiskVhd()
                            {
                                uri = "[concat('http://',variables('newStorageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/',variables('OSDiskName'),'.vhd')]"
                            }
                        }
                    },
                    networkProfile = new ArmNetworkprofile()
                    {
                        networkInterfaces = new ArmNetworkprofileNetworkinterface[]
                        {
                            new ArmNetworkprofileNetworkinterface()
                            {
                                id = "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]"
                            }
                        }
                    }
                }
            };

            //*** ***

            var vmDepArm = new AzureVmDeploymentArm
            {
                properties = new ArmRootProperties()
                {
                    mode     = "Incremental",
                    template = new ArmTemplate()
                    {
                        contentVersion = "1.0.0.0",
                        schema         = "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                        //parameters = armParams,
                        resources = armResources,
                        variables = armVars
                                    //mode = "Incremental"
                    }
                }
            };

            //var serialized = vmDepArm.SerializeJson();

            return(new VmConfig {
                AzureArmConfig = vmDepArm
            });
        }
コード例 #6
0
        //*********************************************************************
        ///
        // POST odata/VmDeployments
        /// <summary>
        ///
        /// </summary>
        /// <param name="vmdeploymentrequest"></param>
        /// <returns></returns>
        ///
        //*********************************************************************

        //[Authorize]
        public async Task <IHttpActionResult> Post(
            CmpInterfaceModel.Models.VmDeploymentRequest vmdeploymentrequest)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var checkForExistingVm = true;
                var newRequest         = true;
                CmpServiceLib.Models.VmDeploymentRequest response = null;

                var cmp = new CmpServiceLib.CmpService(_EventLog,
                                                       _CmpDbConnectionString, _AftsDbConnectionString);


                vmdeploymentrequest.LastStatusUpdate = DateTime.Now;

                if (0 == vmdeploymentrequest.ID)
                {
                    if (cmp.IsVmDepRequestInProcess(vmdeploymentrequest.TargetVmName))
                    {
                        throw new Exception(string.Format(
                                                "A request for deployment for a server with name '{0}' is currently in process. Duplicates not allowed.",
                                                vmdeploymentrequest.TargetVmName));
                    }

                    var vmCfg = CmpInterfaceModel.Models.VmConfig.Deserialize(vmdeploymentrequest.Config);

                    if (null != vmCfg)
                    {
                        if (null != vmCfg.Placement)
                        {
                            if (vmCfg.Placement.RebuildRequest)
                            {
                                checkForExistingVm = false;
                            }
                        }
                    }

                    if (checkForExistingVm)
                    {
                        if (DoesNameResolve(vmdeploymentrequest.TargetVmName))
                        {
                            throw new Exception(string.Format(
                                                    "A DNS record for a server with name '{0}' already exists. Duplicates not allowed.",
                                                    vmdeploymentrequest.TargetVmName));
                        }
                    }

                    if (vmdeploymentrequest.WhenRequested.Year < 2013)
                    {
                        vmdeploymentrequest.WhenRequested = DateTime.Now;
                    }

                    vmdeploymentrequest.Status =
                        CmpInterfaceModel.Constants.StatusEnum.Submitted.ToString();
                }
                else
                {
                    newRequest = false;
                }

                var vmDepReq = new CmpServiceLib.Models.VmDeploymentRequest
                {
                    ID = vmdeploymentrequest.ID,
                    ExceptionMessage              = vmdeploymentrequest.ExceptionMessage,
                    LastStatusUpdate              = vmdeploymentrequest.LastStatusUpdate,
                    ParentAppName                 = vmdeploymentrequest.ParentAppName,
                    RequestDescription            = vmdeploymentrequest.RequestDescription,
                    RequestName                   = vmdeploymentrequest.RequestName,
                    SourceServerName              = vmdeploymentrequest.SourceServerName,
                    SourceVhdFilesCSV             = vmdeploymentrequest.SourceVhdFilesCSV,
                    SourceServerRegion            = vmdeploymentrequest.SourceServerRegion,
                    StatusCode                    = vmdeploymentrequest.Status,
                    TagData                       = vmdeploymentrequest.TagData,
                    TargetLocation                = vmdeploymentrequest.TargetLocation,
                    TargetLocationType            = vmdeploymentrequest.TargetLocationType,
                    TargetVmName                  = vmdeploymentrequest.TargetVmName,
                    TargetServicename             = vmdeploymentrequest.TargetServiceName,
                    VmSize                        = vmdeploymentrequest.VmSize,
                    WhenRequested                 = vmdeploymentrequest.WhenRequested,
                    WhoRequested                  = vmdeploymentrequest.WhoRequested,
                    Active                        = vmdeploymentrequest.Active,
                    AftsID                        = vmdeploymentrequest.AftsID,
                    Config                        = vmdeploymentrequest.Config,
                    ConfigOriginal                = vmdeploymentrequest.Config,
                    ParentAppID                   = vmdeploymentrequest.ParentAppID,
                    RequestType                   = vmdeploymentrequest.RequestType,
                    StatusMessage                 = vmdeploymentrequest.StatusMessage,
                    TargetAccount                 = vmdeploymentrequest.TargetAccount,
                    TargetAccountCreds            = vmdeploymentrequest.TargetAccountCreds,
                    TargetAccountType             = vmdeploymentrequest.TargetAccountType,
                    TargetServiceProviderType     = vmdeploymentrequest.TargetServiceProviderType,
                    ServiceProviderAccountID      = 1,
                    ServiceProviderStatusCheckTag = null,
                    TagID             = vmdeploymentrequest.TagID,
                    OverwriteExisting = false,
                    ValidationResults = vmdeploymentrequest.ValidationResults,
                    ExceptionTypeCode = vmdeploymentrequest.ExceptionTypeCode,
                    //CurrentStateStartTime  = Now,
                    //CurrentStateTryCount = 0,
                    //LastState = null,
                    //ServiceProviderResourceGroup = null,
                    //Warnings = null
                };

                if (newRequest)
                {
                    response = cmp.InsertVmDepRequest(vmDepReq);
                }
                else
                {
                    cmp.ResubmitVmDepRequest(vmDepReq);
                }

                if (response != null)
                {
                    vmdeploymentrequest.ID = response.ID;
                }

                return(Created(vmdeploymentrequest));
            }
            catch (Exception ex)
            {
                LogThis(ex, EventLogEntryType.Error, "Exception in Post()", 100, 100);
                throw;
            }
        }