Skip to content

Commit

Permalink
Merge pull request #1031 from vespa-engine/thomasht86/support-instance
Browse files Browse the repository at this point in the history
add instance arg
  • Loading branch information
ldalves authored Feb 28, 2025
2 parents 0593bf9 + 679f429 commit 23c4bff
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions vespa/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ def __init__(
output_file: IO = sys.stdout,
application_root: Optional[str] = None,
cluster: Optional[str] = None,
instance: str = "default",
) -> None:
"""
Deploy application to the Vespa Cloud (cloud.vespa.ai)
Expand Down Expand Up @@ -508,6 +509,7 @@ def __init__(
:param output_file: Output file to write output messages. Default is sys.stdout
:param application_root: Directory for application root. (location of services.xml, models/, schemas/, etc.). If application is packaged with maven, use the generated <myapp>/target/application directory.
:param cluster: Name of the cluster to target for when retrieving endpoints. Will affect which endpoints are used for initializing :class:`Vespa` instance in :func:`VespaCloud.get_application` and :func:`VespaCloud.deploy`.
:param instance: Name of the application instance. Default is "default".
"""
self.tenant = tenant
self.application = application
Expand All @@ -517,6 +519,7 @@ def __init__(
raise ValueError(
"Either application_package or application_root must be set for deployment."
)
self.instance = instance
self.output = output_file
self.api_key = self._read_private_key(key_location, key_content)
self.control_plane_auth_method = None # "api_key" or "access_token"
Expand Down Expand Up @@ -633,7 +636,7 @@ def deploy(
region = self.get_dev_region()
job = "dev-" + region
run = self._start_deployment(
instance=instance,
instance=instance or self.instance,
job=job,
disk_folder=disk_folder,
application_zip_bytes=None,
Expand Down Expand Up @@ -747,7 +750,7 @@ def get_application(
f"Only region: {region} available in dev environment.", file=self.output
)
elif environment == "prod":
valid_regions = self.get_prod_regions(instance=instance)
valid_regions = self.get_prod_regions(instance=instance or self.instance)
if region is not None:
if region not in valid_regions:
raise ValueError(
Expand All @@ -759,7 +762,9 @@ def get_application(
raise ValueError("Environment must be 'dev' or 'prod'.")
if endpoint_type == "mtls":
mtls_endpoint = self.get_mtls_endpoint(
instance=instance, region=region, environment=environment
instance=instance or self.instance,
region=region,
environment=environment,
)
app: Vespa = Vespa(
url=mtls_endpoint,
Expand All @@ -770,7 +775,9 @@ def get_application(
elif endpoint_type == "token":
try: # May have client_token_id set but the deployed app was not configured to use it
token_endpoint = self.get_token_endpoint(
instance=instance, region=region, environment=environment
instance=instance or self.instance,
region=region,
environment=environment,
)
except Exception as _:
raise ValueError(
Expand Down Expand Up @@ -889,15 +896,15 @@ def deploy_from_disk(
region = self.get_dev_region()
job = "dev-" + region
run = self._start_deployment(
instance=instance,
instance=instance or self.instance,
job=job,
disk_folder=disk_folder,
application_zip_bytes=data,
version=version,
)
self._follow_deployment(instance, job, run)
app: Vespa = self.get_application(
instance=instance, environment="dev", endpoint_type="mtls"
instance=instance or self.instance, environment="dev", endpoint_type="mtls"
)
return app

Expand Down Expand Up @@ -1047,9 +1054,7 @@ def _vespa_auth_cert(self):
print(output.stdout.decode("utf-8"))

def _set_application(self):
vespa_cli_command = (
f"vespa config set application {self.tenant}.{self.application}"
)
vespa_cli_command = f"vespa config set application {self.tenant}.{self.application}.{self.instance}"
print("Running: " + vespa_cli_command)
output = subprocess.run(
shlex.split(vespa_cli_command),
Expand Down Expand Up @@ -1083,8 +1088,8 @@ def _check_dir(path: Path):
else:
# If cert/key not found in application root: look in ~/.vespa/tenant.app.default/
home_vespa_dir = (
VESPA_HOME / f"{self.tenant}.{self.application}.default"
) # TODO Support other instance names
VESPA_HOME / f"{self.tenant}.{self.application}.{self.instance}"
)
cert, key = _check_dir(home_vespa_dir)
if cert and key:
self.data_cert_path = cert
Expand Down

0 comments on commit 23c4bff

Please sign in to comment.