Exemple #1
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                if (ShouldProcess(this.Name, VerbsCommon.New))
                {
                    DiskAccess diskAccess = new DiskAccess();
                    diskAccess.Location   = this.Location;

                    var result   = DiskAccessesClient.CreateOrUpdate(this.ResourceGroupName, this.Name, diskAccess);
                    var psObject = new PSDiskAccess();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <DiskAccess, PSDiskAccess>(result, psObject);
                    WriteObject(psObject);
                }
            });
        }
Exemple #2
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                if (ShouldProcess(this.Name, VerbsCommon.Remove))
                {
                    string resourceGroupName;
                    string diskAccessName;
                    switch (this.ParameterSetName)
                    {
                    case ResourceIDParameterSet:
                        resourceGroupName = GetResourceGroupName(this.ResourceId);
                        diskAccessName    = GetResourceName(this.ResourceId, "Microsoft.Compute/diskAccesses");
                        break;

                    case InputObjectParameterSet:
                        resourceGroupName = GetResourceGroupName(this.InputObject.Id);
                        diskAccessName    = GetResourceName(this.InputObject.Id, "Microsoft.Compute/diskAccesses");
                        break;

                    default:
                        resourceGroupName = this.ResourceGroupName;
                        diskAccessName    = this.Name;
                        break;
                    }

                    var result = DiskAccessesClient.DeleteWithHttpMessagesAsync(resourceGroupName, diskAccessName).GetAwaiter().GetResult();
                    PSOperationStatusResponse output = new PSOperationStatusResponse
                    {
                        StartTime = this.StartTime,
                        EndTime   = DateTime.Now
                    };

                    if (result != null && result.Request != null && result.Request.RequestUri != null)
                    {
                        output.Name = GetOperationIdFromUrlString(result.Request.RequestUri.ToString());
                    }

                    WriteObject(output);
                }
            });
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                string resourceGroupName;
                string diskAccessName;

                if (this.ParameterSetName == ResourceIDParameterSet)
                {
                    resourceGroupName = GetResourceGroupName(this.ResourceId);
                    diskAccessName    = GetResourceName(this.ResourceId, "Microsoft.Compute/diskAccesses");
                }
                else
                {
                    resourceGroupName = this.ResourceGroupName;
                    diskAccessName    = this.Name;
                }

                if (ShouldGetByName(resourceGroupName, diskAccessName))
                {
                    var result   = DiskAccessesClient.Get(resourceGroupName, diskAccessName);
                    var psObject = new PSDiskAccess();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <DiskAccess, PSDiskAccess>(result, psObject);
                    WriteObject(psObject);
                }
                else if (ShouldListByResourceGroup(resourceGroupName, diskAccessName))
                {
                    var result       = DiskAccessesClient.ListByResourceGroup(resourceGroupName);
                    var resultList   = result.ToList();
                    var nextPageLink = result.NextPageLink;
                    while (!string.IsNullOrEmpty(nextPageLink))
                    {
                        var pageResult = DiskAccessesClient.ListByResourceGroupNext(nextPageLink);
                        foreach (var pageItem in pageResult)
                        {
                            resultList.Add(pageItem);
                        }
                        nextPageLink = pageResult.NextPageLink;
                    }
                    var psObject = new List <PSDiskAccessList>();
                    foreach (var r in resultList)
                    {
                        psObject.Add(ComputeAutomationAutoMapperProfile.Mapper.Map <DiskAccess, PSDiskAccessList>(r));
                    }
                    WriteObject(TopLevelWildcardFilter(resourceGroupName, diskAccessName, psObject), true);
                }
                else
                {
                    var result       = DiskAccessesClient.List();
                    var resultList   = result.ToList();
                    var nextPageLink = result.NextPageLink;
                    while (!string.IsNullOrEmpty(nextPageLink))
                    {
                        var pageResult = DiskAccessesClient.ListNext(nextPageLink);
                        foreach (var pageItem in pageResult)
                        {
                            resultList.Add(pageItem);
                        }
                        nextPageLink = pageResult.NextPageLink;
                    }
                    var psObject = new List <PSDiskAccessList>();
                    foreach (var r in resultList)
                    {
                        psObject.Add(ComputeAutomationAutoMapperProfile.Mapper.Map <DiskAccess, PSDiskAccessList>(r));
                    }
                    WriteObject(TopLevelWildcardFilter(resourceGroupName, diskAccessName, psObject), true);
                }
            });
        }