blob: 365b3efe4fcb3687d3fddbb74612957e8e80b445 [file] [log] [blame]
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Code generated by protoc-gen-go_gapic. DO NOT EDIT.
package compute
import (
"bytes"
"context"
"fmt"
"io/ioutil"
"net/http"
"net/url"
gax "github.com/googleapis/gax-go/v2"
"google.golang.org/api/option"
"google.golang.org/api/option/internaloption"
httptransport "google.golang.org/api/transport/http"
computepb "google.golang.org/genproto/googleapis/cloud/compute/v1"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
"google.golang.org/protobuf/encoding/protojson"
)
var newInstancesClientHook clientHook
// InstancesCallOptions contains the retry settings for each method of InstancesClient.
type InstancesCallOptions struct {
AddAccessConfig []gax.CallOption
AddResourcePolicies []gax.CallOption
AggregatedList []gax.CallOption
AttachDisk []gax.CallOption
BulkInsert []gax.CallOption
Delete []gax.CallOption
DeleteAccessConfig []gax.CallOption
DetachDisk []gax.CallOption
Get []gax.CallOption
GetEffectiveFirewalls []gax.CallOption
GetGuestAttributes []gax.CallOption
GetIamPolicy []gax.CallOption
GetScreenshot []gax.CallOption
GetSerialPortOutput []gax.CallOption
GetShieldedInstanceIdentity []gax.CallOption
Insert []gax.CallOption
List []gax.CallOption
ListReferrers []gax.CallOption
RemoveResourcePolicies []gax.CallOption
Reset []gax.CallOption
SetDeletionProtection []gax.CallOption
SetDiskAutoDelete []gax.CallOption
SetIamPolicy []gax.CallOption
SetLabels []gax.CallOption
SetMachineResources []gax.CallOption
SetMachineType []gax.CallOption
SetMetadata []gax.CallOption
SetMinCpuPlatform []gax.CallOption
SetScheduling []gax.CallOption
SetServiceAccount []gax.CallOption
SetShieldedInstanceIntegrityPolicy []gax.CallOption
SetTags []gax.CallOption
SimulateMaintenanceEvent []gax.CallOption
Start []gax.CallOption
StartWithEncryptionKey []gax.CallOption
Stop []gax.CallOption
TestIamPermissions []gax.CallOption
Update []gax.CallOption
UpdateAccessConfig []gax.CallOption
UpdateDisplayDevice []gax.CallOption
UpdateNetworkInterface []gax.CallOption
UpdateShieldedInstanceConfig []gax.CallOption
}
// internalInstancesClient is an interface that defines the methods availaible from Google Compute Engine API.
type internalInstancesClient interface {
Close() error
setGoogleClientInfo(...string)
Connection() *grpc.ClientConn
AddAccessConfig(context.Context, *computepb.AddAccessConfigInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
AddResourcePolicies(context.Context, *computepb.AddResourcePoliciesInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
AggregatedList(context.Context, *computepb.AggregatedListInstancesRequest, ...gax.CallOption) (*computepb.InstanceAggregatedList, error)
AttachDisk(context.Context, *computepb.AttachDiskInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
BulkInsert(context.Context, *computepb.BulkInsertInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
Delete(context.Context, *computepb.DeleteInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
DeleteAccessConfig(context.Context, *computepb.DeleteAccessConfigInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
DetachDisk(context.Context, *computepb.DetachDiskInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
Get(context.Context, *computepb.GetInstanceRequest, ...gax.CallOption) (*computepb.Instance, error)
GetEffectiveFirewalls(context.Context, *computepb.GetEffectiveFirewallsInstanceRequest, ...gax.CallOption) (*computepb.InstancesGetEffectiveFirewallsResponse, error)
GetGuestAttributes(context.Context, *computepb.GetGuestAttributesInstanceRequest, ...gax.CallOption) (*computepb.GuestAttributes, error)
GetIamPolicy(context.Context, *computepb.GetIamPolicyInstanceRequest, ...gax.CallOption) (*computepb.Policy, error)
GetScreenshot(context.Context, *computepb.GetScreenshotInstanceRequest, ...gax.CallOption) (*computepb.Screenshot, error)
GetSerialPortOutput(context.Context, *computepb.GetSerialPortOutputInstanceRequest, ...gax.CallOption) (*computepb.SerialPortOutput, error)
GetShieldedInstanceIdentity(context.Context, *computepb.GetShieldedInstanceIdentityInstanceRequest, ...gax.CallOption) (*computepb.ShieldedInstanceIdentity, error)
Insert(context.Context, *computepb.InsertInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
List(context.Context, *computepb.ListInstancesRequest, ...gax.CallOption) (*computepb.InstanceList, error)
ListReferrers(context.Context, *computepb.ListReferrersInstancesRequest, ...gax.CallOption) (*computepb.InstanceListReferrers, error)
RemoveResourcePolicies(context.Context, *computepb.RemoveResourcePoliciesInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
Reset(context.Context, *computepb.ResetInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
SetDeletionProtection(context.Context, *computepb.SetDeletionProtectionInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
SetDiskAutoDelete(context.Context, *computepb.SetDiskAutoDeleteInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
SetIamPolicy(context.Context, *computepb.SetIamPolicyInstanceRequest, ...gax.CallOption) (*computepb.Policy, error)
SetLabels(context.Context, *computepb.SetLabelsInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
SetMachineResources(context.Context, *computepb.SetMachineResourcesInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
SetMachineType(context.Context, *computepb.SetMachineTypeInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
SetMetadata(context.Context, *computepb.SetMetadataInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
SetMinCpuPlatform(context.Context, *computepb.SetMinCpuPlatformInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
SetScheduling(context.Context, *computepb.SetSchedulingInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
SetServiceAccount(context.Context, *computepb.SetServiceAccountInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
SetShieldedInstanceIntegrityPolicy(context.Context, *computepb.SetShieldedInstanceIntegrityPolicyInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
SetTags(context.Context, *computepb.SetTagsInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
SimulateMaintenanceEvent(context.Context, *computepb.SimulateMaintenanceEventInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
Start(context.Context, *computepb.StartInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
StartWithEncryptionKey(context.Context, *computepb.StartWithEncryptionKeyInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
Stop(context.Context, *computepb.StopInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
TestIamPermissions(context.Context, *computepb.TestIamPermissionsInstanceRequest, ...gax.CallOption) (*computepb.TestPermissionsResponse, error)
Update(context.Context, *computepb.UpdateInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
UpdateAccessConfig(context.Context, *computepb.UpdateAccessConfigInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
UpdateDisplayDevice(context.Context, *computepb.UpdateDisplayDeviceInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
UpdateNetworkInterface(context.Context, *computepb.UpdateNetworkInterfaceInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
UpdateShieldedInstanceConfig(context.Context, *computepb.UpdateShieldedInstanceConfigInstanceRequest, ...gax.CallOption) (*computepb.Operation, error)
}
// InstancesClient is a client for interacting with Google Compute Engine API.
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
//
// The Instances API.
type InstancesClient struct {
// The internal transport-dependent client.
internalClient internalInstancesClient
// The call options for this service.
CallOptions *InstancesCallOptions
}
// Wrapper methods routed to the internal client.
// Close closes the connection to the API service. The user should invoke this when
// the client is no longer required.
func (c *InstancesClient) Close() error {
return c.internalClient.Close()
}
// setGoogleClientInfo sets the name and version of the application in
// the `x-goog-api-client` header passed on each request. Intended for
// use by Google-written clients.
func (c *InstancesClient) setGoogleClientInfo(keyval ...string) {
c.internalClient.setGoogleClientInfo(keyval...)
}
// Connection returns a connection to the API service.
//
// Deprecated.
func (c *InstancesClient) Connection() *grpc.ClientConn {
return c.internalClient.Connection()
}
// AddAccessConfig adds an access config to an instance’s network interface.
func (c *InstancesClient) AddAccessConfig(ctx context.Context, req *computepb.AddAccessConfigInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.AddAccessConfig(ctx, req, opts...)
}
// AddResourcePolicies adds existing resource policies to an instance. You can only add one policy right now which will be applied to this instance for scheduling live migrations.
func (c *InstancesClient) AddResourcePolicies(ctx context.Context, req *computepb.AddResourcePoliciesInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.AddResourcePolicies(ctx, req, opts...)
}
// AggregatedList retrieves aggregated list of all of the instances in your project across all regions and zones.
func (c *InstancesClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListInstancesRequest, opts ...gax.CallOption) (*computepb.InstanceAggregatedList, error) {
return c.internalClient.AggregatedList(ctx, req, opts...)
}
// AttachDisk attaches an existing Disk resource to an instance. You must first create the disk before you can attach it. It is not possible to create and attach a disk at the same time. For more information, read Adding a persistent disk to your instance.
func (c *InstancesClient) AttachDisk(ctx context.Context, req *computepb.AttachDiskInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.AttachDisk(ctx, req, opts...)
}
// BulkInsert creates multiple instances. Count specifies the number of instances to create.
func (c *InstancesClient) BulkInsert(ctx context.Context, req *computepb.BulkInsertInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.BulkInsert(ctx, req, opts...)
}
// Delete deletes the specified Instance resource. For more information, see Deleting an instance.
func (c *InstancesClient) Delete(ctx context.Context, req *computepb.DeleteInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.Delete(ctx, req, opts...)
}
// DeleteAccessConfig deletes an access config from an instance’s network interface.
func (c *InstancesClient) DeleteAccessConfig(ctx context.Context, req *computepb.DeleteAccessConfigInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.DeleteAccessConfig(ctx, req, opts...)
}
// DetachDisk detaches a disk from an instance.
func (c *InstancesClient) DetachDisk(ctx context.Context, req *computepb.DetachDiskInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.DetachDisk(ctx, req, opts...)
}
// Get returns the specified Instance resource. Gets a list of available instances by making a list() request.
func (c *InstancesClient) Get(ctx context.Context, req *computepb.GetInstanceRequest, opts ...gax.CallOption) (*computepb.Instance, error) {
return c.internalClient.Get(ctx, req, opts...)
}
// GetEffectiveFirewalls returns effective firewalls applied to an interface of the instance.
func (c *InstancesClient) GetEffectiveFirewalls(ctx context.Context, req *computepb.GetEffectiveFirewallsInstanceRequest, opts ...gax.CallOption) (*computepb.InstancesGetEffectiveFirewallsResponse, error) {
return c.internalClient.GetEffectiveFirewalls(ctx, req, opts...)
}
// GetGuestAttributes returns the specified guest attributes entry.
func (c *InstancesClient) GetGuestAttributes(ctx context.Context, req *computepb.GetGuestAttributesInstanceRequest, opts ...gax.CallOption) (*computepb.GuestAttributes, error) {
return c.internalClient.GetGuestAttributes(ctx, req, opts...)
}
// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists.
func (c *InstancesClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyInstanceRequest, opts ...gax.CallOption) (*computepb.Policy, error) {
return c.internalClient.GetIamPolicy(ctx, req, opts...)
}
// GetScreenshot returns the screenshot from the specified instance.
func (c *InstancesClient) GetScreenshot(ctx context.Context, req *computepb.GetScreenshotInstanceRequest, opts ...gax.CallOption) (*computepb.Screenshot, error) {
return c.internalClient.GetScreenshot(ctx, req, opts...)
}
// GetSerialPortOutput returns the last 1 MB of serial port output from the specified instance.
func (c *InstancesClient) GetSerialPortOutput(ctx context.Context, req *computepb.GetSerialPortOutputInstanceRequest, opts ...gax.CallOption) (*computepb.SerialPortOutput, error) {
return c.internalClient.GetSerialPortOutput(ctx, req, opts...)
}
// GetShieldedInstanceIdentity returns the Shielded Instance Identity of an instance
func (c *InstancesClient) GetShieldedInstanceIdentity(ctx context.Context, req *computepb.GetShieldedInstanceIdentityInstanceRequest, opts ...gax.CallOption) (*computepb.ShieldedInstanceIdentity, error) {
return c.internalClient.GetShieldedInstanceIdentity(ctx, req, opts...)
}
// Insert creates an instance resource in the specified project using the data included in the request.
func (c *InstancesClient) Insert(ctx context.Context, req *computepb.InsertInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.Insert(ctx, req, opts...)
}
// List retrieves the list of instances contained within the specified zone.
func (c *InstancesClient) List(ctx context.Context, req *computepb.ListInstancesRequest, opts ...gax.CallOption) (*computepb.InstanceList, error) {
return c.internalClient.List(ctx, req, opts...)
}
// ListReferrers retrieves a list of resources that refer to the VM instance specified in the request. For example, if the VM instance is part of a managed or unmanaged instance group, the referrers list includes the instance group. For more information, read Viewing referrers to VM instances.
func (c *InstancesClient) ListReferrers(ctx context.Context, req *computepb.ListReferrersInstancesRequest, opts ...gax.CallOption) (*computepb.InstanceListReferrers, error) {
return c.internalClient.ListReferrers(ctx, req, opts...)
}
// RemoveResourcePolicies removes resource policies from an instance.
func (c *InstancesClient) RemoveResourcePolicies(ctx context.Context, req *computepb.RemoveResourcePoliciesInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.RemoveResourcePolicies(ctx, req, opts...)
}
// Reset performs a reset on the instance. This is a hard reset the VM does not do a graceful shutdown. For more information, see Resetting an instance.
func (c *InstancesClient) Reset(ctx context.Context, req *computepb.ResetInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.Reset(ctx, req, opts...)
}
// SetDeletionProtection sets deletion protection on the instance.
func (c *InstancesClient) SetDeletionProtection(ctx context.Context, req *computepb.SetDeletionProtectionInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.SetDeletionProtection(ctx, req, opts...)
}
// SetDiskAutoDelete sets the auto-delete flag for a disk attached to an instance.
func (c *InstancesClient) SetDiskAutoDelete(ctx context.Context, req *computepb.SetDiskAutoDeleteInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.SetDiskAutoDelete(ctx, req, opts...)
}
// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy.
func (c *InstancesClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyInstanceRequest, opts ...gax.CallOption) (*computepb.Policy, error) {
return c.internalClient.SetIamPolicy(ctx, req, opts...)
}
// SetLabels sets labels on an instance. To learn more about labels, read the Labeling Resources documentation.
func (c *InstancesClient) SetLabels(ctx context.Context, req *computepb.SetLabelsInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.SetLabels(ctx, req, opts...)
}
// SetMachineResources changes the number and/or type of accelerator for a stopped instance to the values specified in the request.
func (c *InstancesClient) SetMachineResources(ctx context.Context, req *computepb.SetMachineResourcesInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.SetMachineResources(ctx, req, opts...)
}
// SetMachineType changes the machine type for a stopped instance to the machine type specified in the request.
func (c *InstancesClient) SetMachineType(ctx context.Context, req *computepb.SetMachineTypeInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.SetMachineType(ctx, req, opts...)
}
// SetMetadata sets metadata for the specified instance to the data included in the request.
func (c *InstancesClient) SetMetadata(ctx context.Context, req *computepb.SetMetadataInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.SetMetadata(ctx, req, opts...)
}
// SetMinCpuPlatform changes the minimum CPU platform that this instance should use. This method can only be called on a stopped instance. For more information, read Specifying a Minimum CPU Platform.
func (c *InstancesClient) SetMinCpuPlatform(ctx context.Context, req *computepb.SetMinCpuPlatformInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.SetMinCpuPlatform(ctx, req, opts...)
}
// SetScheduling sets an instance’s scheduling options. You can only call this method on a stopped instance, that is, a VM instance that is in a TERMINATED state. See Instance Life Cycle for more information on the possible instance states.
func (c *InstancesClient) SetScheduling(ctx context.Context, req *computepb.SetSchedulingInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.SetScheduling(ctx, req, opts...)
}
// SetServiceAccount sets the service account on the instance. For more information, read Changing the service account and access scopes for an instance.
func (c *InstancesClient) SetServiceAccount(ctx context.Context, req *computepb.SetServiceAccountInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.SetServiceAccount(ctx, req, opts...)
}
// SetShieldedInstanceIntegrityPolicy sets the Shielded Instance integrity policy for an instance. You can only use this method on a running instance. This method supports PATCH semantics and uses the JSON merge patch format and processing rules.
func (c *InstancesClient) SetShieldedInstanceIntegrityPolicy(ctx context.Context, req *computepb.SetShieldedInstanceIntegrityPolicyInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.SetShieldedInstanceIntegrityPolicy(ctx, req, opts...)
}
// SetTags sets network tags for the specified instance to the data included in the request.
func (c *InstancesClient) SetTags(ctx context.Context, req *computepb.SetTagsInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.SetTags(ctx, req, opts...)
}
// SimulateMaintenanceEvent simulates a maintenance event on the instance.
func (c *InstancesClient) SimulateMaintenanceEvent(ctx context.Context, req *computepb.SimulateMaintenanceEventInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.SimulateMaintenanceEvent(ctx, req, opts...)
}
// Start starts an instance that was stopped using the instances().stop method. For more information, see Restart an instance.
func (c *InstancesClient) Start(ctx context.Context, req *computepb.StartInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.Start(ctx, req, opts...)
}
// StartWithEncryptionKey starts an instance that was stopped using the instances().stop method. For more information, see Restart an instance.
func (c *InstancesClient) StartWithEncryptionKey(ctx context.Context, req *computepb.StartWithEncryptionKeyInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.StartWithEncryptionKey(ctx, req, opts...)
}
// Stop stops a running instance, shutting it down cleanly, and allows you to restart the instance at a later time. Stopped instances do not incur VM usage charges while they are stopped. However, resources that the VM is using, such as persistent disks and static IP addresses, will continue to be charged until they are deleted. For more information, see Stopping an instance.
func (c *InstancesClient) Stop(ctx context.Context, req *computepb.StopInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.Stop(ctx, req, opts...)
}
// TestIamPermissions returns permissions that a caller has on the specified resource.
func (c *InstancesClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsInstanceRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) {
return c.internalClient.TestIamPermissions(ctx, req, opts...)
}
// Update updates an instance only if the necessary resources are available. This method can update only a specific set of instance properties. See Updating a running instance for a list of updatable instance properties.
func (c *InstancesClient) Update(ctx context.Context, req *computepb.UpdateInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.Update(ctx, req, opts...)
}
// UpdateAccessConfig updates the specified access config from an instance’s network interface with the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules.
func (c *InstancesClient) UpdateAccessConfig(ctx context.Context, req *computepb.UpdateAccessConfigInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.UpdateAccessConfig(ctx, req, opts...)
}
// UpdateDisplayDevice updates the Display config for a VM instance. You can only use this method on a stopped VM instance. This method supports PATCH semantics and uses the JSON merge patch format and processing rules.
func (c *InstancesClient) UpdateDisplayDevice(ctx context.Context, req *computepb.UpdateDisplayDeviceInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.UpdateDisplayDevice(ctx, req, opts...)
}
// UpdateNetworkInterface updates an instance’s network interface. This method can only update an interface’s alias IP range and attached network. See Modifying alias IP ranges for an existing instance for instructions on changing alias IP ranges. See Migrating a VM between networks for instructions on migrating an interface. This method follows PATCH semantics.
func (c *InstancesClient) UpdateNetworkInterface(ctx context.Context, req *computepb.UpdateNetworkInterfaceInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.UpdateNetworkInterface(ctx, req, opts...)
}
// UpdateShieldedInstanceConfig updates the Shielded Instance config for an instance. You can only use this method on a stopped instance. This method supports PATCH semantics and uses the JSON merge patch format and processing rules.
func (c *InstancesClient) UpdateShieldedInstanceConfig(ctx context.Context, req *computepb.UpdateShieldedInstanceConfigInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.UpdateShieldedInstanceConfig(ctx, req, opts...)
}
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
type instancesRESTClient struct {
// The http endpoint to connect to.
endpoint string
// The http client.
httpClient *http.Client
// The x-goog-* metadata to be sent with each request.
xGoogMetadata metadata.MD
}
// NewInstancesRESTClient creates a new instances rest client.
//
// The Instances API.
func NewInstancesRESTClient(ctx context.Context, opts ...option.ClientOption) (*InstancesClient, error) {
clientOpts := append(defaultInstancesRESTClientOptions(), opts...)
httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
if err != nil {
return nil, err
}
c := &instancesRESTClient{
endpoint: endpoint,
httpClient: httpClient,
}
c.setGoogleClientInfo()
return &InstancesClient{internalClient: c, CallOptions: &InstancesCallOptions{}}, nil
}
func defaultInstancesRESTClientOptions() []option.ClientOption {
return []option.ClientOption{
internaloption.WithDefaultEndpoint("compute.googleapis.com"),
internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"),
internaloption.WithDefaultAudience("https://compute.googleapis.com/"),
internaloption.WithDefaultScopes(DefaultAuthScopes()...),
}
}
// setGoogleClientInfo sets the name and version of the application in
// the `x-goog-api-client` header passed on each request. Intended for
// use by Google-written clients.
func (c *instancesRESTClient) setGoogleClientInfo(keyval ...string) {
kv := append([]string{"gl-go", versionGo()}, keyval...)
kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN")
c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
}
// Close closes the connection to the API service. The user should invoke this when
// the client is no longer required.
func (c *instancesRESTClient) Close() error {
// Replace httpClient with nil to force cleanup.
c.httpClient = nil
return nil
}
// Connection returns a connection to the API service.
//
// Deprecated.
func (c *instancesRESTClient) Connection() *grpc.ClientConn {
return nil
}
// AddAccessConfig adds an access config to an instance’s network interface.
func (c *instancesRESTClient) AddAccessConfig(ctx context.Context, req *computepb.AddAccessConfigInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetAccessConfigResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/addAccessConfig", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req.GetNetworkInterface() != "" {
params.Add("networkInterface", fmt.Sprintf("%v", req.GetNetworkInterface()))
}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// AddResourcePolicies adds existing resource policies to an instance. You can only add one policy right now which will be applied to this instance for scheduling live migrations.
func (c *instancesRESTClient) AddResourcePolicies(ctx context.Context, req *computepb.AddResourcePoliciesInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetInstancesAddResourcePoliciesRequestResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/addResourcePolicies", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// AggregatedList retrieves aggregated list of all of the instances in your project across all regions and zones.
func (c *instancesRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListInstancesRequest, opts ...gax.CallOption) (*computepb.InstanceAggregatedList, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
jsonReq, err := m.Marshal(req)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/instances", req.GetProject())
params := url.Values{}
if req != nil && req.Filter != nil {
params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
}
if req != nil && req.IncludeAllScopes != nil {
params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes()))
}
if req != nil && req.MaxResults != nil {
params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults()))
}
if req != nil && req.OrderBy != nil {
params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy()))
}
if req != nil && req.PageToken != nil {
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
}
if req != nil && req.ReturnPartialSuccess != nil {
params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.InstanceAggregatedList{}
return rsp, unm.Unmarshal(buf, rsp)
}
// AttachDisk attaches an existing Disk resource to an instance. You must first create the disk before you can attach it. It is not possible to create and attach a disk at the same time. For more information, read Adding a persistent disk to your instance.
func (c *instancesRESTClient) AttachDisk(ctx context.Context, req *computepb.AttachDiskInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetAttachedDiskResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/attachDisk", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req != nil && req.ForceAttach != nil {
params.Add("forceAttach", fmt.Sprintf("%v", req.GetForceAttach()))
}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// BulkInsert creates multiple instances. Count specifies the number of instances to create.
func (c *instancesRESTClient) BulkInsert(ctx context.Context, req *computepb.BulkInsertInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetBulkInsertInstanceResourceResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/bulkInsert", req.GetProject(), req.GetZone())
params := url.Values{}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// Delete deletes the specified Instance resource. For more information, see Deleting an instance.
func (c *instancesRESTClient) Delete(ctx context.Context, req *computepb.DeleteInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
jsonReq, err := m.Marshal(req)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// DeleteAccessConfig deletes an access config from an instance’s network interface.
func (c *instancesRESTClient) DeleteAccessConfig(ctx context.Context, req *computepb.DeleteAccessConfigInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
jsonReq, err := m.Marshal(req)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/deleteAccessConfig", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req.GetAccessConfig() != "" {
params.Add("accessConfig", fmt.Sprintf("%v", req.GetAccessConfig()))
}
if req.GetNetworkInterface() != "" {
params.Add("networkInterface", fmt.Sprintf("%v", req.GetNetworkInterface()))
}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// DetachDisk detaches a disk from an instance.
func (c *instancesRESTClient) DetachDisk(ctx context.Context, req *computepb.DetachDiskInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
jsonReq, err := m.Marshal(req)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/detachDisk", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req.GetDeviceName() != "" {
params.Add("deviceName", fmt.Sprintf("%v", req.GetDeviceName()))
}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// Get returns the specified Instance resource. Gets a list of available instances by making a list() request.
func (c *instancesRESTClient) Get(ctx context.Context, req *computepb.GetInstanceRequest, opts ...gax.CallOption) (*computepb.Instance, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
jsonReq, err := m.Marshal(req)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v", req.GetProject(), req.GetZone(), req.GetInstance())
httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Instance{}
return rsp, unm.Unmarshal(buf, rsp)
}
// GetEffectiveFirewalls returns effective firewalls applied to an interface of the instance.
func (c *instancesRESTClient) GetEffectiveFirewalls(ctx context.Context, req *computepb.GetEffectiveFirewallsInstanceRequest, opts ...gax.CallOption) (*computepb.InstancesGetEffectiveFirewallsResponse, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
jsonReq, err := m.Marshal(req)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/getEffectiveFirewalls", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req.GetNetworkInterface() != "" {
params.Add("networkInterface", fmt.Sprintf("%v", req.GetNetworkInterface()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.InstancesGetEffectiveFirewallsResponse{}
return rsp, unm.Unmarshal(buf, rsp)
}
// GetGuestAttributes returns the specified guest attributes entry.
func (c *instancesRESTClient) GetGuestAttributes(ctx context.Context, req *computepb.GetGuestAttributesInstanceRequest, opts ...gax.CallOption) (*computepb.GuestAttributes, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
jsonReq, err := m.Marshal(req)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/getGuestAttributes", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req != nil && req.QueryPath != nil {
params.Add("queryPath", fmt.Sprintf("%v", req.GetQueryPath()))
}
if req != nil && req.VariableKey != nil {
params.Add("variableKey", fmt.Sprintf("%v", req.GetVariableKey()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.GuestAttributes{}
return rsp, unm.Unmarshal(buf, rsp)
}
// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists.
func (c *instancesRESTClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyInstanceRequest, opts ...gax.CallOption) (*computepb.Policy, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
jsonReq, err := m.Marshal(req)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/getIamPolicy", req.GetProject(), req.GetZone(), req.GetResource())
params := url.Values{}
if req != nil && req.OptionsRequestedPolicyVersion != nil {
params.Add("optionsRequestedPolicyVersion", fmt.Sprintf("%v", req.GetOptionsRequestedPolicyVersion()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Policy{}
return rsp, unm.Unmarshal(buf, rsp)
}
// GetScreenshot returns the screenshot from the specified instance.
func (c *instancesRESTClient) GetScreenshot(ctx context.Context, req *computepb.GetScreenshotInstanceRequest, opts ...gax.CallOption) (*computepb.Screenshot, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
jsonReq, err := m.Marshal(req)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/screenshot", req.GetProject(), req.GetZone(), req.GetInstance())
httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Screenshot{}
return rsp, unm.Unmarshal(buf, rsp)
}
// GetSerialPortOutput returns the last 1 MB of serial port output from the specified instance.
func (c *instancesRESTClient) GetSerialPortOutput(ctx context.Context, req *computepb.GetSerialPortOutputInstanceRequest, opts ...gax.CallOption) (*computepb.SerialPortOutput, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
jsonReq, err := m.Marshal(req)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/serialPort", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req != nil && req.Port != nil {
params.Add("port", fmt.Sprintf("%v", req.GetPort()))
}
if req != nil && req.Start != nil {
params.Add("start", fmt.Sprintf("%v", req.GetStart()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.SerialPortOutput{}
return rsp, unm.Unmarshal(buf, rsp)
}
// GetShieldedInstanceIdentity returns the Shielded Instance Identity of an instance
func (c *instancesRESTClient) GetShieldedInstanceIdentity(ctx context.Context, req *computepb.GetShieldedInstanceIdentityInstanceRequest, opts ...gax.CallOption) (*computepb.ShieldedInstanceIdentity, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
jsonReq, err := m.Marshal(req)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/getShieldedInstanceIdentity", req.GetProject(), req.GetZone(), req.GetInstance())
httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.ShieldedInstanceIdentity{}
return rsp, unm.Unmarshal(buf, rsp)
}
// Insert creates an instance resource in the specified project using the data included in the request.
func (c *instancesRESTClient) Insert(ctx context.Context, req *computepb.InsertInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetInstanceResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances", req.GetProject(), req.GetZone())
params := url.Values{}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
if req != nil && req.SourceInstanceTemplate != nil {
params.Add("sourceInstanceTemplate", fmt.Sprintf("%v", req.GetSourceInstanceTemplate()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// List retrieves the list of instances contained within the specified zone.
func (c *instancesRESTClient) List(ctx context.Context, req *computepb.ListInstancesRequest, opts ...gax.CallOption) (*computepb.InstanceList, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
jsonReq, err := m.Marshal(req)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances", req.GetProject(), req.GetZone())
params := url.Values{}
if req != nil && req.Filter != nil {
params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
}
if req != nil && req.MaxResults != nil {
params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults()))
}
if req != nil && req.OrderBy != nil {
params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy()))
}
if req != nil && req.PageToken != nil {
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
}
if req != nil && req.ReturnPartialSuccess != nil {
params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.InstanceList{}
return rsp, unm.Unmarshal(buf, rsp)
}
// ListReferrers retrieves a list of resources that refer to the VM instance specified in the request. For example, if the VM instance is part of a managed or unmanaged instance group, the referrers list includes the instance group. For more information, read Viewing referrers to VM instances.
func (c *instancesRESTClient) ListReferrers(ctx context.Context, req *computepb.ListReferrersInstancesRequest, opts ...gax.CallOption) (*computepb.InstanceListReferrers, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
jsonReq, err := m.Marshal(req)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/referrers", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req != nil && req.Filter != nil {
params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
}
if req != nil && req.MaxResults != nil {
params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults()))
}
if req != nil && req.OrderBy != nil {
params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy()))
}
if req != nil && req.PageToken != nil {
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
}
if req != nil && req.ReturnPartialSuccess != nil {
params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.InstanceListReferrers{}
return rsp, unm.Unmarshal(buf, rsp)
}
// RemoveResourcePolicies removes resource policies from an instance.
func (c *instancesRESTClient) RemoveResourcePolicies(ctx context.Context, req *computepb.RemoveResourcePoliciesInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetInstancesRemoveResourcePoliciesRequestResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/removeResourcePolicies", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// Reset performs a reset on the instance. This is a hard reset the VM does not do a graceful shutdown. For more information, see Resetting an instance.
func (c *instancesRESTClient) Reset(ctx context.Context, req *computepb.ResetInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
jsonReq, err := m.Marshal(req)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/reset", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// SetDeletionProtection sets deletion protection on the instance.
func (c *instancesRESTClient) SetDeletionProtection(ctx context.Context, req *computepb.SetDeletionProtectionInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
jsonReq, err := m.Marshal(req)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/setDeletionProtection", req.GetProject(), req.GetZone(), req.GetResource())
params := url.Values{}
if req != nil && req.DeletionProtection != nil {
params.Add("deletionProtection", fmt.Sprintf("%v", req.GetDeletionProtection()))
}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// SetDiskAutoDelete sets the auto-delete flag for a disk attached to an instance.
func (c *instancesRESTClient) SetDiskAutoDelete(ctx context.Context, req *computepb.SetDiskAutoDeleteInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
jsonReq, err := m.Marshal(req)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/setDiskAutoDelete", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req.GetAutoDelete() {
params.Add("autoDelete", fmt.Sprintf("%v", req.GetAutoDelete()))
}
if req.GetDeviceName() != "" {
params.Add("deviceName", fmt.Sprintf("%v", req.GetDeviceName()))
}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy.
func (c *instancesRESTClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyInstanceRequest, opts ...gax.CallOption) (*computepb.Policy, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetZoneSetPolicyRequestResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/setIamPolicy", req.GetProject(), req.GetZone(), req.GetResource())
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Policy{}
return rsp, unm.Unmarshal(buf, rsp)
}
// SetLabels sets labels on an instance. To learn more about labels, read the Labeling Resources documentation.
func (c *instancesRESTClient) SetLabels(ctx context.Context, req *computepb.SetLabelsInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetInstancesSetLabelsRequestResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/setLabels", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// SetMachineResources changes the number and/or type of accelerator for a stopped instance to the values specified in the request.
func (c *instancesRESTClient) SetMachineResources(ctx context.Context, req *computepb.SetMachineResourcesInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetInstancesSetMachineResourcesRequestResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/setMachineResources", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// SetMachineType changes the machine type for a stopped instance to the machine type specified in the request.
func (c *instancesRESTClient) SetMachineType(ctx context.Context, req *computepb.SetMachineTypeInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetInstancesSetMachineTypeRequestResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/setMachineType", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// SetMetadata sets metadata for the specified instance to the data included in the request.
func (c *instancesRESTClient) SetMetadata(ctx context.Context, req *computepb.SetMetadataInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetMetadataResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/setMetadata", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// SetMinCpuPlatform changes the minimum CPU platform that this instance should use. This method can only be called on a stopped instance. For more information, read Specifying a Minimum CPU Platform.
func (c *instancesRESTClient) SetMinCpuPlatform(ctx context.Context, req *computepb.SetMinCpuPlatformInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetInstancesSetMinCpuPlatformRequestResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/setMinCpuPlatform", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// SetScheduling sets an instance’s scheduling options. You can only call this method on a stopped instance, that is, a VM instance that is in a TERMINATED state. See Instance Life Cycle for more information on the possible instance states.
func (c *instancesRESTClient) SetScheduling(ctx context.Context, req *computepb.SetSchedulingInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetSchedulingResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/setScheduling", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// SetServiceAccount sets the service account on the instance. For more information, read Changing the service account and access scopes for an instance.
func (c *instancesRESTClient) SetServiceAccount(ctx context.Context, req *computepb.SetServiceAccountInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetInstancesSetServiceAccountRequestResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/setServiceAccount", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// SetShieldedInstanceIntegrityPolicy sets the Shielded Instance integrity policy for an instance. You can only use this method on a running instance. This method supports PATCH semantics and uses the JSON merge patch format and processing rules.
func (c *instancesRESTClient) SetShieldedInstanceIntegrityPolicy(ctx context.Context, req *computepb.SetShieldedInstanceIntegrityPolicyInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetShieldedInstanceIntegrityPolicyResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/setShieldedInstanceIntegrityPolicy", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// SetTags sets network tags for the specified instance to the data included in the request.
func (c *instancesRESTClient) SetTags(ctx context.Context, req *computepb.SetTagsInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetTagsResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/setTags", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// SimulateMaintenanceEvent simulates a maintenance event on the instance.
func (c *instancesRESTClient) SimulateMaintenanceEvent(ctx context.Context, req *computepb.SimulateMaintenanceEventInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
jsonReq, err := m.Marshal(req)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/simulateMaintenanceEvent", req.GetProject(), req.GetZone(), req.GetInstance())
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// Start starts an instance that was stopped using the instances().stop method. For more information, see Restart an instance.
func (c *instancesRESTClient) Start(ctx context.Context, req *computepb.StartInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
jsonReq, err := m.Marshal(req)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/start", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// StartWithEncryptionKey starts an instance that was stopped using the instances().stop method. For more information, see Restart an instance.
func (c *instancesRESTClient) StartWithEncryptionKey(ctx context.Context, req *computepb.StartWithEncryptionKeyInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetInstancesStartWithEncryptionKeyRequestResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/startWithEncryptionKey", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// Stop stops a running instance, shutting it down cleanly, and allows you to restart the instance at a later time. Stopped instances do not incur VM usage charges while they are stopped. However, resources that the VM is using, such as persistent disks and static IP addresses, will continue to be charged until they are deleted. For more information, see Stopping an instance.
func (c *instancesRESTClient) Stop(ctx context.Context, req *computepb.StopInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
jsonReq, err := m.Marshal(req)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/stop", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// TestIamPermissions returns permissions that a caller has on the specified resource.
func (c *instancesRESTClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsInstanceRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetTestPermissionsRequestResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/testIamPermissions", req.GetProject(), req.GetZone(), req.GetResource())
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.TestPermissionsResponse{}
return rsp, unm.Unmarshal(buf, rsp)
}
// Update updates an instance only if the necessary resources are available. This method can update only a specific set of instance properties. See Updating a running instance for a list of updatable instance properties.
func (c *instancesRESTClient) Update(ctx context.Context, req *computepb.UpdateInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetInstanceResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("")
params := url.Values{}
if req.GetInstance() != "" {
params.Add("instance", fmt.Sprintf("%v", req.GetInstance()))
}
if req != nil && req.MinimalAction != nil {
params.Add("minimalAction", fmt.Sprintf("%v", req.GetMinimalAction()))
}
if req != nil && req.MostDisruptiveAllowedAction != nil {
params.Add("mostDisruptiveAllowedAction", fmt.Sprintf("%v", req.GetMostDisruptiveAllowedAction()))
}
if req.GetProject() != "" {
params.Add("project", fmt.Sprintf("%v", req.GetProject()))
}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
if req.GetZone() != "" {
params.Add("zone", fmt.Sprintf("%v", req.GetZone()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("PUT", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// UpdateAccessConfig updates the specified access config from an instance’s network interface with the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules.
func (c *instancesRESTClient) UpdateAccessConfig(ctx context.Context, req *computepb.UpdateAccessConfigInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetAccessConfigResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/updateAccessConfig", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req.GetNetworkInterface() != "" {
params.Add("networkInterface", fmt.Sprintf("%v", req.GetNetworkInterface()))
}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// UpdateDisplayDevice updates the Display config for a VM instance. You can only use this method on a stopped VM instance. This method supports PATCH semantics and uses the JSON merge patch format and processing rules.
func (c *instancesRESTClient) UpdateDisplayDevice(ctx context.Context, req *computepb.UpdateDisplayDeviceInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetDisplayDeviceResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/updateDisplayDevice", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// UpdateNetworkInterface updates an instance’s network interface. This method can only update an interface’s alias IP range and attached network. See Modifying alias IP ranges for an existing instance for instructions on changing alias IP ranges. See Migrating a VM between networks for instructions on migrating an interface. This method follows PATCH semantics.
func (c *instancesRESTClient) UpdateNetworkInterface(ctx context.Context, req *computepb.UpdateNetworkInterfaceInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetNetworkInterfaceResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/updateNetworkInterface", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req.GetNetworkInterface() != "" {
params.Add("networkInterface", fmt.Sprintf("%v", req.GetNetworkInterface()))
}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}
// UpdateShieldedInstanceConfig updates the Shielded Instance config for an instance. You can only use this method on a stopped instance. This method supports PATCH semantics and uses the JSON merge patch format and processing rules.
func (c *instancesRESTClient) UpdateShieldedInstanceConfig(ctx context.Context, req *computepb.UpdateShieldedInstanceConfigInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetShieldedInstanceConfigResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/updateShieldedInstanceConfig", req.GetProject(), req.GetZone(), req.GetInstance())
params := url.Values{}
if req != nil && req.RequestId != nil {
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
}
baseUrl.RawQuery = params.Encode()
httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return nil, err
}
httpReq = httpReq.WithContext(ctx)
// Set the headers
for k, v := range c.xGoogMetadata {
httpReq.Header[k] = v
}
httpReq.Header["Content-Type"] = []string{"application/json"}
httpRsp, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
defer httpRsp.Body.Close()
if httpRsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(httpRsp.Status)
}
buf, err := ioutil.ReadAll(httpRsp.Body)
if err != nil {
return nil, err
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
rsp := &computepb.Operation{}
return rsp, unm.Unmarshal(buf, rsp)
}