Skip to content

Commit 5e05609

Browse files
fix(compute): remove proto3_optional from parent_id (googleapis#260)
- [ ] Regenerate this pull request now. Source-Link: googleapis/googleapis@fd16b6a Source-Link: https://github.com/googleapis/googleapis-gen/commit/d935b9847a1b708ab4e696320ba60ce0341c5d7a Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZDkzNWI5ODQ3YTFiNzA4YWI0ZTY5NjMyMGJhNjBjZTAzNDFjNWQ3YSJ9 Source-Link: googleapis/googleapis@4bb6fd6 Source-Link: https://github.com/googleapis/googleapis-gen/commit/c7d06533be6e2470e36b9f351ae4ff479a47dc53 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYzdkMDY1MzNiZTZlMjQ3MGUzNmI5ZjM1MWFlNGZmNDc5YTQ3ZGM1MyJ9 PiperOrigin-RevId: 440970084 Source-Link: googleapis/googleapis@5e0a3d5 Source-Link: https://github.com/googleapis/googleapis-gen/commit/b0c628a3fade768f225d76992791ea1ba2a881be 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
1 parent 3dd1e81 commit 5e05609

File tree

343 files changed

+203231
-47437
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

343 files changed

+203231
-47437
lines changed

packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from collections import OrderedDict
1717
import os
1818
import re
19-
from typing import Dict, Optional, Sequence, Tuple, Type, Union
19+
from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union
2020
import pkg_resources
2121

2222
from google.api_core import client_options as client_options_lib

packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/transports/base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def __init__(
8484
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
8585
be used for service account credentials.
8686
"""
87+
8788
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
8889
if ":" not in host:
8990
host += ":443"
@@ -180,5 +181,9 @@ def list(
180181
]:
181182
raise NotImplementedError()
182183

184+
@property
185+
def kind(self) -> str:
186+
raise NotImplementedError()
187+
183188

184189
__all__ = ("AcceleratorTypesTransport",)

packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/transports/rest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,10 @@ def list(
583583
# In C++ this would require a dynamic_cast
584584
return stub # type: ignore
585585

586+
@property
587+
def kind(self) -> str:
588+
return "rest"
589+
586590
def close(self):
587591
self._session.close()
588592

packages/google-cloud-compute/google/cloud/compute_v1/services/addresses/client.py

Lines changed: 233 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
# limitations under the License.
1515
#
1616
from collections import OrderedDict
17+
import functools
1718
import os
1819
import re
19-
from typing import Dict, Optional, Sequence, Tuple, Type, Union
20+
from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union
2021
import pkg_resources
2122

2223
from google.api_core import client_options as client_options_lib
2324
from google.api_core import exceptions as core_exceptions
25+
from google.api_core import extended_operation
2426
from google.api_core import gapic_v1
2527
from google.api_core import retry as retries
2628
from google.auth import credentials as ga_credentials # type: ignore
@@ -34,6 +36,7 @@
3436
except AttributeError: # pragma: NO COVER
3537
OptionalRetry = Union[retries.Retry, object] # type: ignore
3638

39+
from google.api_core import extended_operation # type: ignore
3740
from google.cloud.compute_v1.services.addresses import pagers
3841
from google.cloud.compute_v1.types import compute
3942
from .transports.base import AddressesTransport, DEFAULT_CLIENT_INFO
@@ -521,22 +524,9 @@ def delete_unary(
521524
sent along with the request as metadata.
522525
523526
Returns:
524-
google.cloud.compute_v1.types.Operation:
525-
Represents an Operation resource. Google Compute Engine
526-
has three Operation resources: \*
527-
[Global](/compute/docs/reference/rest/v1/globalOperations)
528-
\*
529-
[Regional](/compute/docs/reference/rest/v1/regionOperations)
530-
\*
531-
[Zonal](/compute/docs/reference/rest/v1/zoneOperations)
532-
You can use an operation resource to manage asynchronous
533-
API requests. For more information, read Handling API
534-
responses. Operations can be global, regional or zonal.
535-
- For global operations, use the globalOperations
536-
resource. - For regional operations, use the
537-
regionOperations resource. - For zonal operations, use
538-
the zonalOperations resource. For more information, read
539-
Global, Regional, and Zonal Resources.
527+
google.api_core.extended_operation.ExtendedOperation:
528+
An object representing a extended
529+
long-running operation.
540530
541531
"""
542532
# Create or coerce a protobuf request object.
@@ -579,6 +569,118 @@ def delete_unary(
579569
# Done; return the response.
580570
return response
581571

572+
def delete(
573+
self,
574+
request: Union[compute.DeleteAddressRequest, dict] = None,
575+
*,
576+
project: str = None,
577+
region: str = None,
578+
address: str = None,
579+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
580+
timeout: float = None,
581+
metadata: Sequence[Tuple[str, str]] = (),
582+
) -> extended_operation.ExtendedOperation:
583+
r"""Deletes the specified address resource.
584+
585+
Args:
586+
request (Union[google.cloud.compute_v1.types.DeleteAddressRequest, dict]):
587+
The request object. A request message for
588+
Addresses.Delete. See the method description for
589+
details.
590+
project (str):
591+
Project ID for this request.
592+
This corresponds to the ``project`` field
593+
on the ``request`` instance; if ``request`` is provided, this
594+
should not be set.
595+
region (str):
596+
Name of the region for this request.
597+
This corresponds to the ``region`` field
598+
on the ``request`` instance; if ``request`` is provided, this
599+
should not be set.
600+
address (str):
601+
Name of the address resource to
602+
delete.
603+
604+
This corresponds to the ``address`` field
605+
on the ``request`` instance; if ``request`` is provided, this
606+
should not be set.
607+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
608+
should be retried.
609+
timeout (float): The timeout for this request.
610+
metadata (Sequence[Tuple[str, str]]): Strings which should be
611+
sent along with the request as metadata.
612+
613+
Returns:
614+
google.api_core.extended_operation.ExtendedOperation:
615+
An object representing a extended
616+
long-running operation.
617+
618+
"""
619+
# Create or coerce a protobuf request object.
620+
# Quick check: If we got a request object, we should *not* have
621+
# gotten any keyword arguments that map to the request.
622+
has_flattened_params = any([project, region, address])
623+
if request is not None and has_flattened_params:
624+
raise ValueError(
625+
"If the `request` argument is set, then none of "
626+
"the individual field arguments should be set."
627+
)
628+
629+
# Minor optimization to avoid making a copy if the user passes
630+
# in a compute.DeleteAddressRequest.
631+
# There's no risk of modifying the input as we've already verified
632+
# there are no flattened fields.
633+
if not isinstance(request, compute.DeleteAddressRequest):
634+
request = compute.DeleteAddressRequest(request)
635+
# If we have keyword arguments corresponding to fields on the
636+
# request, apply these.
637+
if project is not None:
638+
request.project = project
639+
if region is not None:
640+
request.region = region
641+
if address is not None:
642+
request.address = address
643+
644+
# Wrap the RPC method; this adds retry and timeout information,
645+
# and friendly error handling.
646+
rpc = self._transport._wrapped_methods[self._transport.delete]
647+
648+
# Send the request.
649+
response = rpc(
650+
request,
651+
retry=retry,
652+
timeout=timeout,
653+
metadata=metadata,
654+
)
655+
656+
operation_service = self._transport._region_operations_client
657+
operation_request = compute.GetRegionOperationRequest()
658+
operation_request.project = request.project
659+
operation_request.region = request.region
660+
operation_request.operation = response.name
661+
662+
get_operation = functools.partial(operation_service.get, operation_request)
663+
# Cancel is not part of extended operations yet.
664+
cancel_operation = lambda: None
665+
666+
# Note: this class is an implementation detail to provide a uniform
667+
# set of names for certain fields in the extended operation proto message.
668+
# See google.api_core.extended_operation.ExtendedOperation for details
669+
# on these properties and the expected interface.
670+
class _CustomOperation(extended_operation.ExtendedOperation):
671+
@property
672+
def error_message(self):
673+
return self._extended_operation.http_error_message
674+
675+
@property
676+
def error_code(self):
677+
return self._extended_operation.http_error_status_code
678+
679+
response = _CustomOperation.make(get_operation, cancel_operation, response)
680+
681+
# Done; return the response.
682+
return response
683+
582684
def get(
583685
self,
584686
request: Union[compute.GetAddressRequest, dict] = None,
@@ -711,22 +813,95 @@ def insert_unary(
711813
sent along with the request as metadata.
712814
713815
Returns:
714-
google.cloud.compute_v1.types.Operation:
715-
Represents an Operation resource. Google Compute Engine
716-
has three Operation resources: \*
717-
[Global](/compute/docs/reference/rest/v1/globalOperations)
718-
\*
719-
[Regional](/compute/docs/reference/rest/v1/regionOperations)
720-
\*
721-
[Zonal](/compute/docs/reference/rest/v1/zoneOperations)
722-
You can use an operation resource to manage asynchronous
723-
API requests. For more information, read Handling API
724-
responses. Operations can be global, regional or zonal.
725-
- For global operations, use the globalOperations
726-
resource. - For regional operations, use the
727-
regionOperations resource. - For zonal operations, use
728-
the zonalOperations resource. For more information, read
729-
Global, Regional, and Zonal Resources.
816+
google.api_core.extended_operation.ExtendedOperation:
817+
An object representing a extended
818+
long-running operation.
819+
820+
"""
821+
# Create or coerce a protobuf request object.
822+
# Quick check: If we got a request object, we should *not* have
823+
# gotten any keyword arguments that map to the request.
824+
has_flattened_params = any([project, region, address_resource])
825+
if request is not None and has_flattened_params:
826+
raise ValueError(
827+
"If the `request` argument is set, then none of "
828+
"the individual field arguments should be set."
829+
)
830+
831+
# Minor optimization to avoid making a copy if the user passes
832+
# in a compute.InsertAddressRequest.
833+
# There's no risk of modifying the input as we've already verified
834+
# there are no flattened fields.
835+
if not isinstance(request, compute.InsertAddressRequest):
836+
request = compute.InsertAddressRequest(request)
837+
# If we have keyword arguments corresponding to fields on the
838+
# request, apply these.
839+
if project is not None:
840+
request.project = project
841+
if region is not None:
842+
request.region = region
843+
if address_resource is not None:
844+
request.address_resource = address_resource
845+
846+
# Wrap the RPC method; this adds retry and timeout information,
847+
# and friendly error handling.
848+
rpc = self._transport._wrapped_methods[self._transport.insert]
849+
850+
# Send the request.
851+
response = rpc(
852+
request,
853+
retry=retry,
854+
timeout=timeout,
855+
metadata=metadata,
856+
)
857+
858+
# Done; return the response.
859+
return response
860+
861+
def insert(
862+
self,
863+
request: Union[compute.InsertAddressRequest, dict] = None,
864+
*,
865+
project: str = None,
866+
region: str = None,
867+
address_resource: compute.Address = None,
868+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
869+
timeout: float = None,
870+
metadata: Sequence[Tuple[str, str]] = (),
871+
) -> extended_operation.ExtendedOperation:
872+
r"""Creates an address resource in the specified project
873+
by using the data included in the request.
874+
875+
Args:
876+
request (Union[google.cloud.compute_v1.types.InsertAddressRequest, dict]):
877+
The request object. A request message for
878+
Addresses.Insert. See the method description for
879+
details.
880+
project (str):
881+
Project ID for this request.
882+
This corresponds to the ``project`` field
883+
on the ``request`` instance; if ``request`` is provided, this
884+
should not be set.
885+
region (str):
886+
Name of the region for this request.
887+
This corresponds to the ``region`` field
888+
on the ``request`` instance; if ``request`` is provided, this
889+
should not be set.
890+
address_resource (google.cloud.compute_v1.types.Address):
891+
The body resource for this request
892+
This corresponds to the ``address_resource`` field
893+
on the ``request`` instance; if ``request`` is provided, this
894+
should not be set.
895+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
896+
should be retried.
897+
timeout (float): The timeout for this request.
898+
metadata (Sequence[Tuple[str, str]]): Strings which should be
899+
sent along with the request as metadata.
900+
901+
Returns:
902+
google.api_core.extended_operation.ExtendedOperation:
903+
An object representing a extended
904+
long-running operation.
730905
731906
"""
732907
# Create or coerce a protobuf request object.
@@ -766,6 +941,31 @@ def insert_unary(
766941
metadata=metadata,
767942
)
768943

944+
operation_service = self._transport._region_operations_client
945+
operation_request = compute.GetRegionOperationRequest()
946+
operation_request.project = request.project
947+
operation_request.region = request.region
948+
operation_request.operation = response.name
949+
950+
get_operation = functools.partial(operation_service.get, operation_request)
951+
# Cancel is not part of extended operations yet.
952+
cancel_operation = lambda: None
953+
954+
# Note: this class is an implementation detail to provide a uniform
955+
# set of names for certain fields in the extended operation proto message.
956+
# See google.api_core.extended_operation.ExtendedOperation for details
957+
# on these properties and the expected interface.
958+
class _CustomOperation(extended_operation.ExtendedOperation):
959+
@property
960+
def error_message(self):
961+
return self._extended_operation.http_error_message
962+
963+
@property
964+
def error_code(self):
965+
return self._extended_operation.http_error_status_code
966+
967+
response = _CustomOperation.make(get_operation, cancel_operation, response)
968+
769969
# Done; return the response.
770970
return response
771971

packages/google-cloud-compute/google/cloud/compute_v1/services/addresses/transports/base.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from google.oauth2 import service_account # type: ignore
2727

2828
from google.cloud.compute_v1.types import compute
29+
from google.cloud.compute_v1.services import region_operations
2930

3031
try:
3132
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
@@ -83,6 +84,8 @@ def __init__(
8384
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
8485
be used for service account credentials.
8586
"""
87+
self._extended_operations_services: Dict[str, Any] = {}
88+
8689
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
8790
if ":" not in host:
8891
host += ":443"
@@ -203,5 +206,21 @@ def list(
203206
]:
204207
raise NotImplementedError()
205208

209+
@property
210+
def kind(self) -> str:
211+
raise NotImplementedError()
212+
213+
@property
214+
def _region_operations_client(self) -> region_operations.RegionOperationsClient:
215+
ex_op_service = self._extended_operations_services.get("region_operations")
216+
if not ex_op_service:
217+
ex_op_service = region_operations.RegionOperationsClient(
218+
credentials=self._credentials,
219+
transport=self.kind,
220+
)
221+
self._extended_operations_services["region_operations"] = ex_op_service
222+
223+
return ex_op_service
224+
206225

207226
__all__ = ("AddressesTransport",)

0 commit comments

Comments
 (0)