public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                if (ShouldProcess(this.Name, VerbsCommon.New))
                {
                    string resourceGroup = this.ResourceGroupName;
                    string restorePointCollectionName = this.Name;
                    string vmId     = this.VmId;
                    string location = this.Location;

                    RestorePointCollection restorePointCollection = new RestorePointCollection(location);
                    restorePointCollection.Source = new RestorePointCollectionSourceProperties()
                    {
                        Id = vmId
                    };

                    var result   = RestorePointCollectionsClient.CreateOrUpdate(resourceGroup, restorePointCollectionName, restorePointCollection);
                    var psObject = new PSRestorePointCollection();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <RestorePointCollection, PSRestorePointCollection>(result, psObject);
                    WriteObject(psObject);
                }
            });
        }
        // for update of RPC, only update of tags is permitted
        private void UpdateRpc(string rgName, string rpcName, RestorePointCollection rpc,
                               Dictionary <string, string> tags)
        {
            rpc.Tags = tags;
            RestorePointCollectionUpdate updateRpc = new RestorePointCollectionUpdate(
                tags, rpc.Source);

            m_CrpClient.RestorePointCollections.Update(rgName, rpcName, updateRpc);
        }
        // Verify that the two rpcs created by this test are in the GET restorePointCollections response.
        private void VerifyReturnedRpcs(IEnumerable <RestorePointCollection> rpcs, string rpcName1, string rpcName2, string location, string vmId)
        {
            // two rpcs are returned because the RG has two rpcs
            RestorePointCollection rpc1 = rpcs.Where(rpc => rpc.Name == rpcName1).First();

            VerifyRpc(rpc1, rpcName1, location, vmId);
            RestorePointCollection rpc2 = rpcs.Where(rpc => rpc.Name == rpcName2).First();

            VerifyRpc(rpc2, rpcName2, location, vmId);
        }
        private RestorePointCollection CreateRpc(string sourceVMId, string rpcName,
                                                 string rgName, string location, Dictionary <string, string> tags)
        {
            //Models.SubResource sourceVM = new Models.SubResource(id: sourceVMId);
            RestorePointCollectionSourceProperties rpcSourceProperties = new RestorePointCollectionSourceProperties(location: location, id: sourceVMId);
            var inputRpc = new RestorePointCollection(location, source: rpcSourceProperties, name: rpcName, tags: tags);
            RestorePointCollection restorePointCollection =
                m_CrpClient.RestorePointCollections.CreateOrUpdate(rgName, rpcName,
                                                                   inputRpc);

            return(restorePointCollection);
        }
Beispiel #5
0
        public void CreateLocalRestorePointWithSecurityProfile()
        {
            string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION");

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                string location = "southcentralus";
                Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", location);
                EnsureClientsInitialized(context);
                var            rgName   = ComputeManagementTestUtilities.GenerateName(TestPrefix);
                ImageReference imageRef = new ImageReference(publisher: "MICROSOFTWINDOWSDESKTOP", offer: "WINDOWS-10", version: "latest", sku: "20H2-ENT-G2");
                VirtualMachine inputVM;
                string         storageAccountForDisks = TestUtilities.GenerateName(TestPrefix);
                string         availabilitySetName    = TestUtilities.GenerateName(TestPrefix);

                try
                {
                    // PUT VM with SecurityType = TrustedLaunch
                    VirtualMachine createdVM = CreateVM(rgName, availabilitySetName, storageAccountForDisks, imageRef, out inputVM, hasManagedDisks: true,
                                                        vmSize: VirtualMachineSizeTypes.StandardD2sV3, securityType: "TrustedLaunch");

                    string rpcName = ComputeManagementTestUtilities.GenerateName("rpcClientTest");
                    string rpName  = ComputeManagementTestUtilities.GenerateName("rpClientTest");

                    // Create Restore Point Collection
                    string vmId   = createdVM.Id;
                    string vmSize = createdVM.HardwareProfile.VmSize;
                    Dictionary <string, string> tags = new Dictionary <string, string>()
                    {
                        { "testTag", "testTagValue" }
                    };
                    RestorePointCollection createdRpc = CreateRpc(vmId, rpcName, rgName, location, tags);

                    // Create Restore Point
                    RestorePoint createdRP = CreateRestorePoint(rgName, rpcName, rpName, diskToExclude: null, sourceRestorePointId: null);

                    // GET Disk Restore Point
                    IPage <DiskRestorePoint> listDiskRestorePoint = m_CrpClient.DiskRestorePoint.ListByRestorePoint(rgName, rpcName, rpName);
                    var getDrp = m_CrpClient.DiskRestorePoint.Get(rgName, rpcName, rpName, listDiskRestorePoint.First().Name);

                    Assert.Equal("TrustedLaunch", getDrp.SecurityProfile.SecurityType);
                }
                catch (Exception e)
                {
                    throw e;
                }
                finally
                {
                    m_ResourcesClient.ResourceGroups.Delete(rgName);
                    Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", originalTestLocation);
                }
            }
        }
        // Verify that the two rpcs created by this test are in the GET restorePointCollections response.
        private void VerifyReturnedRpcs(IEnumerable <RestorePointCollection> rpcs, string rpcName1, string rpcName2, string remoteRcpName, string location,
                                        string remoteLocation, string sourceVMId, string sourceRpcId)
        {
            // two rpcs are returned because the RG has two rpcs
            RestorePointCollection rpc1 = rpcs.Where(rpc => rpc.Name == rpcName1).First();

            VerifyRpc(rpc1, rpcName1, location, sourceVMId);
            RestorePointCollection rpc2 = rpcs.Where(rpc => rpc.Name == rpcName2).First();

            VerifyRpc(rpc2, rpcName2, location, sourceVMId);
            RestorePointCollection rpc3 = rpcs.Where(rpc => rpc.Name == remoteRcpName).First();

            VerifyRpc(rpc3, remoteRcpName, remoteLocation, sourceRpcId);
        }
        // if verifying result of GET RPC with $expand=restorePoints, verify that the returned rpc contains the expected restore point
        private void VerifyRpc(RestorePointCollection rpc, string rpcName,
                               string location, string sourceVmId, bool shouldRpcContainRestorePoints = false)
        {
            Assert.NotNull(rpc);
            Assert.Equal(rpcName, rpc.Name);
            Assert.Equal(location, rpc.Location, ignoreCase: true);
            Assert.NotNull(rpc.Id);
            Assert.Equal("Microsoft.Compute/restorePointCollections", rpc.Type);
            Assert.Equal(sourceVmId, rpc.Source.Id, ignoreCase: true);
            Assert.NotNull(rpc.Id);
            IDictionary <string, string> tagsOnRestorePoint = rpc.Tags;

            // RPC contains restore points only if request contains $expand=restorePoints
            if (shouldRpcContainRestorePoints)
            {
                Assert.NotNull(rpc.RestorePoints);
                Assert.Equal(1, rpc.RestorePoints.Count);
            }
            else
            {
                Assert.Null(rpc.RestorePoints);
            }
        }
        public void CreateRpcAndRestorePoints()
        {
            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                EnsureClientsInitialized(context);
                string         location = ComputeManagementTestUtilities.DefaultLocation;
                var            rgName   = ComputeManagementTestUtilities.GenerateName(TestPrefix);
                ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true);
                VirtualMachine inputVM;
                string         storageAccountForDisksName = TestUtilities.GenerateName(TestPrefix);
                string         availabilitySetName        = TestUtilities.GenerateName(TestPrefix);

                try
                {
                    StorageAccount storageAccountForDisks = CreateStorageAccount(rgName, storageAccountForDisksName);
                    // create the VM
                    VirtualMachine createdVM = CreateVM(rgName, availabilitySetName, storageAccountForDisks, imageRef, out inputVM,
                                                        (vm) =>
                    {
                        vm.DiagnosticsProfile = GetManagedDiagnosticsProfile();
                    }, hasManagedDisks: true);
                    DataDisk dataDisk   = createdVM.StorageProfile.DataDisks[0];
                    string   dataDiskId = dataDisk.ManagedDisk.Id;
                    OSDisk   osDisk     = createdVM.StorageProfile.OsDisk;

                    string rpName   = ComputeManagementTestUtilities.GenerateName("rpClientTest");
                    string rpcName  = ComputeManagementTestUtilities.GenerateName("rpc1ClientTest");
                    string rpcName2 = ComputeManagementTestUtilities.GenerateName("rpc2ClientTest");
                    string vmId     = createdVM.Id;
                    string vmSize   = createdVM.HardwareProfile.VmSize;

                    // create two RPCs
                    Dictionary <string, string> tags = new Dictionary <string, string>()
                    {
                        { "RG", "rg" },
                        { "testTag", "testTagValue" },
                    };
                    RestorePointCollection createdRpc = CreateRpc(createdVM.Id, rpcName, rgName, location, tags);
                    VerifyRpc(createdRpc, rpcName, location, vmId);

                    RestorePointCollection createdRpc2 = CreateRpc(createdVM.Id, rpcName2, rgName, location, tags);
                    VerifyRpc(createdRpc2, rpcName2, location, vmId);

                    // for PATCH RPC, only tags are allowed to be updated
                    Dictionary <string, string> newTags = new Dictionary <string, string>()
                    {
                        { "newTag", "newValue1" },
                        { "newtestTag", "newValue2" },
                    };
                    UpdateRpc(rgName, rpcName, createdRpc, newTags);

                    // GET list of all rpc in the resource group.
                    IEnumerable <RestorePointCollection> rpcs = ListRpcInResourceGroup(rgName);
                    VerifyReturnedRpcs(rpcs, rpcName, rpcName2, location, vmId);

                    // GET list of all rpc in subscription.
                    rpcs = ListRpcInSubscription();
                    VerifyReturnedRpcs(rpcs, rpcName, rpcName2, location, vmId);

                    // create RP in the RPC
                    RestorePoint createdRP = CreateRestorePoint(rgName, rpcName, rpName, osDisk, diskToExclude: dataDiskId);
                    VerifyRestorePointDetails(createdRP, rpName, osDisk, 1,
                                              excludeDiskId: dataDiskId, vmSize: vmSize);
                    RestorePoint getRP = GetRP(rgName, rpcName, rpName);
                    VerifyRestorePointDetails(createdRP, rpName, osDisk, 1,
                                              excludeDiskId: dataDiskId, vmSize: vmSize);

                    // get RPC without $expand=restorePoints
                    RestorePointCollection returnedRpc = GetRpc(rgName, rpcName);
                    VerifyRpc(returnedRpc, rpcName, location, vmId);

                    // get RPC with $expand=restorePoints
                    returnedRpc = GetRpc(rgName, rpcName,
                                         RestorePointCollectionExpandOptions.RestorePoints);
                    VerifyRpc(returnedRpc, rpcName, location, vmId,
                              shouldRpcContainRestorePoints: true);

                    // verify the restore point returned from GET RPC with $expand=restorePoints
                    RestorePoint rpInRpc = returnedRpc.RestorePoints[0];
                    VerifyRestorePointDetails(rpInRpc, rpName, osDisk, 1,
                                              excludeDiskId: dataDiskId, vmSize: vmSize);

                    // delete the restore point
                    DeleteRP(rgName, rpcName, rpName);
                    // GET of deleted restore point should return 404 not found
                    try
                    {
                        GetRP(rgName, rpcName, rpName);
                        Assert.False(true);
                    }
                    catch (CloudException ex)
                    {
                        Assert.True(ex.Response.StatusCode == HttpStatusCode.NotFound);
                    }

                    // delete the restore point collection
                    DeleteRpc(rgName, rpcName);
                    // GET of deleted RPC should return 404 not found
                    try
                    {
                        GetRpc(rgName, rpcName);
                        Assert.False(true);
                    }
                    catch (CloudException ex)
                    {
                        Assert.True(ex.Response.StatusCode == HttpStatusCode.NotFound);
                    }
                }
                catch (Exception e)
                {
                    throw e;
                }
                finally
                {
                    m_ResourcesClient.ResourceGroups.Delete(rgName);
                }
            }
        }
Beispiel #9
0
 /// <summary>
 /// The operation to create or update the restore point collection. Please
 /// refer to https://aka.ms/RestorePoints for more details. When updating a
 /// restore point collection, only tags may be modified.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='restorePointCollectionName'>
 /// The name of the restore point collection.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the Create or Update restore point collection
 /// operation.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <RestorePointCollection> CreateOrUpdateAsync(this IRestorePointCollectionsOperations operations, string resourceGroupName, string restorePointCollectionName, RestorePointCollection parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, restorePointCollectionName, parameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Beispiel #10
0
 /// <summary>
 /// The operation to create or update the restore point collection. Please
 /// refer to https://aka.ms/RestorePoints for more details. When updating a
 /// restore point collection, only tags may be modified.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='restorePointCollectionName'>
 /// The name of the restore point collection.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the Create or Update restore point collection
 /// operation.
 /// </param>
 public static RestorePointCollection CreateOrUpdate(this IRestorePointCollectionsOperations operations, string resourceGroupName, string restorePointCollectionName, RestorePointCollection parameters)
 {
     return(operations.CreateOrUpdateAsync(resourceGroupName, restorePointCollectionName, parameters).GetAwaiter().GetResult());
 }