示例#1
0
        protected override void ProcessRecord()
        {
            string project;
            string zone;
            string name;

            switch (ParameterSetName)
            {
            case ParameterSetNames.ByName:
                project = Project;
                zone    = Zone;
                name    = DiskName;
                break;

            case ParameterSetNames.ByObject:
                project = GetProjectNameFromUri(InputObject.SelfLink);
                zone    = GetZoneNameFromUri(InputObject.Zone);
                name    = InputObject.Name;
                break;

            default:
                throw UnknownParameterSetException;
            }

            // In PowerShell, 10GB is parsed as 10*2^30. If a user enters 10GB, bring it back down to 10.
            if (NewSizeGb > 1L << 30)
            {
                NewSizeGb = NewSizeGb / (1L << 30);
            }

            var diskResizeReq = new DisksResizeRequest {
                SizeGb = NewSizeGb
            };

            DisksResource.ResizeRequest resizeReq =
                Service.Disks.Resize(diskResizeReq, project, zone, name);

            Operation op = resizeReq.Execute();

            AddZoneOperation(project, zone, op, () =>
            {
                // Return the updated disk.
                DisksResource.GetRequest getReq = Service.Disks.Get(project, zone, name);
                Disk disk = getReq.Execute();
                WriteObject(disk);
            });
        }
示例#2
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            // Special case. If you specify the Project, Zone, and DiskName we use the Get command to
            // get the specific disk. This will throw a 404 if it does not exist.
            if (!String.IsNullOrEmpty(Project) && !String.IsNullOrEmpty(Zone) && !String.IsNullOrEmpty(DiskName))
            {
                DisksResource.GetRequest getReq = Service.Disks.Get(Project, Zone, DiskName);
                Disk disk = getReq.Execute();
                WriteObject(disk);
                return;
            }

            DisksResource.AggregatedListRequest listReq = Service.Disks.AggregatedList(Project);
            // The v1 version of the API only supports one filter at a time. So we need to
            // specify a filter here and manually filter results later. Also, since the only
            // operations are "eq" and "ne", we don't use the filter for zone so that we can
            // can allow filtering by regions.
            if (!String.IsNullOrEmpty(DiskName))
            {
                listReq.Filter = $"name eq \"{DiskName}\"";
            }

            // First page. AggregatedList.Items is a dictionary of zone to disks.
            DiskAggregatedList disks = listReq.Execute();

            foreach (DisksScopedList diskList in disks.Items.Values)
            {
                WriteDiskObjects(diskList.Disks);
            }

            // Keep paging through results as necessary.
            while (disks.NextPageToken != null)
            {
                listReq.PageToken = disks.NextPageToken;
                disks             = listReq.Execute();
                foreach (DisksScopedList diskList in disks.Items.Values)
                {
                    WriteDiskObjects(diskList.Disks);
                }
            }
        }
示例#3
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            // The GCE API requires disk types to be specified as URI-like things.
            // If null will default to "pd-standard"
            string diskTypeResource = DiskType;

            if (diskTypeResource != null)
            {
                diskTypeResource = $"zones/{Zone}/diskTypes/{DiskType}";
            }

            // In PowerShell, 10GB is parsed as 10*2^30. If a user enters 10GB, bring it back down to 10.
            if (SizeGb.HasValue && SizeGb.Value > 1L << 30)
            {
                SizeGb = SizeGb.Value / (1L << 30);
            }

            Disk newDisk = new Disk
            {
                Name           = DiskName,
                Type           = diskTypeResource,
                SourceSnapshot = Snapshot?.SelfLink,
                SourceImage    = Image?.SelfLink,
                // Optional fields. OK if null.
                Description = Description,
                SizeGb      = SizeGb,
                Labels      = ConvertToDictionary <string, string>(Label)
            };

            DisksResource.InsertRequest insertReq = Service.Disks.Insert(newDisk, Project, Zone);

            Operation op = insertReq.Execute();

            AddZoneOperation(Project, Zone, op, () =>
            {
                // Return the newly created disk.
                DisksResource.GetRequest getReq = Service.Disks.Get(Project, Zone, DiskName);
                Disk disk = getReq.Execute();
                WriteObject(disk);
            });
        }
示例#4
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            // The GCE API requires disk types to be specified as URI-like things.
            // If null will default to "pd-standard"
            string diskTypeResource = DiskType;

            if (diskTypeResource != null)
            {
                diskTypeResource = $"zones/{Zone}/diskTypes/{DiskType}";
            }

            Disk newDisk = new Disk
            {
                Name           = DiskName,
                Type           = diskTypeResource,
                SourceSnapshot = Snapshot?.SelfLink,
                SourceImage    = Image?.SelfLink,
                // Optional fields. OK if null.
                Description = Description,
                SizeGb      = SizeGb
            };

            DisksResource.InsertRequest insertReq = Service.Disks.Insert(newDisk, Project, Zone);

            Operation op = insertReq.Execute();

            AddZoneOperation(Project, Zone, op, () =>
            {
                // Return the newly created disk.
                DisksResource.GetRequest getReq = Service.Disks.Get(Project, Zone, DiskName);
                Disk disk = getReq.Execute();
                WriteObject(disk);
            });
        }