Skip to content

Commit

Permalink
fix(compute): remove proto3_optional from parent_id (#260)
Browse files Browse the repository at this point in the history
- [ ] Regenerate this pull request now.

Source-Link: googleapis/googleapis@fd16b6a

Source-Link: googleapis/googleapis-gen@d935b98
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZDkzNWI5ODQ3YTFiNzA4YWI0ZTY5NjMyMGJhNjBjZTAzNDFjNWQ3YSJ9


Source-Link: googleapis/googleapis@4bb6fd6

Source-Link: googleapis/googleapis-gen@c7d0653
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYzdkMDY1MzNiZTZlMjQ3MGUzNmI5ZjM1MWFlNGZmNDc5YTQ3ZGM1MyJ9


PiperOrigin-RevId: 440970084

Source-Link: googleapis/googleapis@5e0a3d5

Source-Link: googleapis/googleapis-gen@b0c628a
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYjBjNjI4YTNmYWRlNzY4ZjIyNWQ3Njk5Mjc5MWVhMWJhMmE4ODFiZSJ9

fix(compute): replace missing REQUIRED for parent_id
feat: add new methods for long running operations
fix(deps): require google-api-core>=2.7.0
chore: Use gapic-generator-python 0.65.0
  • Loading branch information
gcf-owl-bot[bot] authored Apr 14, 2022
1 parent 3dd1e81 commit 5e05609
Show file tree
Hide file tree
Showing 343 changed files with 203,231 additions and 47,437 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from collections import OrderedDict
import os
import re
from typing import Dict, Optional, Sequence, Tuple, Type, Union
from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union
import pkg_resources

from google.api_core import client_options as client_options_lib
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def __init__(
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
be used for service account credentials.
"""

# Save the hostname. Default to port 443 (HTTPS) if none is specified.
if ":" not in host:
host += ":443"
Expand Down Expand Up @@ -180,5 +181,9 @@ def list(
]:
raise NotImplementedError()

@property
def kind(self) -> str:
raise NotImplementedError()


__all__ = ("AcceleratorTypesTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,10 @@ def list(
# In C++ this would require a dynamic_cast
return stub # type: ignore

@property
def kind(self) -> str:
return "rest"

def close(self):
self._session.close()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
# limitations under the License.
#
from collections import OrderedDict
import functools
import os
import re
from typing import Dict, Optional, Sequence, Tuple, Type, Union
from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union
import pkg_resources

from google.api_core import client_options as client_options_lib
from google.api_core import exceptions as core_exceptions
from google.api_core import extended_operation
from google.api_core import gapic_v1
from google.api_core import retry as retries
from google.auth import credentials as ga_credentials # type: ignore
Expand All @@ -34,6 +36,7 @@
except AttributeError: # pragma: NO COVER
OptionalRetry = Union[retries.Retry, object] # type: ignore

from google.api_core import extended_operation # type: ignore
from google.cloud.compute_v1.services.addresses import pagers
from google.cloud.compute_v1.types import compute
from .transports.base import AddressesTransport, DEFAULT_CLIENT_INFO
Expand Down Expand Up @@ -521,22 +524,9 @@ def delete_unary(
sent along with the request as metadata.
Returns:
google.cloud.compute_v1.types.Operation:
Represents an Operation resource. Google Compute Engine
has three Operation resources: \*
[Global](/compute/docs/reference/rest/v1/globalOperations)
\*
[Regional](/compute/docs/reference/rest/v1/regionOperations)
\*
[Zonal](/compute/docs/reference/rest/v1/zoneOperations)
You can use an operation resource to manage asynchronous
API requests. For more information, read Handling API
responses. Operations can be global, regional or zonal.
- For global operations, use the globalOperations
resource. - For regional operations, use the
regionOperations resource. - For zonal operations, use
the zonalOperations resource. For more information, read
Global, Regional, and Zonal Resources.
google.api_core.extended_operation.ExtendedOperation:
An object representing a extended
long-running operation.
"""
# Create or coerce a protobuf request object.
Expand Down Expand Up @@ -579,6 +569,118 @@ def delete_unary(
# Done; return the response.
return response

def delete(
self,
request: Union[compute.DeleteAddressRequest, dict] = None,
*,
project: str = None,
region: str = None,
address: str = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> extended_operation.ExtendedOperation:
r"""Deletes the specified address resource.
Args:
request (Union[google.cloud.compute_v1.types.DeleteAddressRequest, dict]):
The request object. A request message for
Addresses.Delete. See the method description for
details.
project (str):
Project ID for this request.
This corresponds to the ``project`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
region (str):
Name of the region for this request.
This corresponds to the ``region`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
address (str):
Name of the address resource to
delete.
This corresponds to the ``address`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
retry (google.api_core.retry.Retry): Designation of what errors, if any,
should be retried.
timeout (float): The timeout for this request.
metadata (Sequence[Tuple[str, str]]): Strings which should be
sent along with the request as metadata.
Returns:
google.api_core.extended_operation.ExtendedOperation:
An object representing a extended
long-running operation.
"""
# Create or coerce a protobuf request object.
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([project, region, address])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
)

# Minor optimization to avoid making a copy if the user passes
# in a compute.DeleteAddressRequest.
# There's no risk of modifying the input as we've already verified
# there are no flattened fields.
if not isinstance(request, compute.DeleteAddressRequest):
request = compute.DeleteAddressRequest(request)
# If we have keyword arguments corresponding to fields on the
# request, apply these.
if project is not None:
request.project = project
if region is not None:
request.region = region
if address is not None:
request.address = address

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = self._transport._wrapped_methods[self._transport.delete]

# Send the request.
response = rpc(
request,
retry=retry,
timeout=timeout,
metadata=metadata,
)

operation_service = self._transport._region_operations_client
operation_request = compute.GetRegionOperationRequest()
operation_request.project = request.project
operation_request.region = request.region
operation_request.operation = response.name

get_operation = functools.partial(operation_service.get, operation_request)
# Cancel is not part of extended operations yet.
cancel_operation = lambda: None

# Note: this class is an implementation detail to provide a uniform
# set of names for certain fields in the extended operation proto message.
# See google.api_core.extended_operation.ExtendedOperation for details
# on these properties and the expected interface.
class _CustomOperation(extended_operation.ExtendedOperation):
@property
def error_message(self):
return self._extended_operation.http_error_message

@property
def error_code(self):
return self._extended_operation.http_error_status_code

response = _CustomOperation.make(get_operation, cancel_operation, response)

# Done; return the response.
return response

def get(
self,
request: Union[compute.GetAddressRequest, dict] = None,
Expand Down Expand Up @@ -711,22 +813,95 @@ def insert_unary(
sent along with the request as metadata.
Returns:
google.cloud.compute_v1.types.Operation:
Represents an Operation resource. Google Compute Engine
has three Operation resources: \*
[Global](/compute/docs/reference/rest/v1/globalOperations)
\*
[Regional](/compute/docs/reference/rest/v1/regionOperations)
\*
[Zonal](/compute/docs/reference/rest/v1/zoneOperations)
You can use an operation resource to manage asynchronous
API requests. For more information, read Handling API
responses. Operations can be global, regional or zonal.
- For global operations, use the globalOperations
resource. - For regional operations, use the
regionOperations resource. - For zonal operations, use
the zonalOperations resource. For more information, read
Global, Regional, and Zonal Resources.
google.api_core.extended_operation.ExtendedOperation:
An object representing a extended
long-running operation.
"""
# Create or coerce a protobuf request object.
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([project, region, address_resource])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
)

# Minor optimization to avoid making a copy if the user passes
# in a compute.InsertAddressRequest.
# There's no risk of modifying the input as we've already verified
# there are no flattened fields.
if not isinstance(request, compute.InsertAddressRequest):
request = compute.InsertAddressRequest(request)
# If we have keyword arguments corresponding to fields on the
# request, apply these.
if project is not None:
request.project = project
if region is not None:
request.region = region
if address_resource is not None:
request.address_resource = address_resource

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = self._transport._wrapped_methods[self._transport.insert]

# Send the request.
response = rpc(
request,
retry=retry,
timeout=timeout,
metadata=metadata,
)

# Done; return the response.
return response

def insert(
self,
request: Union[compute.InsertAddressRequest, dict] = None,
*,
project: str = None,
region: str = None,
address_resource: compute.Address = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> extended_operation.ExtendedOperation:
r"""Creates an address resource in the specified project
by using the data included in the request.
Args:
request (Union[google.cloud.compute_v1.types.InsertAddressRequest, dict]):
The request object. A request message for
Addresses.Insert. See the method description for
details.
project (str):
Project ID for this request.
This corresponds to the ``project`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
region (str):
Name of the region for this request.
This corresponds to the ``region`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
address_resource (google.cloud.compute_v1.types.Address):
The body resource for this request
This corresponds to the ``address_resource`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
retry (google.api_core.retry.Retry): Designation of what errors, if any,
should be retried.
timeout (float): The timeout for this request.
metadata (Sequence[Tuple[str, str]]): Strings which should be
sent along with the request as metadata.
Returns:
google.api_core.extended_operation.ExtendedOperation:
An object representing a extended
long-running operation.
"""
# Create or coerce a protobuf request object.
Expand Down Expand Up @@ -766,6 +941,31 @@ def insert_unary(
metadata=metadata,
)

operation_service = self._transport._region_operations_client
operation_request = compute.GetRegionOperationRequest()
operation_request.project = request.project
operation_request.region = request.region
operation_request.operation = response.name

get_operation = functools.partial(operation_service.get, operation_request)
# Cancel is not part of extended operations yet.
cancel_operation = lambda: None

# Note: this class is an implementation detail to provide a uniform
# set of names for certain fields in the extended operation proto message.
# See google.api_core.extended_operation.ExtendedOperation for details
# on these properties and the expected interface.
class _CustomOperation(extended_operation.ExtendedOperation):
@property
def error_message(self):
return self._extended_operation.http_error_message

@property
def error_code(self):
return self._extended_operation.http_error_status_code

response = _CustomOperation.make(get_operation, cancel_operation, response)

# Done; return the response.
return response

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from google.oauth2 import service_account # type: ignore

from google.cloud.compute_v1.types import compute
from google.cloud.compute_v1.services import region_operations

try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down Expand Up @@ -83,6 +84,8 @@ def __init__(
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
be used for service account credentials.
"""
self._extended_operations_services: Dict[str, Any] = {}

# Save the hostname. Default to port 443 (HTTPS) if none is specified.
if ":" not in host:
host += ":443"
Expand Down Expand Up @@ -203,5 +206,21 @@ def list(
]:
raise NotImplementedError()

@property
def kind(self) -> str:
raise NotImplementedError()

@property
def _region_operations_client(self) -> region_operations.RegionOperationsClient:
ex_op_service = self._extended_operations_services.get("region_operations")
if not ex_op_service:
ex_op_service = region_operations.RegionOperationsClient(
credentials=self._credentials,
transport=self.kind,
)
self._extended_operations_services["region_operations"] = ex_op_service

return ex_op_service


__all__ = ("AddressesTransport",)
Loading

0 comments on commit 5e05609

Please sign in to comment.