예제 #1
0
파일: FIVM.cs 프로젝트: albertwo1978/grover
        protected override bool turnOff(Microsoft.Azure.Management.ResourceManager.Fluent.Core.IResource curResource)
        {
            Microsoft.Azure.Management.Compute.Fluent.IVirtualMachine curVM = (Microsoft.Azure.Management.Compute.Fluent.IVirtualMachine)curResource;

            try
            {
                curVM.PowerOff();
                return(true);
            }
            catch (Exception err)
            {
                log.LogError($"Error turning on VM {curSubName} -> {curRGName} -> {curVM.Name}: {err}");
                return(false);
            }
        }
예제 #2
0
        // Remove the IMSI from the VM and the KeyVault Access policy
        private async Task RemoveAccess(Microsoft.Azure.Management.Compute.Fluent.IVirtualMachine vm, Microsoft.Azure.Management.KeyVault.Fluent.IVault vault, ILogger log)
        {
            try
            {
                TimeSpan timeSpan = new TimeSpan(0, 4, 0);
                await Task.Delay(timeSpan);

                log.LogInformation("[EnableVmMSIFunction] Cleanup Delay finished:" + DateTime.Now.ToString());
                // Remove Access policy
                await vault.Update()
                .WithoutAccessPolicy(vm.SystemAssignedManagedServiceIdentityPrincipalId).ApplyAsync();

                await vault.RefreshAsync();

                // Remove VM identity
                await vm.Update().WithoutSystemAssignedManagedServiceIdentity().ApplyAsync();
            }
            catch (Exception e)
            {
                log.LogInformation("[EnableVmMSIFunction] Cleanup Error:" + e.Message);
            }
        }