Esempio n. 1
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);
            });
        }
Esempio n. 2
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);
            });
        }