Skip to content

Commit b28938a

Browse files
committed
feat: Add endpoind_id arg to Endpoint#create
1 parent c1e899d commit b28938a

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

google/cloud/aiplatform/models.py

+26
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ def network(self) -> Optional[str]:
198198
def create(
199199
cls,
200200
display_name: Optional[str] = None,
201+
endpoint_id: Optional[str] = None,
201202
description: Optional[str] = None,
202203
labels: Optional[Dict[str, str]] = None,
203204
metadata: Optional[Sequence[Tuple[str, str]]] = (),
@@ -215,6 +216,17 @@ def create(
215216
Optional. The user-defined name of the Endpoint.
216217
The name can be up to 128 characters long and can be consist
217218
of any UTF-8 characters.
219+
endpoint_id (str):
220+
Optional. The ID to use for endpoint, which will become
221+
the final component of the endpoint resource name. If
222+
not provided, Vertex AI will generate a value for this
223+
ID.
224+
225+
This value should be 1-10 characters, and valid
226+
characters are /[0-9]/. When using HTTP/JSON, this field
227+
is populated based on a query string argument, such as
228+
``?endpoint_id=12345``. This is the fallback for fields
229+
that are not included in either the URI or the body.
218230
project (str):
219231
Required. Project to retrieve endpoint from. If not set, project
220232
set in aiplatform.init will be used.
@@ -276,6 +288,7 @@ def create(
276288
return cls._create(
277289
api_client=api_client,
278290
display_name=display_name,
291+
endpoint_id=endpoint_id,
279292
project=project,
280293
location=location,
281294
description=description,
@@ -297,6 +310,7 @@ def _create(
297310
display_name: str,
298311
project: str,
299312
location: str,
313+
endpoint_id: Optional[str] = None,
300314
description: Optional[str] = None,
301315
labels: Optional[Dict[str, str]] = None,
302316
metadata: Optional[Sequence[Tuple[str, str]]] = (),
@@ -321,6 +335,17 @@ def _create(
321335
location (str):
322336
Required. Location to retrieve endpoint from. If not set, location
323337
set in aiplatform.init will be used.
338+
endpoint_id (str):
339+
Optional. The ID to use for endpoint, which will become
340+
the final component of the endpoint resource name. If
341+
not provided, Vertex AI will generate a value for this
342+
ID.
343+
344+
This value should be 1-10 characters, and valid
345+
characters are /[0-9]/. When using HTTP/JSON, this field
346+
is populated based on a query string argument, such as
347+
``?endpoint_id=12345``. This is the fallback for fields
348+
that are not included in either the URI or the body.
324349
description (str):
325350
Optional. The description of the Endpoint.
326351
labels (Dict[str, str]):
@@ -368,6 +393,7 @@ def _create(
368393
operation_future = api_client.create_endpoint(
369394
parent=parent,
370395
endpoint=gapic_endpoint,
396+
endpoint_id=endpoint_id,
371397
metadata=metadata,
372398
timeout=create_request_timeout,
373399
)

tests/unit/aiplatform/test_endpoints.py

+30
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ def test_init_aiplatform_with_encryption_key_name_and_create_endpoint(
547547
create_endpoint_mock.assert_called_once_with(
548548
parent=_TEST_PARENT,
549549
endpoint=expected_endpoint,
550+
endpoint_id=None,
550551
metadata=(),
551552
timeout=None,
552553
)
@@ -573,13 +574,39 @@ def test_create(self, create_endpoint_mock, sync):
573574
create_endpoint_mock.assert_called_once_with(
574575
parent=_TEST_PARENT,
575576
endpoint=expected_endpoint,
577+
endpoint_id=None,
576578
metadata=(),
577579
timeout=None,
578580
)
579581

580582
expected_endpoint.name = _TEST_ENDPOINT_NAME
581583
assert my_endpoint._gca_resource == expected_endpoint
582584

585+
@pytest.mark.usefixtures("get_endpoint_mock")
586+
@pytest.mark.parametrize("sync", [True, False])
587+
def test_create_with_endpoint_id(self, create_endpoint_mock, sync):
588+
my_endpoint = models.Endpoint.create(
589+
display_name=_TEST_DISPLAY_NAME,
590+
endpoint_id=_TEST_ID,
591+
description=_TEST_DESCRIPTION,
592+
sync=sync,
593+
create_request_timeout=None,
594+
)
595+
if not sync:
596+
my_endpoint.wait()
597+
598+
expected_endpoint = gca_endpoint.Endpoint(
599+
display_name=_TEST_DISPLAY_NAME,
600+
description=_TEST_DESCRIPTION,
601+
)
602+
create_endpoint_mock.assert_called_once_with(
603+
parent=_TEST_PARENT,
604+
endpoint=expected_endpoint,
605+
endpoint_id=_TEST_ID,
606+
metadata=(),
607+
timeout=None,
608+
)
609+
583610
@pytest.mark.usefixtures("get_endpoint_mock")
584611
@pytest.mark.parametrize("sync", [True, False])
585612
def test_create_with_timeout(self, create_endpoint_mock, sync):
@@ -599,6 +626,7 @@ def test_create_with_timeout(self, create_endpoint_mock, sync):
599626
create_endpoint_mock.assert_called_once_with(
600627
parent=_TEST_PARENT,
601628
endpoint=expected_endpoint,
629+
endpoint_id=None,
602630
metadata=(),
603631
timeout=180.0,
604632
)
@@ -642,6 +670,7 @@ def test_create_with_description(self, create_endpoint_mock, sync):
642670
create_endpoint_mock.assert_called_once_with(
643671
parent=_TEST_PARENT,
644672
endpoint=expected_endpoint,
673+
endpoint_id=None,
645674
metadata=(),
646675
timeout=None,
647676
)
@@ -665,6 +694,7 @@ def test_create_with_labels(self, create_endpoint_mock, sync):
665694
create_endpoint_mock.assert_called_once_with(
666695
parent=_TEST_PARENT,
667696
endpoint=expected_endpoint,
697+
endpoint_id=None,
668698
metadata=(),
669699
timeout=None,
670700
)

0 commit comments

Comments
 (0)