blob: 03d1aa434dae60b2b246bf4b2ea162ea3b580630 [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 newProjectsClientHook clientHook
// ProjectsCallOptions contains the retry settings for each method of ProjectsClient.
type ProjectsCallOptions struct {
DisableXpnHost []gax.CallOption
DisableXpnResource []gax.CallOption
EnableXpnHost []gax.CallOption
EnableXpnResource []gax.CallOption
Get []gax.CallOption
GetXpnHost []gax.CallOption
GetXpnResources []gax.CallOption
ListXpnHosts []gax.CallOption
MoveDisk []gax.CallOption
MoveInstance []gax.CallOption
SetCommonInstanceMetadata []gax.CallOption
SetDefaultNetworkTier []gax.CallOption
SetUsageExportBucket []gax.CallOption
}
// internalProjectsClient is an interface that defines the methods availaible from Google Compute Engine API.
type internalProjectsClient interface {
Close() error
setGoogleClientInfo(...string)
Connection() *grpc.ClientConn
DisableXpnHost(context.Context, *computepb.DisableXpnHostProjectRequest, ...gax.CallOption) (*computepb.Operation, error)
DisableXpnResource(context.Context, *computepb.DisableXpnResourceProjectRequest, ...gax.CallOption) (*computepb.Operation, error)
EnableXpnHost(context.Context, *computepb.EnableXpnHostProjectRequest, ...gax.CallOption) (*computepb.Operation, error)
EnableXpnResource(context.Context, *computepb.EnableXpnResourceProjectRequest, ...gax.CallOption) (*computepb.Operation, error)
Get(context.Context, *computepb.GetProjectRequest, ...gax.CallOption) (*computepb.Project, error)
GetXpnHost(context.Context, *computepb.GetXpnHostProjectRequest, ...gax.CallOption) (*computepb.Project, error)
GetXpnResources(context.Context, *computepb.GetXpnResourcesProjectsRequest, ...gax.CallOption) (*computepb.ProjectsGetXpnResources, error)
ListXpnHosts(context.Context, *computepb.ListXpnHostsProjectsRequest, ...gax.CallOption) (*computepb.XpnHostList, error)
MoveDisk(context.Context, *computepb.MoveDiskProjectRequest, ...gax.CallOption) (*computepb.Operation, error)
MoveInstance(context.Context, *computepb.MoveInstanceProjectRequest, ...gax.CallOption) (*computepb.Operation, error)
SetCommonInstanceMetadata(context.Context, *computepb.SetCommonInstanceMetadataProjectRequest, ...gax.CallOption) (*computepb.Operation, error)
SetDefaultNetworkTier(context.Context, *computepb.SetDefaultNetworkTierProjectRequest, ...gax.CallOption) (*computepb.Operation, error)
SetUsageExportBucket(context.Context, *computepb.SetUsageExportBucketProjectRequest, ...gax.CallOption) (*computepb.Operation, error)
}
// ProjectsClient 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 Projects API.
type ProjectsClient struct {
// The internal transport-dependent client.
internalClient internalProjectsClient
// The call options for this service.
CallOptions *ProjectsCallOptions
}
// 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 *ProjectsClient) 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 *ProjectsClient) setGoogleClientInfo(keyval ...string) {
c.internalClient.setGoogleClientInfo(keyval...)
}
// Connection returns a connection to the API service.
//
// Deprecated.
func (c *ProjectsClient) Connection() *grpc.ClientConn {
return c.internalClient.Connection()
}
// DisableXpnHost disable this project as a shared VPC host project.
func (c *ProjectsClient) DisableXpnHost(ctx context.Context, req *computepb.DisableXpnHostProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.DisableXpnHost(ctx, req, opts...)
}
// DisableXpnResource disable a service resource (also known as service project) associated with this host project.
func (c *ProjectsClient) DisableXpnResource(ctx context.Context, req *computepb.DisableXpnResourceProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.DisableXpnResource(ctx, req, opts...)
}
// EnableXpnHost enable this project as a shared VPC host project.
func (c *ProjectsClient) EnableXpnHost(ctx context.Context, req *computepb.EnableXpnHostProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.EnableXpnHost(ctx, req, opts...)
}
// EnableXpnResource enable service resource (a.k.a service project) for a host project, so that subnets in the host project can be used by instances in the service project.
func (c *ProjectsClient) EnableXpnResource(ctx context.Context, req *computepb.EnableXpnResourceProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.EnableXpnResource(ctx, req, opts...)
}
// Get returns the specified Project resource.
func (c *ProjectsClient) Get(ctx context.Context, req *computepb.GetProjectRequest, opts ...gax.CallOption) (*computepb.Project, error) {
return c.internalClient.Get(ctx, req, opts...)
}
// GetXpnHost gets the shared VPC host project that this project links to. May be empty if no link exists.
func (c *ProjectsClient) GetXpnHost(ctx context.Context, req *computepb.GetXpnHostProjectRequest, opts ...gax.CallOption) (*computepb.Project, error) {
return c.internalClient.GetXpnHost(ctx, req, opts...)
}
// GetXpnResources gets service resources (a.k.a service project) associated with this host project.
func (c *ProjectsClient) GetXpnResources(ctx context.Context, req *computepb.GetXpnResourcesProjectsRequest, opts ...gax.CallOption) (*computepb.ProjectsGetXpnResources, error) {
return c.internalClient.GetXpnResources(ctx, req, opts...)
}
// ListXpnHosts lists all shared VPC host projects visible to the user in an organization.
func (c *ProjectsClient) ListXpnHosts(ctx context.Context, req *computepb.ListXpnHostsProjectsRequest, opts ...gax.CallOption) (*computepb.XpnHostList, error) {
return c.internalClient.ListXpnHosts(ctx, req, opts...)
}
// MoveDisk moves a persistent disk from one zone to another.
func (c *ProjectsClient) MoveDisk(ctx context.Context, req *computepb.MoveDiskProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.MoveDisk(ctx, req, opts...)
}
// MoveInstance moves an instance and its attached persistent disks from one zone to another.
func (c *ProjectsClient) MoveInstance(ctx context.Context, req *computepb.MoveInstanceProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.MoveInstance(ctx, req, opts...)
}
// SetCommonInstanceMetadata sets metadata common to all instances within the specified project using the data included in the request.
func (c *ProjectsClient) SetCommonInstanceMetadata(ctx context.Context, req *computepb.SetCommonInstanceMetadataProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.SetCommonInstanceMetadata(ctx, req, opts...)
}
// SetDefaultNetworkTier sets the default network tier of the project. The default network tier is used when an address/forwardingRule/instance is created without specifying the network tier field.
func (c *ProjectsClient) SetDefaultNetworkTier(ctx context.Context, req *computepb.SetDefaultNetworkTierProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.SetDefaultNetworkTier(ctx, req, opts...)
}
// SetUsageExportBucket enables the usage export feature and sets the usage export bucket where reports are stored. If you provide an empty request body using this method, the usage export feature will be disabled.
func (c *ProjectsClient) SetUsageExportBucket(ctx context.Context, req *computepb.SetUsageExportBucketProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
return c.internalClient.SetUsageExportBucket(ctx, req, opts...)
}
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
type projectsRESTClient 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
}
// NewProjectsRESTClient creates a new projects rest client.
//
// The Projects API.
func NewProjectsRESTClient(ctx context.Context, opts ...option.ClientOption) (*ProjectsClient, error) {
clientOpts := append(defaultProjectsRESTClientOptions(), opts...)
httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
if err != nil {
return nil, err
}
c := &projectsRESTClient{
endpoint: endpoint,
httpClient: httpClient,
}
c.setGoogleClientInfo()
return &ProjectsClient{internalClient: c, CallOptions: &ProjectsCallOptions{}}, nil
}
func defaultProjectsRESTClientOptions() []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 *projectsRESTClient) 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 *projectsRESTClient) 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 *projectsRESTClient) Connection() *grpc.ClientConn {
return nil
}
// DisableXpnHost disable this project as a shared VPC host project.
func (c *projectsRESTClient) DisableXpnHost(ctx context.Context, req *computepb.DisableXpnHostProjectRequest, 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/disableXpnHost", req.GetProject())
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)
}
// DisableXpnResource disable a service resource (also known as service project) associated with this host project.
func (c *projectsRESTClient) DisableXpnResource(ctx context.Context, req *computepb.DisableXpnResourceProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetProjectsDisableXpnResourceRequestResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/disableXpnResource", req.GetProject())
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)
}
// EnableXpnHost enable this project as a shared VPC host project.
func (c *projectsRESTClient) EnableXpnHost(ctx context.Context, req *computepb.EnableXpnHostProjectRequest, 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/enableXpnHost", req.GetProject())
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)
}
// EnableXpnResource enable service resource (a.k.a service project) for a host project, so that subnets in the host project can be used by instances in the service project.
func (c *projectsRESTClient) EnableXpnResource(ctx context.Context, req *computepb.EnableXpnResourceProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetProjectsEnableXpnResourceRequestResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/enableXpnResource", req.GetProject())
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)
}
// Get returns the specified Project resource.
func (c *projectsRESTClient) Get(ctx context.Context, req *computepb.GetProjectRequest, opts ...gax.CallOption) (*computepb.Project, 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", req.GetProject())
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.Project{}
return rsp, unm.Unmarshal(buf, rsp)
}
// GetXpnHost gets the shared VPC host project that this project links to. May be empty if no link exists.
func (c *projectsRESTClient) GetXpnHost(ctx context.Context, req *computepb.GetXpnHostProjectRequest, opts ...gax.CallOption) (*computepb.Project, 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/getXpnHost", req.GetProject())
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.Project{}
return rsp, unm.Unmarshal(buf, rsp)
}
// GetXpnResources gets service resources (a.k.a service project) associated with this host project.
func (c *projectsRESTClient) GetXpnResources(ctx context.Context, req *computepb.GetXpnResourcesProjectsRequest, opts ...gax.CallOption) (*computepb.ProjectsGetXpnResources, 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/getXpnResources", req.GetProject())
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.ProjectsGetXpnResources{}
return rsp, unm.Unmarshal(buf, rsp)
}
// ListXpnHosts lists all shared VPC host projects visible to the user in an organization.
func (c *projectsRESTClient) ListXpnHosts(ctx context.Context, req *computepb.ListXpnHostsProjectsRequest, opts ...gax.CallOption) (*computepb.XpnHostList, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetProjectsListXpnHostsRequestResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/listXpnHosts", req.GetProject())
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("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.XpnHostList{}
return rsp, unm.Unmarshal(buf, rsp)
}
// MoveDisk moves a persistent disk from one zone to another.
func (c *projectsRESTClient) MoveDisk(ctx context.Context, req *computepb.MoveDiskProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetDiskMoveRequestResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/moveDisk", req.GetProject())
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)
}
// MoveInstance moves an instance and its attached persistent disks from one zone to another.
func (c *projectsRESTClient) MoveInstance(ctx context.Context, req *computepb.MoveInstanceProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetInstanceMoveRequestResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/moveInstance", req.GetProject())
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)
}
// SetCommonInstanceMetadata sets metadata common to all instances within the specified project using the data included in the request.
func (c *projectsRESTClient) SetCommonInstanceMetadata(ctx context.Context, req *computepb.SetCommonInstanceMetadataProjectRequest, 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/setCommonInstanceMetadata", req.GetProject())
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)
}
// SetDefaultNetworkTier sets the default network tier of the project. The default network tier is used when an address/forwardingRule/instance is created without specifying the network tier field.
func (c *projectsRESTClient) SetDefaultNetworkTier(ctx context.Context, req *computepb.SetDefaultNetworkTierProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetProjectsSetDefaultNetworkTierRequestResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/setDefaultNetworkTier", req.GetProject())
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)
}
// SetUsageExportBucket enables the usage export feature and sets the usage export bucket where reports are stored. If you provide an empty request body using this method, the usage export feature will be disabled.
func (c *projectsRESTClient) SetUsageExportBucket(ctx context.Context, req *computepb.SetUsageExportBucketProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) {
m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true}
body := req.GetUsageExportLocationResource()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, _ := url.Parse(c.endpoint)
baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/setUsageExportBucket", req.GetProject())
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)
}