Example #1
0
        public override void Execute()
        {
            var createVm = new CreateSingleVmExample(Context);

            createVm.Execute();

            var rmClient      = new ResourcesManagementClient(Context.SubscriptionId, Context.Credential);
            var computeClient = new ComputeManagementClient(Context.SubscriptionId, Context.Credential);
            var rg            = rmClient.ResourceGroups.Get(Context.RgName).Value;

            foreach (var entity in rmClient.Resources.ListByResourceGroup(rg.Name, filter: "resourceType eq 'Microsoft.Compute/virtualMachines'"))
            {
                Console.WriteLine($"{entity.Name}");
                var vmUpdate = new VirtualMachineUpdate();
                foreach (var pair in entity?.Tags)
                {
                    vmUpdate.Tags.Add(pair.Key, pair.Value);
                }

                vmUpdate.Tags.Add("name", "value");

                // note that it is also possible to use the generic resource Update command, however,
                // this requires additional parameters that are difficult to discover, including rp-specific api-version
                computeClient.VirtualMachines.StartUpdate(rg.Name, entity.Name, vmUpdate).WaitForCompletionAsync().ConfigureAwait(false).GetAwaiter().GetResult();
            }
        }
        public override void Execute()
        {
            var createVm = new CreateSingleVmExample(Context);

            createVm.Execute();

            var rgOp = new AzureResourceManagerClient().ResourceGroup(Context.SubscriptionId, Context.RgName);

            foreach (var genericOp in rgOp.VirtualMachines().ListByName(Context.VmName))
            {
                Console.WriteLine($"Deleting {genericOp.Id}");
                genericOp.Delete();
            }

            try
            {
                var vmOp = rgOp.VirtualMachine(Context.VmName);
                Console.WriteLine($"Trying to get {vmOp.Id}");
                var response = vmOp.Get();
            }
            catch (RequestFailedException e) when(e.Status == 404)
            {
                Console.WriteLine("Got 404 returned as expected");
                return;
            }

            throw new InvalidOperationException("Failed");
        }
Example #3
0
        public override void Execute()
        {
            var createVm = new CreateSingleVmExample(Context);

            createVm.Execute();

            ExecuteAsync().ConfigureAwait(false).GetAwaiter().GetResult();
        }
Example #4
0
        public override void Execute()
        {
            var createVm = new CreateSingleVmExample(Context);

            createVm.Execute();

            var rgOp = new AzureResourceManagerClient().GetResourceGroupOperations(Context.SubscriptionId, Context.RgName);

            foreach (var entity in rgOp.GetVirtualMachineContainer().List())
            {
                Console.WriteLine($"{entity.Id.Name}");
                entity.StartAddTag("name", "Value");
            }
        }
Example #5
0
        public override void Execute()
        {
            var createVm = new CreateSingleVmExample(Context);

            createVm.Execute();

            var rgOp = new AzureResourceManagerClient().ResourceGroup(Context.SubscriptionId, Context.RgName);
            var vmOp = rgOp.VirtualMachine(Context.VmName);

            var vm = vmOp.Get().Value;

            Console.WriteLine($"Adding tags to {vm.Data.Name}");
            vm.StartAddTag("tagkey", "tagvalue");
        }
Example #6
0
        public override void Execute()
        {
            var createVm = new CreateSingleVmExample(Context);

            createVm.Execute();

            var client        = new AzureResourceManagerClient();
            var subscription  = client.GetSubscriptionOperations(Context.SubscriptionId);
            var resourceGroup = subscription.GetResourceGroupOperations(Context.RgName);
            var vm            = resourceGroup.GetVirtualMachineOperations(Context.VmName);

            Console.WriteLine($"Found VM {Context.VmName}");
            Console.WriteLine("--------Stopping VM--------");
            vm.PowerOff();
            Console.WriteLine("--------Starting VM--------");
            vm.PowerOn();
        }
Example #7
0
        public override void Execute()
        {
            var createVm = new CreateSingleVmExample(Context);

            createVm.Execute();
            var client = new AzureResourceManagerClient();

            //retrieve from lowest level, doesn't give ability to walk up and down the container structure
            var vmOp = client.GetResourceOperations <VirtualMachineOperations>(Context.SubscriptionId, Context.RgName, Context.VmName);
            var vm   = vmOp.Get().Value.Data;

            Console.WriteLine($"Found VM {vm.Id}");

            //retrieve from lowest level inside management package gives ability to walk up and down
            var rg  = client.GetResourceGroupOperations(Context.SubscriptionId, Context.RgName);
            var vm2 = rg.GetVirtualMachineOperations(Context.VmName).Get().Value.Data;

            Console.WriteLine($"Found VM {vm2.Id}");
        }
        public override void Execute()
        {
            var createVm = new CreateSingleVmExample(Context);

            createVm.Execute();

            var client       = new AzureResourceManagerClient();
            var subscription = client.GetSubscriptionOperations(Context.SubscriptionId);

            var resourceGroup = subscription.GetResourceGroupOperations(Context.RgName).Get().Value;

            _ = resourceGroup.GetAvailabilitySetOperations(Context.VmName + "_aSet").Get().Value;
            var vnet = resourceGroup.GetVirtualNetworkOperations(Context.VmName + "_vnet").Get().Value;

            _ = vnet.GetSubnetOperations(Context.SubnetName).Get().Value;
            _ = resourceGroup.GetNetworkSecurityGroupOperations(Context.NsgName).Get().Value;
            _ = resourceGroup.GetPublicIpAddressOperations($"{Context.VmName}_ip").Get().Value;
            _ = resourceGroup.GetNetworkInterfaceOperations($"{Context.VmName}_nic").Get().Value;
            _ = resourceGroup.GetVirtualMachineOperations(Context.VmName).Get().Value;
        }
        public override void Execute()
        {
            var createVm = new CreateSingleVmExample(Context);

            createVm.Execute();

            var client        = new AzureResourceManagerClient();
            var subscription  = client.GetSubscriptionOperations(Context.SubscriptionId);
            var resourceGroup = subscription.GetResourceGroupOperations(Context.RgName);
            var vmId          = resourceGroup.GetVirtualMachineOperations(Context.VmName).Id;
            var vnId          = resourceGroup.GetVirtualNetworkOperations(Context.VmName + "_vnet").Id;
            var subnetId      = resourceGroup.GetVirtualNetworkOperations(Context.VmName + "_vnet").GetSubnetOperations(Context.SubnetName).Id;
            var asId          = resourceGroup.GetAvailabilitySetOperations(Context.VmName + "_aSet").Id;
            var nsgId         = resourceGroup.GetNetworkSecurityGroupOperations(Context.NsgName).Id;
            var niId          = resourceGroup.GetNetworkInterfaceOperations(Context.VmName + "_nic").Id;

            var vmOps = client.GetVirtualMachineOperations(vmId);

            Console.WriteLine("\nclient.GetVirtualMachineOperations(vmResourceId)");
            vmOps.PowerOff();
            Console.WriteLine("Option 1 vm is " + vmOps.Get().Value.Data.InstanceView.Statuses.Last().Code);
            vmOps.PowerOn();
            Console.WriteLine("Option 1 vm is " + vmOps.Get().Value.Data.InstanceView.Statuses.Last().Code);

            var subnetOps = client.GetSubnetOperations(subnetId);

            Console.WriteLine("Option 1 subnet is " + subnetOps.Id);

            var vnOps  = client.GetVirtualNetworkOperations(vnId);
            var nsgOps = client.GetNetworkSecurityGroupOperations(nsgId);
            var niOps  = client.GetNetworkInterfaceOperations(niId);
            var asOps  = client.GetAvailabilitySetOperations(asId);

            Console.WriteLine(vnOps.Id);
            Console.WriteLine(nsgOps.Id);
            Console.WriteLine(niOps.Id);
            Console.WriteLine(asOps.Id);

            Console.WriteLine("Demo complete");
        }
Example #10
0
        public override void Execute()
        {
            var createVm = new CreateSingleVmExample(Context);

            createVm.Execute();

            var rgOp = new AzureResourceManagerClient().GetResourceGroupOperations(Context.SubscriptionId, Context.RgName);

            foreach (var genericOp in rgOp.GetVirtualMachineContainer().ListByName(Context.VmName))
            {
                Console.WriteLine($"Adding tag to {genericOp.Id}");
                genericOp.StartAddTag("tagKey", "tagVaue");
            }

            var vmOp = rgOp.GetVirtualMachineOperations(Context.VmName);

            Console.WriteLine($"Getting {vmOp.Id}");
            var vm = vmOp.Get().Value;

            if (!vm.Data.Tags.ContainsKey("tagKey"))
            {
                throw new InvalidOperationException("Failed");
            }
        }