private async Task<string> ResizeDisk()
        {
            ServiceAccountCredential credential = new ServiceAccountCredential(
               new ServiceAccountCredential.Initializer(ServiceAccountEmail)
               {
                   Scopes = new[] { ComputeService.Scope.Compute, ComputeService.Scope.CloudPlatform }
               }.FromPrivateKey(PrivateKey));

            var cs = new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = "GCloud Resize Disk"
            };

            var t = new ComputeService(cs);

            var drr = new DisksResizeRequest
            {
                SizeGb = long.Parse(NewSize)
            };

            var request = t.Disks.Resize(drr, Project, Region + "-" + Zone, DiskName);

            var response = request.Execute();

            if (response.HttpErrorStatusCode != null)
            {
                var errorStr = new StringBuilder();
                foreach (var error in response.Error.Errors)
                    errorStr.AppendLine(error.Code + " - " + error.Message);
                return errorStr.ToString();
            }
            else return "Success";
        }
Ejemplo n.º 2
0
 /// <summary>Snippet for Resize</summary>
 public void Resize()
 {
     // Snippet: Resize(string, string, string, DisksResizeRequest, CallSettings)
     // Create client
     DisksClient disksClient = DisksClient.Create();
     // Initialize request argument(s)
     string             project = "";
     string             zone    = "";
     string             disk    = "";
     DisksResizeRequest disksResizeRequestResource = new DisksResizeRequest();
     // Make the request
     Operation response = disksClient.Resize(project, zone, disk, disksResizeRequestResource);
     // End snippet
 }
Ejemplo n.º 3
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);
            });
        }
Ejemplo n.º 4
0
        /// <summary>Snippet for ResizeAsync</summary>
        public async Task ResizeAsync()
        {
            // Snippet: ResizeAsync(string, string, string, DisksResizeRequest, CallSettings)
            // Additional: ResizeAsync(string, string, string, DisksResizeRequest, CancellationToken)
            // Create client
            DisksClient disksClient = await DisksClient.CreateAsync();

            // Initialize request argument(s)
            string             project = "";
            string             zone    = "";
            string             disk    = "";
            DisksResizeRequest disksResizeRequestResource = new DisksResizeRequest();
            // Make the request
            Operation response = await disksClient.ResizeAsync(project, zone, disk, disksResizeRequestResource);

            // End snippet
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Resizes the specified persistent disk.
        /// Documentation https://developers.google.com/compute/alpha/reference/disks/resize
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated compute service.</param>
        /// <param name="project">Project ID for this request.</param>
        /// <param name="zone">The name of the zone for this request.</param>
        /// <param name="disk">The name of the persistent disk.</param>
        /// <param name="body">A valid compute alpha body.</param>
        /// <returns>OperationResponse</returns>
        public static Operation Resize(computeService service, string project, string zone, string disk, DisksResizeRequest body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }
                if (zone == null)
                {
                    throw new ArgumentNullException(zone);
                }
                if (disk == null)
                {
                    throw new ArgumentNullException(disk);
                }

                // Make the request.
                return(service.Disks.Resize(body, project, zone, disk).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Disks.Resize failed.", ex);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Resizes the specified persistent disk.
        /// Documentation https://developers.google.com/compute/beta/reference/disks/resize
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Compute service.</param>
        /// <param name="project">Project ID for this request.</param>
        /// <param name="zone">The name of the zone for this request.</param>
        /// <param name="disk">The name of the persistent disk.</param>
        /// <param name="body">A valid Compute beta body.</param>
        /// <param name="optional">Optional paramaters.</param>
        /// <returns>OperationResponse</returns>
        public static Operation Resize(ComputeService service, string project, string zone, string disk, DisksResizeRequest body, DisksResizeOptionalParms optional = null)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }
                if (zone == null)
                {
                    throw new ArgumentNullException(zone);
                }
                if (disk == null)
                {
                    throw new ArgumentNullException(disk);
                }

                // Building the initial request.
                var request = service.Disks.Resize(body, project, zone, disk);

                // Applying optional parameters to the request.
                request = (DisksResource.ResizeRequest)SampleHelpers.ApplyOptionalParms(request, optional);

                // Requesting data.
                return(request.Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Disks.Resize failed.", ex);
            }
        }
        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);
            });
        }