コード例 #1
0
        public void CommandOperator_DefaultValues_SetsNothing()
        {
            var expected = new GetAzureVmCommand();

            Command actual = expected;

            Assert.That(actual.Parameters, Is.Empty);
        }
コード例 #2
0
        public void CommandOperator_ServiceNameIsEmpty_SetsNothing()
        {
            var expected = new GetAzureVmCommand
            {
                ServiceName = String.Empty
            };

            Command command = expected;
            var actual = command.Parameters.FirstOrDefault(x => x.Name == GetAzureVmCommand.ServiceNameParameter);

            Assert.That(actual, Is.Null);
        }
コード例 #3
0
        public void CommandOperator_ServiceNameIsSomething_SetsServiceName()
        {
            var expected = new GetAzureVmCommand
            {
                ServiceName = "SomeName"
            };

            Command command = expected;
            var actual = command.Parameters.FirstOrDefault(x => x.Name == GetAzureVmCommand.ServiceNameParameter);

            Assert.That(actual, Is.Not.Null);
            Assert.That(actual.Value, Is.EqualTo(expected.ServiceName));
        }
コード例 #4
0
        private static bool AzureVirtualMachineExists(IPowershellExecutor executor, VirtualMachine virtualMachine, string serviceName)
        {
            var getAzureVmCommand = new GetAzureVmCommand
            {
                ServiceName = serviceName,
                Name = virtualMachine.Name
            };

            var results = executor.Execute(getAzureVmCommand);

            var result = results.Any();

            return result;
        }
コード例 #5
0
        private static void AttachAzureDrive(IPowershellExecutor executor, VirtualMachine virtualMachine, string serviceName, string dataDiskName)
        {
            var getAzureVm = new GetAzureVmCommand
            {
                Name = virtualMachine.Name,
                ServiceName = serviceName
            };

            var addAzureDataDisk = new AddAzureDataDiskCommand
            {
                Import = true,
                DiskName = dataDiskName,
                LogicalUnitNumber = 0
            };

            var updateAzureVm = new UpdateAzureVmCommand();

            var result = executor.Execute(getAzureVm, addAzureDataDisk, updateAzureVm);
        }
コード例 #6
0
        private static string GetAttachedOsDisks(IPowershellExecutor executor, VirtualMachine virtualMachine, string serviceName)
        {
            var getAzureVmCommand = new GetAzureVmCommand
            {
                ServiceName = serviceName,
                Name = virtualMachine.Name
            };

            var getAzureOsDiskCommand = new GetAzureOsDiskCommand();

            var osDisk = executor.Execute(getAzureVmCommand, getAzureOsDiskCommand)
                .Select(x => x.Properties["DiskName"].Value)
                .Cast<string>()
                .FirstOrDefault();

            return osDisk;
        }
コード例 #7
0
        private static IEnumerable<KeyValuePair<string, int>> GetAttachedDataDisks(IPowershellExecutor executor, VirtualMachine virtualMachine, string serviceName)
        {
            var getAzureVmCommand = new GetAzureVmCommand
            {
                ServiceName = serviceName,
                Name = virtualMachine.Name
            };

            var getAzureDataDiskCommand = new GetAzureDataDiskCommand();

            var dataDisks = executor.Execute(getAzureVmCommand, getAzureDataDiskCommand)
                .ToDictionary(x => (string) x.Properties["DiskName"].Value, y => (int) y.Properties["LUN"].Value);
                //.Select(x => x.Properties["DiskName"].Value)
                //.Cast<string>();

            return dataDisks;
        }
コード例 #8
0
        private static void DetachDiskFromVirtualMachine(IPowershellExecutor executor, VirtualMachine virtualMachine, string serviceName, int logicalUnitNumber)
        {
            var getAzureVmCommand = new GetAzureVmCommand
            {
                ServiceName = serviceName,
                Name = virtualMachine.Name
            };

            var removeAzureDataDiskCommand = new RemoveAzureDataDiskCommand
            {
                LogicalUnitNumber = logicalUnitNumber
            };

            var updateAzureVmCommand = new UpdateAzureVmCommand();

            executor.Execute(getAzureVmCommand, removeAzureDataDiskCommand, updateAzureVmCommand);
        }