Skip to content

Commit

Permalink
Update commands
Browse files Browse the repository at this point in the history
  • Loading branch information
am-lim committed Nov 5, 2023
1 parent 7c2d5d4 commit 1efbcce
Show file tree
Hide file tree
Showing 14 changed files with 1,049 additions and 801 deletions.
158 changes: 158 additions & 0 deletions src/devcenter/azext_devcenter/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,3 +650,161 @@
az devcenter dev environment-definition show --endpoint "https://8a40af38-3b4c-4672-a6a4-5e964b1870ed-contosodevcenter.centralus.devcenter.azure.com/" \
--project-name "DevProject" --catalog-name "myCatalog" --definition-name "foo"
"""

helps[
"devcenter dev environment list-operation"
] = """
type: command
short-summary: "Lists operations on the environment which have occurred within the past 90 days."
examples:
- name: List using dev center
text: |-
az devcenter dev environment list-operation --dev-center-name "ContosoDevCenter" \
--name "mydevenv" --project-name "DevProject" --user-id "00000000-0000-0000-0000-000000000000"
examples:
- name: List using endpoint
text: |-
az devcenter dev environment list-operation --endpoint "https://8a40af38-3b4c-4672-a6a4-5e964b1870ed-contosodevcenter.centralus.devcenter.azure.com/" \
--name "mydevenv" --project-name "DevProject" --user-id "00000000-0000-0000-0000-000000000000"
"""

helps[
"devcenter dev environment show-operation"
] = """
type: command
short-summary: "Gets an environment action result."
examples:
- name: Get using dev center
text: |-
az devcenter dev environment show-operation --dev-center-name "ContosoDevCenter" \
--name "mydevenv" --project-name "DevProject" --user-id "00000000-0000-0000-0000-000000000000" --operation-id \
"f5dbdfab-fa0e-4831-8d13-25359aa5e680"
examples:
- name: Get using endpoint
text: |-
az devcenter dev environment show-operation --endpoint "https://8a40af38-3b4c-4672-a6a4-5e964b1870ed-contosodevcenter.centralus.devcenter.azure.com/" \
--name "mydevenv" --project-name "DevProject" --user-id "00000000-0000-0000-0000-000000000000" --operation-id "f5dbdfab-fa0e-4831-8d13-25359aa5e680"
"""

helps[
"devcenter dev environment show-logs-by-operation"
] = """
type: command
short-summary: "Gets the logs for an operation on an environment."
examples:
- name: Get using dev center
text: |-
az devcenter dev environment show-logs-by-operation --dev-center-name "ContosoDevCenter" \
--name "mydevenv" --project-name "DevProject" --user-id "00000000-0000-0000-0000-000000000000" --operation-id \
"f5dbdfab-fa0e-4831-8d13-25359aa5e680"
examples:
- name: Get using endpoint
text: |-
az devcenter dev environment show-logs-by-operation --endpoint "https://8a40af38-3b4c-4672-a6a4-5e964b1870ed-contosodevcenter.centralus.devcenter.azure.com/" \
--name "mydevenv" --project-name "DevProject" --user-id "00000000-0000-0000-0000-000000000000" --operation-id "f5dbdfab-fa0e-4831-8d13-25359aa5e680"
"""

helps[
"devcenter dev environment show-action"
] = """
type: command
short-summary: "Retrieve a specific environment action."
examples:
- name: Get using dev center
text: |-
az devcenter dev environment show-action --dev-center-name "ContosoDevCenter" \
--name "mydevenv" --project-name "DevProject" --user-id "00000000-0000-0000-0000-000000000000" --action-name \
"myEnv-Delete"
examples:
- name: Get using endpoint
text: |-
az devcenter dev environment show-action --endpoint "https://8a40af38-3b4c-4672-a6a4-5e964b1870ed-contosodevcenter.centralus.devcenter.azure.com/" \
--name "mydevenv" --project-name "DevProject" --user-id "00000000-0000-0000-0000-000000000000" --action-name "myEnv-Delete"
"""

helps[
"devcenter dev environment list-action"
] = """
type: command
short-summary: "List specific environment actions."
examples:
- name: List using dev center
text: |-
az devcenter dev environment list-action --dev-center-name "ContosoDevCenter" \
--name "mydevenv" --project-name "DevProject" --user-id "00000000-0000-0000-0000-000000000000"
examples:
- name: List using endpoint
text: |-
az devcenter dev environment list-action --endpoint "https://8a40af38-3b4c-4672-a6a4-5e964b1870ed-contosodevcenter.centralus.devcenter.azure.com/" \
--name "mydevenv" --project-name "DevProject" --user-id "00000000-0000-0000-0000-000000000000"
"""

helps[
"devcenter dev environment delay-action"
] = """
type: command
short-summary: "Delay an environment action."
examples:
- name: Delay using dev center
text: |-
az devcenter dev environment delay-action --dev-center-name "ContosoDevCenter" \
--name "mydevenv" --project-name "DevProject" --user-id "00000000-0000-0000-0000-000000000000" --action-name \
"myEnv-Delete" --delay-time "04:30"
examples:
- name: Delay using endpoint
text: |-
az devcenter dev environment delay-action --endpoint "https://8a40af38-3b4c-4672-a6a4-5e964b1870ed-contosodevcenter.centralus.devcenter.azure.com/" \
--name "mydevenv" --project-name "DevProject" --user-id "00000000-0000-0000-0000-000000000000" --action-name "myEnv-Delete" --delay-time "04:30"
"""

helps[
"devcenter dev environment skip-action"
] = """
type: command
short-summary: "Skip a specific environment action."
examples:
- name: Skip using dev center
text: |-
az devcenter dev environment skip-action --dev-center-name "ContosoDevCenter" \
--name "mydevenv" --project-name "DevProject" --user-id "00000000-0000-0000-0000-000000000000" --action-name \
"myEnv-Delete"
examples:
- name: Skip using endpoint
text: |-
az devcenter dev environment skip-action --endpoint "https://8a40af38-3b4c-4672-a6a4-5e964b1870ed-contosodevcenter.centralus.devcenter.azure.com/" \
--name "mydevenv" --project-name "DevProject" --user-id "00000000-0000-0000-0000-000000000000" --action-name "myEnv-Delete"
"""

helps[
"devcenter dev environment show-outputs"
] = """
type: command
short-summary: "Gets outputs from the environment."
examples:
- name: Get using dev center
text: |-
az devcenter dev environment show-outputs --dev-center-name "ContosoDevCenter" \
--name "mydevenv" --project-name "DevProject" --user-id "00000000-0000-0000-0000-000000000000"
examples:
- name: Get using endpoint
text: |-
az devcenter dev environment show-outputs --endpoint "https://8a40af38-3b4c-4672-a6a4-5e964b1870ed-contosodevcenter.centralus.devcenter.azure.com/" \
--name "mydevenv" --project-name "DevProject" --user-id "00000000-0000-0000-0000-000000000000"
"""

helps[
"devcenter dev environment update-expiration-date"
] = """
type: command
short-summary: "Update the environment expiration"
examples:
- name: Get using dev center
text: |-
az devcenter dev environment update-expiration-date --dev-center-name "ContosoDevCenter" \
--name "mydevenv" --project-name "DevProject" --user-id "00000000-0000-0000-0000-000000000000" --expiration "2025-11-30T22:35:00+00:00"
examples:
- name: Get using endpoint
text: |-
az devcenter dev environment update-expiration-date --endpoint "https://8a40af38-3b4c-4672-a6a4-5e964b1870ed-contosodevcenter.centralus.devcenter.azure.com/" \
--name "mydevenv" --project-name "DevProject" --user-id "00000000-0000-0000-0000-000000000000" --expiration "2025-11-30T22:35:00+00:00"
"""
46 changes: 24 additions & 22 deletions src/devcenter/azext_devcenter/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
validate_file_or_dict,
)

from ._validators import validate_dev_box_list, validate_time
from ._validators import validate_dev_box_list, validate_time, is_iso8601


dev_center_type = CLIArgumentType(
Expand Down Expand Up @@ -640,7 +640,7 @@ def load_arguments(self, _):
help="The name " "of the environment.",
)

with self.argument_context("devcenter dev environment create") as c:
with self.argument_context("devcenter dev environment create", validator=is_iso8601) as c:
c.argument(
"dev_center",
arg_type=dev_center_type,
Expand Down Expand Up @@ -681,12 +681,13 @@ def load_arguments(self, _):
)
c.argument(
"expiration_date",
options_list=["--expiration_date", "--expiration"],
options_list=["--expiration-date", "--expiration"],
type=str,
help="The date of environment expiration. Must be an ISO string",
help="The time the expiration date will be triggered (UTC), after which the environment"
" and associated resources will be deleted. The string format is ISO format.",
)

with self.argument_context("devcenter dev environment update") as c:
with self.argument_context("devcenter dev environment update", validator=is_iso8601) as c:
c.argument(
"dev_center",
arg_type=dev_center_type,
Expand Down Expand Up @@ -719,12 +720,12 @@ def load_arguments(self, _):
)
c.argument(
"expiration_date",
options_list=["--expiration_date", "--expiration"],
options_list=["--expiration-date", "--expiration"],
type=str,
help="The date of environment expiration. Must be an ISO string",
)

with self.argument_context("devcenter dev environment deploy") as c:
with self.argument_context("devcenter dev environment deploy", validator=is_iso8601) as c:
c.argument(
"dev_center",
arg_type=dev_center_type,
Expand Down Expand Up @@ -757,7 +758,7 @@ def load_arguments(self, _):
)
c.argument(
"expiration_date",
options_list=["--expiration_date", "--expiration"],
options_list=["--expiration-date", "--expiration"],
type=str,
help="The date of environment expiration. Must be an ISO string",
)
Expand Down Expand Up @@ -873,7 +874,7 @@ def load_arguments(self, _):
"endpoint",
arg_type=endpoint,
)

with self.argument_context("devcenter dev environment list-operation") as c:
c.argument(
"dev_center",
Expand Down Expand Up @@ -927,7 +928,7 @@ def load_arguments(self, _):
)
c.argument(
"operation_id",
options_list=["--operation-id", "-o"],
options_list=["--operation-id"],
type=str,
help="The ID " "of the operation.",
)
Expand Down Expand Up @@ -959,7 +960,7 @@ def load_arguments(self, _):
)
c.argument(
"operation_id",
options_list=["--operation-id", "-o"],
options_list=["--operation-id"],
type=str,
help="The ID " "of the operation.",
)
Expand Down Expand Up @@ -995,7 +996,7 @@ def load_arguments(self, _):
type=str,
help="The name of an action that will take place on an environment.",
)

with self.argument_context("devcenter dev environment skip-action") as c:
c.argument(
"dev_center",
Expand Down Expand Up @@ -1027,7 +1028,7 @@ def load_arguments(self, _):
type=str,
help="The name of an action that will take place on an environment.",
)

with self.argument_context("devcenter dev environment list-action") as c:
c.argument(
"dev_center",
Expand All @@ -1054,7 +1055,9 @@ def load_arguments(self, _):
help="The name " "of the environment.",
)

with self.argument_context("devcenter dev environment delay-action") as c:
with self.argument_context(
"devcenter dev environment delay-action", validator=validate_time
) as c:
c.argument(
"dev_center",
arg_type=dev_center_type,
Expand Down Expand Up @@ -1086,12 +1089,10 @@ def load_arguments(self, _):
help="The name of an action that will take place on an environment.",
)
c.argument(
"until",
options_list=["--until"],
type=str,
help="The time to delay the environment action until. Must be an ISO string",
"delay_time",
help="The delayed timespan from the scheduled action time. Format HH:MM",
)

with self.argument_context("devcenter dev environment show-outputs") as c:
c.argument(
"dev_center",
Expand All @@ -1118,7 +1119,7 @@ def load_arguments(self, _):
help="The name " "of the environment.",
)

with self.argument_context("devcenter dev environment update-environment-expiration-date") as c:
with self.argument_context("devcenter dev environment update-expiration-date", validator=is_iso8601) as c:
c.argument(
"dev_center",
arg_type=dev_center_type,
Expand All @@ -1145,7 +1146,8 @@ def load_arguments(self, _):
)
c.argument(
"expiration_date",
options_list=["--expiration_date", "--expiration"],
options_list=["--expiration-date", "--expiration"],
type=str,
help="The date of environment expiration. Must be an ISO string",
help="The time the expiration date will be triggered (UTC), after which the environment "
"and associated resources will be deleted. The string format is ISO format.",
)
32 changes: 28 additions & 4 deletions src/devcenter/azext_devcenter/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
from datetime import datetime
import locale
import re
from azure.cli.core.azclierror import (
Expand Down Expand Up @@ -33,22 +34,35 @@ def validate_repo_git(ado_git, git_hub):
or GitHub source control definition (--git-hub) should be set."""
raise RequiredArgumentMissingError(error_message)

def validate_pool_create(virtual_network_type, network_connection_name, managed_virtual_network_regions):
if not has_value(managed_virtual_network_regions) and virtual_network_type == "Managed":

def validate_pool_create(
virtual_network_type, network_connection_name, managed_virtual_network_regions
):
if (
not has_value(managed_virtual_network_regions)
and virtual_network_type == "Managed"
):
error_message = """When virtual-network-type is set to "Managed", \
managed virtual network regions (--managed-virtual-network-regions) should be set."""
raise RequiredArgumentMissingError(error_message)
if not has_value(network_connection_name) and (virtual_network_type == "Unmanaged" or not has_value(virtual_network_type)):
if not has_value(network_connection_name) and (
virtual_network_type == "Unmanaged" or not has_value(virtual_network_type)
):
error_message = """When virtual-network-type is not used or set to "Unmanaged", \
a network connection name (--network-connection) should be set."""
raise RequiredArgumentMissingError(error_message)
if has_value(managed_virtual_network_regions) and (virtual_network_type == "Unmanaged" or not has_value(virtual_network_type)):
if has_value(managed_virtual_network_regions) and (
virtual_network_type == "Unmanaged" or not has_value(virtual_network_type)
):
print(managed_virtual_network_regions[0])
error_message = """When virtual-network-type is not used or set to "Unmanaged", \
managed virtual network regions (--managed-virtual-network-regions) should not be set."""
raise RequiredArgumentMissingError(error_message)


# Data plane


def validate_dev_box_list(namespace):
if namespace.project_name is not None and namespace.user_id is None:
raise RequiredArgumentMissingError(
Expand Down Expand Up @@ -96,3 +110,13 @@ def validate_env_name_already_exists(env_iterator, name, user_id, project):
error_message = f"""An environment with the name '{name}' \
already exists for the user-id '{user_id}' in this project '{project}'."""
raise InvalidArgumentValueError(error_message)


def is_iso8601(namespace):
try:
datetime.fromisoformat(namespace.expiration_date)
return True
except ValueError as exception:
error_message = f"""The expiration date is invalid '{namespace.expiration_date}' \
it must be in ISO 8601 format. For example: 2023-12-30T22:35:00+00:00"""
raise InvalidArgumentValueError(error_message) from exception
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def _build_arguments_schema(cls, *args, **kwargs):
enum={"Disabled": "Disabled", "Enabled": "Enabled"},
)
_args_schema.managed_virtual_network_regions = AAZListArg(
options=["--managed-virtual-network-regions"],
options=["--managed-virtual-network-regions", "-m"],
arg_group="Properties",
help="The regions of the managed virtual network (required when managedNetworkType is Managed).",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def _build_arguments_schema(cls, *args, **kwargs):
enum={"Disabled": "Disabled", "Enabled": "Enabled"},
)
_args_schema.managed_virtual_network_regions = AAZListArg(
options=["--managed-virtual-network-regions"],
options=["--managed-virtual-network-regions", "-m"],
arg_group="Properties",
help="The regions of the managed virtual network (required when managedNetworkType is Managed).",
nullable=True,
Expand Down
Loading

0 comments on commit 1efbcce

Please sign in to comment.