Beispiel #1
0
        public AssignedVmModel GenerateVm(string serviceBaseName, VMConfigModel vmConfig, VMUserModel user)
        {
            //TODO: refactor GenerateVMsForUsers to be used instead of this one

            if (serviceBaseName.Length > 10) throw new ArgumentOutOfRangeException("serviceBaseName can't have more than 10 characters.");

            //find a name that is available
            Random r = new Random();
            string serviceName = null;
            HostedServiceCheckNameAvailabilityResponse availableResponse;

            do
            {
                int randomValue = r.Next(99999);
                serviceName = serviceBaseName + randomValue;

                availableResponse = _compute.HostedServices.CheckNameAvailability(serviceName);

            } while (!availableResponse.IsAvailable);

            var createCloudService = _compute.HostedServices.Create(
                new HostedServiceCreateParameters
                {
                    ServiceName = serviceName,
                    Location = vmConfig.Region
                });

            string virtualMachineName = serviceName;

            //TODO: need a status check
            GenerateVM(serviceName, vmConfig, virtualMachineName, RdpPortBase, user,
                firstVMInDeployment: true);
            AssignedVmModel assignedVm = new AssignedVmModel
            {
                UserId = user.IdentityId,
                UserName = user.Username,
                VmName = virtualMachineName,
                VmRdpPort = RdpPortBase,
                Password = user.Password
            };

            return assignedVm;
        }
Beispiel #2
0
        private void GenerateVM(string serviceName, VMConfigModel vmConfig, string virtualMachineName, 
			int rdpPort, VMUserModel user, bool firstVMInDeployment)
        {
            var windowsConfigurationSet = new ConfigurationSet
            {
                //TODO: depends on the OS type??
                ConfigurationSetType = ConfigurationSetTypes.WindowsProvisioningConfiguration,
                AdminPassword = user.Password,
                AdminUserName = user.Username,
                ComputerName = virtualMachineName,
                HostName = string.Format("{0}.cloudapp.net", serviceName),

            };

            var endpoints = new ConfigurationSet
            {
                ConfigurationSetType = "NetworkConfiguration",
                InputEndpoints = new List<InputEndpoint>
                {
                    new InputEndpoint
                    {
                        Name = "RDP",
                        Port = rdpPort,
                        Protocol = "TCP",
                        LocalPort = InternalRdpPort
                    }
                }
            };

            string newVhdName = string.Format("{0}.vhd", virtualMachineName);

            Uri mediaUri = new Uri(GetVHDStorageUrl(vmConfig.Region) + newVhdName);

            var vhd = new OSVirtualHardDisk
            {
                SourceImageName = vmConfig.ImageName,
                HostCaching = VirtualHardDiskHostCaching.ReadWrite,
                MediaLink = mediaUri,

            };

            OperationStatusResponse deploymentResult;

            if (firstVMInDeployment)
            {
                deploymentResult = CreateDeployment(serviceName, virtualMachineName, windowsConfigurationSet, endpoints, vhd, vmConfig);

            }
            else
            {
                deploymentResult = AddVm(serviceName, virtualMachineName, windowsConfigurationSet, endpoints, vhd, vmConfig);
            }
            //TODO: handle the deploymentResult
        }
Beispiel #3
0
 //TODO: stub
 public AssignedVmModel GenerateVm(string serviceBaseName, VMConfigModel vmConfig, VMUserModel user)
 {
     throw new NotImplementedException();
 }