From 6639fcde18cffe7699e2b6fa0c2bb573c09d259e Mon Sep 17 00:00:00 2001 From: Amanda Lim Date: Wed, 16 Aug 2023 19:31:00 -0700 Subject: [PATCH] Update data plane --- .../azext_devcenter/_client_factory.py | 2 +- src/devcenter/azext_devcenter/_help.py | 109 ++ src/devcenter/azext_devcenter/_params.py | 1247 +++++++++-------- src/devcenter/azext_devcenter/_validators.py | 4 +- src/devcenter/azext_devcenter/commands.py | 129 +- src/devcenter/azext_devcenter/custom.py | 814 ++++++----- src/devcenter/azext_devcenter/utils.py | 7 +- 7 files changed, 1325 insertions(+), 987 deletions(-) diff --git a/src/devcenter/azext_devcenter/_client_factory.py b/src/devcenter/azext_devcenter/_client_factory.py index 11c584e9cec..582465f443e 100644 --- a/src/devcenter/azext_devcenter/_client_factory.py +++ b/src/devcenter/azext_devcenter/_client_factory.py @@ -28,8 +28,8 @@ def cf_devcenter_dataplane(cli_ctx, endpoint=None, dev_center=None, project_name profile = Profile(cli_ctx=cli_ctx) credential = profile.get_login_credentials(resource="https://devcenter.azure.com") - cli_ctx.cloud.endpoints.active_directory_resource_id = "https://devcenter.azure.com" + return DevCenterClient(endpoint, credential[0]) diff --git a/src/devcenter/azext_devcenter/_help.py b/src/devcenter/azext_devcenter/_help.py index 2c6eb3271fd..a3479d5af71 100644 --- a/src/devcenter/azext_devcenter/_help.py +++ b/src/devcenter/azext_devcenter/_help.py @@ -95,6 +95,30 @@ short-summary: Manage schedules. """ +helps[ + "devcenter dev schedule list" +] = """ + type: command + short-summary: "List schedules." + examples: + - name: List schedules by project using dev center + text: |- + az devcenter dev schedule list --dev-center-name "ContosoDevCenter" \ +--project-name "DevProject" + - name: List schedules by project using endpoint + text: |- + az devcenter dev schedule list --endpoint "https://8a40af38-3b4c-4672-a6a4-5e964b1870ed-contosodevcenter.centralus.devcenter.azure.com/" \ +--project-name "DevProject" + - name: List schedules by pool using dev center + text: |- + az devcenter dev schedule list --dev-center-name "ContosoDevCenter" \ +--pool-name "DevPool" --project-name "DevProject" + - name: List schedules by pool using endpoint + text: |- + az devcenter dev schedule list --endpoint "https://8a40af38-3b4c-4672-a6a4-5e964b1870ed-contosodevcenter.centralus.devcenter.azure.com/" \ +--pool-name "DevPool" --project-name "DevProject" +""" + helps[ "devcenter dev schedule show" ] = """ @@ -245,6 +269,22 @@ --project-name "DevProject" --user-id "00000000-0000-0000-0000-000000000000" """ +helps[ + "devcenter dev dev-box repair" +] = """ + type: command + short-summary: "Attempts automated repair steps to resolve common problems on a Dev Box. The dev box may restart during this operation." + examples: + - name: Repair using dev center + text: |- + az devcenter dev dev-box repair --name "MyDevBox" --dev-center-name "ContosoDevCenter" \ + --project-name "DevProject" --user-id "00000000-0000-0000-0000-000000000000" + - name: Repair using endpoint + text: |- + az devcenter dev dev-box repair --name "MyDevBox" --endpoint "https://8a40af38-3b4c-4672-a6a4-5e964b1870ed-contosodevcenter.centralus.devcenter.azure.com/" \ +--project-name "DevProject" --user-id "00000000-0000-0000-0000-000000000000" +""" + helps[ "devcenter dev dev-box stop" ] = """ @@ -313,6 +353,40 @@ --user-id "00000000-0000-0000-0000-000000000000" """ +helps[ + "devcenter dev dev-box list-operation" +] = """ + type: command + short-summary: "Lists operations on the dev box which have occurred within the past 90 days." + examples: + - name: List operations using dev center + text: |- + az devcenter dev dev-box list-operation --dev-center-name "ContosoDevCenter" \ +--project-name "DevProject" --name "myDevBox" --user-id "00000000-0000-0000-0000-000000000000" + - name: List operations using endpoint + text: |- + az devcenter dev dev-box list-operation --endpoint "https://8a40af38-3b4c-4672-a6a4-5e964b1870ed-contosodevcenter.centralus.devcenter.azure.com/" \ +--project-name "DevProject" --name "myDevBox" --user-id "00000000-0000-0000-0000-000000000000" +""" + +helps[ + "devcenter dev dev-box show-operation" +] = """ + type: command + short-summary: "Get an operation on a dev box." + examples: + - name: Get operation using dev center + text: |- + az devcenter dev dev-box show-operation --dev-center-name "ContosoDevCenter" \ +--project-name "DevProject" --name "myDevBox" --operation-id \ +"f5dbdfab-fa0e-4831-8d13-25359aa5e680" --user-id "00000000-0000-0000-0000-000000000000" + - name: Get operation using endpoint + text: |- + az devcenter dev dev-box show-operation --endpoint "https://8a40af38-3b4c-4672-a6a4-5e964b1870ed-contosodevcenter.centralus.devcenter.azure.com/" \ +--project-name "DevProject" --name "myDevBox" --operation-id \ +"f5dbdfab-fa0e-4831-8d13-25359aa5e680" --user-id "00000000-0000-0000-0000-000000000000" +""" + helps[ "devcenter dev dev-box show-action" ] = """ @@ -576,3 +650,38 @@ 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 operations using dev center + text: |- + az devcenter dev environment list-operation --dev-center-name "ContosoDevCenter" \ +--project-name "DevProject" --name "myEnv" --user-id "00000000-0000-0000-0000-000000000000" + - name: List operations using endpoint + text: |- + az devcenter dev environment list-operation --endpoint "https://8a40af38-3b4c-4672-a6a4-5e964b1870ed-contosodevcenter.centralus.devcenter.azure.com/" \ +--project-name "DevProject" --name "myEnv" --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 operation using dev center + text: |- + az devcenter dev environment show-operation --dev-center-name "ContosoDevCenter" \ +--project-name "DevProject" --name "myEnv" --operation-id \ +"f5dbdfab-fa0e-4831-8d13-25359aa5e680" --user-id "00000000-0000-0000-0000-000000000000" + - name: Get operation using endpoint + text: |- + az devcenter dev environment show-operation --endpoint "https://8a40af38-3b4c-4672-a6a4-5e964b1870ed-contosodevcenter.centralus.devcenter.azure.com/" \ +--project-name "DevProject" --name "myEnv" --operation-id \ +"f5dbdfab-fa0e-4831-8d13-25359aa5e680" --user-id "00000000-0000-0000-0000-000000000000" +""" diff --git a/src/devcenter/azext_devcenter/_params.py b/src/devcenter/azext_devcenter/_params.py index afda75845ed..54c154358ba 100644 --- a/src/devcenter/azext_devcenter/_params.py +++ b/src/devcenter/azext_devcenter/_params.py @@ -218,558 +218,697 @@ def load_arguments(self, _): help="The name of the dev box pool this machine belongs to.", ) + with self.argument_context("devcenter dev dev-box delete") as c: + c.argument( + "dev_center", + arg_type=dev_center_type, + ) + c.argument( + "project_name", + arg_type=project_type, + ) + c.argument( + "endpoint", + arg_type=endpoint, + ) + c.argument( + "user_id", + type=str, + help="The AAD object id of the user. If value is 'me', the identity is taken from the " + "authentication context", + ) + c.argument( + "dev_box_name", + options_list=["--name", "-n", "--dev-box-name"], + type=str, + help="The name of a dev " "box.", + ) + + with self.argument_context("devcenter dev dev-box start") as c: + c.argument( + "dev_center", + arg_type=dev_center_type, + ) + c.argument( + "project_name", + arg_type=project_type, + ) + c.argument( + "endpoint", + arg_type=endpoint, + ) + c.argument( + "user_id", + type=str, + help="The AAD object id of the user. If value is 'me', the identity is taken from the " + "authentication context", + ) + c.argument( + "dev_box_name", + options_list=["--name", "-n", "--dev-box-name"], + type=str, + help="The name of a dev " "box.", + ) + + with self.argument_context("devcenter dev dev-box stop") as c: + c.argument( + "dev_center", + arg_type=dev_center_type, + ) + c.argument( + "project_name", + arg_type=project_type, + ) + c.argument( + "endpoint", + arg_type=endpoint, + ) + c.argument( + "user_id", + type=str, + help="The AAD object id of the user. If value is 'me', the identity is taken from the " + "authentication context", + ) + c.argument( + "dev_box_name", + options_list=["--name", "-n", "--dev-box-name"], + type=str, + help="The name of a dev " "box.", + ) + c.argument( + "hibernate", + arg_type=get_three_state_flag(), + help="Optional parameter to hibernate the dev box.", + is_preview=True, + ) + + with self.argument_context("devcenter dev dev-box restart") as c: + c.argument( + "dev_center", + arg_type=dev_center_type, + ) + c.argument( + "project_name", + arg_type=project_type, + ) + c.argument( + "endpoint", + arg_type=endpoint, + ) + c.argument( + "user_id", + type=str, + help="The AAD object id of the user. If value is 'me', the identity is taken " + "from the authentication context.", + ) + c.argument( + "dev_box_name", + options_list=["--name", "-n", "--dev-box-name"], + type=str, + help="The name of a dev " "box.", + ) + + with self.argument_context("devcenter dev dev-box repair") as c: + c.argument( + "dev_center", + arg_type=dev_center_type, + ) + c.argument( + "project_name", + arg_type=project_type, + ) + c.argument( + "endpoint", + arg_type=endpoint, + ) + c.argument( + "user_id", + type=str, + help="The AAD object id of the user. If value is 'me', the identity is taken " + "from the authentication context.", + ) + c.argument( + "dev_box_name", + options_list=["--name", "-n", "--dev-box-name"], + type=str, + help="The name of a dev " "box.", + ) + + with self.argument_context("devcenter dev dev-box show-remote-connection") as c: + c.argument( + "dev_center", + arg_type=dev_center_type, + ) + c.argument( + "project_name", + arg_type=project_type, + ) + c.argument( + "endpoint", + arg_type=endpoint, + ) + c.argument( + "user_id", + type=str, + help="The AAD object id of the user. If value is 'me', the identity is taken from the " + "authentication context", + ) + c.argument( + "dev_box_name", + options_list=["--name", "-n", "--dev-box-name"], + type=str, + help="The name of a dev " "box.", + ) + + with self.argument_context("devcenter dev dev-box list-action") as c: + c.argument( + "dev_center", + arg_type=dev_center_type, + ) + c.argument( + "project_name", + arg_type=project_type, + ) + c.argument( + "endpoint", + arg_type=endpoint, + ) + c.argument( + "user_id", + type=str, + help="The AAD object id of the user. If value is 'me', the identity is taken " + "from the authentication context.", + ) + c.argument( + "dev_box_name", + options_list=["--name", "-n", "--dev-box-name"], + type=str, + help="The name of a dev " "box.", + ) + + with self.argument_context("devcenter dev dev-box show-action") as c: + c.argument( + "dev_center", + arg_type=dev_center_type, + ) + c.argument( + "project_name", + arg_type=project_type, + ) + c.argument( + "endpoint", + arg_type=endpoint, + ) + c.argument( + "user_id", + type=str, + help="The AAD object id of the user. If value is 'me', the identity is taken " + "from the authentication context.", + ) + c.argument( + "dev_box_name", + options_list=["--name", "-n", "--dev-box-name"], + type=str, + help="The name of a dev " "box.", + ) + c.argument( + "action_name", + type=str, + help="The name of an action that will take place on a dev box.", + ) + + with self.argument_context("devcenter dev dev-box skip-action") as c: + c.argument( + "dev_center", + arg_type=dev_center_type, + ) + c.argument( + "project_name", + arg_type=project_type, + ) + c.argument( + "endpoint", + arg_type=endpoint, + ) + c.argument( + "user_id", + type=str, + help="The AAD object id of the user. If value is 'me', the identity is taken " + "from the authentication context.", + ) + c.argument( + "dev_box_name", + options_list=["--name", "-n", "--dev-box-name"], + type=str, + help="The name of a dev " "box.", + ) + c.argument( + "action_name", + type=str, + help="The name of an action that will take place on a dev box.", + ) + + with self.argument_context( + "devcenter dev dev-box delay-action", validator=validate_time + ) as c: + c.argument( + "dev_center", + arg_type=dev_center_type, + ) + c.argument( + "project_name", + arg_type=project_type, + ) + c.argument( + "endpoint", + arg_type=endpoint, + ) + c.argument( + "user_id", + type=str, + help="The AAD object id of the user. If value is 'me', the identity is taken " + "from the authentication context.", + ) + c.argument( + "dev_box_name", + options_list=["--name", "-n", "--dev-box-name"], + type=str, + help="The name of a dev " "box.", + ) + c.argument( + "action_name", + type=str, + help="The name of an action that will take place on a dev box.", + ) + c.argument( + "delay_time", + help="The delayed timespan from the scheduled action time. Format HH:MM", + ) + + with self.argument_context( + "devcenter dev dev-box delay-all-actions", validator=validate_time + ) as c: + c.argument( + "dev_center", + arg_type=dev_center_type, + ) + c.argument( + "project_name", + arg_type=project_type, + ) + c.argument( + "endpoint", + arg_type=endpoint, + ) + c.argument( + "user_id", + type=str, + help="The AAD object id of the user. If value is 'me', the identity is taken " + "from the authentication context.", + ) + c.argument( + "dev_box_name", + options_list=["--name", "-n", "--dev-box-name"], + type=str, + help="The name of a dev " "box.", + ) + c.argument( + "delay_time", + help="The delayed timespan from the earliest scheduled time of all actions. Format HH:MM", + ) + + with self.argument_context("devcenter dev dev-box list-operation") as c: + c.argument( + "dev_center", + arg_type=dev_center_type, + ) + c.argument( + "project_name", + arg_type=project_type, + ) + c.argument( + "endpoint", + arg_type=endpoint, + ) + c.argument( + "user_id", + type=str, + help="The AAD object id of the user. If value is 'me', the identity is taken " + "from the authentication context.", + ) + c.argument( + "dev_box_name", + options_list=["--name", "-n", "--dev-box-name"], + type=str, + help="The name of a dev " "box.", + ) + + with self.argument_context("devcenter dev dev-box show-operation") as c: + c.argument( + "dev_center", + arg_type=dev_center_type, + ) + c.argument( + "project_name", + arg_type=project_type, + ) + c.argument( + "endpoint", + arg_type=endpoint, + ) + c.argument( + "user_id", + type=str, + help="The AAD object id of the user. If value is 'me', the identity is taken " + "from the authentication context.", + ) + c.argument( + "dev_box_name", + options_list=["--name", "-n", "--dev-box-name"], + type=str, + help="The name of a dev " "box.", + ) + c.argument( + "operation_id", + type=str, + help="The id of the operation on a dev box.", + ) + + with self.argument_context("devcenter dev environment list") as c: + c.argument( + "dev_center", + arg_type=dev_center_type, + ) + c.argument( + "project_name", + arg_type=project_type, + ) + c.argument( + "endpoint", + arg_type=endpoint, + ) + c.argument( + "user_id", + type=str, + help="The AAD object id of the user. If value is 'me', the identity is taken " + "from the authentication context.", + ) + + with self.argument_context("devcenter dev environment show") as c: + c.argument( + "dev_center", + arg_type=dev_center_type, + ) + c.argument( + "project_name", + arg_type=project_type, + ) + c.argument( + "endpoint", + arg_type=endpoint, + ) + c.argument( + "user_id", + type=str, + help="The AAD object id of the user. If value is 'me', the identity is taken from the " + "authentication context", + ) + c.argument( + "environment_name", + options_list=["--name", "-n", "--environment-name"], + type=str, + help="The name " "of the environment.", + ) + + with self.argument_context("devcenter dev environment create") as c: + c.argument( + "dev_center", + arg_type=dev_center_type, + ) + c.argument( + "project_name", + arg_type=project_type, + ) + c.argument( + "endpoint", + arg_type=endpoint, + ) + c.argument( + "user_id", + type=str, + help="The AAD object id of the user. If value is 'me', the identity is taken " + "from the authentication context.", + ) + c.argument( + "environment_name", + options_list=["--name", "-n", "--environment-name"], + type=str, + help="The name " "of the environment.", + ) + c.argument( + "parameters", + type=validate_file_or_dict, + help="Parameters object for the environment. Expected " + "value: json-string/json-file/@json-file.", + ) + c.argument("environment_type", type=str, help="Environment type.") + c.argument("catalog_name", type=str, help="Name of the catalog.") + c.argument( + "environment_definition_name", + options_list=["-e", "--environment-definition-name"], + type=str, + help="Name of the environment definition.", + ) + + with self.argument_context("devcenter dev environment update") as c: + c.argument( + "dev_center", + arg_type=dev_center_type, + ) + c.argument( + "project_name", + arg_type=project_type, + ) + c.argument( + "endpoint", + arg_type=endpoint, + ) + c.argument( + "user_id", + type=str, + help="The AAD object id of the user. If value is 'me', the identity is taken " + "from the authentication context.", + ) + c.argument( + "environment_name", + options_list=["--name", "-n", "--environment-name"], + type=str, + help="The name " "of the environment.", + ) + c.argument( + "parameters", + type=validate_file_or_dict, + help="Parameters object for the environment. Expected " + "value: json-string/json-file/@json-file.", + ) + + with self.argument_context("devcenter dev environment deploy") as c: + c.argument( + "dev_center", + arg_type=dev_center_type, + ) + c.argument( + "project_name", + arg_type=project_type, + ) + c.argument( + "endpoint", + arg_type=endpoint, + ) + c.argument( + "user_id", + type=str, + help="The AAD object id of the user. If value is 'me', the identity is taken " + "from the authentication context.", + ) + c.argument( + "environment_name", + options_list=["--name", "-n", "--environment-name"], + type=str, + help="The name " "of the environment.", + ) + c.argument( + "parameters", + type=validate_file_or_dict, + help="Parameters object for the environment. Expected " + "value: json-string/json-file/@json-file.", + ) + + with self.argument_context("devcenter dev environment delete") as c: + c.argument( + "dev_center", + arg_type=dev_center_type, + ) + c.argument( + "project_name", + arg_type=project_type, + ) + c.argument( + "endpoint", + arg_type=endpoint, + ) + c.argument( + "user_id", + type=str, + help="The AAD object id of the user. If value is 'me', the identity is taken from the " + "authentication context", + ) + c.argument( + "environment_name", + options_list=["--name", "-n", "--environment-name"], + type=str, + help="The name " "of the environment.", + ) + + with self.argument_context("devcenter dev catalog list") as c: + c.argument( + "dev_center", + arg_type=dev_center_type, + ) + c.argument( + "project_name", + arg_type=project_type, + ) + c.argument( + "endpoint", + arg_type=endpoint, + ) + + with self.argument_context("devcenter dev catalog show") as c: + c.argument( + "dev_center", + arg_type=dev_center_type, + ) + c.argument( + "project_name", + arg_type=project_type, + ) + c.argument( + "endpoint", + arg_type=endpoint, + ) + c.argument( + "catalog_name", + options_list=["--name", "-n", "--catalog-name"], + type=str, + help="The name of the catalog", + ) + + with self.argument_context("devcenter dev environment-definition list") as c: + c.argument( + "dev_center", + arg_type=dev_center_type, + ) + c.argument( + "project_name", + required=True, + arg_type=project_type, + ) + c.argument( + "endpoint", + arg_type=endpoint, + ) + c.argument("catalog_name", type=str, help="The name of the catalog") + + with self.argument_context("devcenter dev environment-definition show") as c: + c.argument( + "dev_center", + arg_type=dev_center_type, + ) + c.argument( + "project_name", + required=True, + arg_type=project_type, + ) + c.argument( + "endpoint", + arg_type=endpoint, + ) + c.argument("catalog_name", type=str, help="The name of the catalog") + c.argument( + "definition_name", + options_list=["--name", "-n", "--definition-name"], + type=str, + help="The name of the environment definition", + ) + + with self.argument_context("devcenter dev environment-type list") as c: + c.argument( + "dev_center", + arg_type=dev_center_type, + ) + c.argument( + "project_name", + arg_type=project_type, + ) + c.argument( + "endpoint", + arg_type=endpoint, + ) + + with self.argument_context("devcenter dev environment list-operation") as c: + c.argument( + "dev_center", + arg_type=dev_center_type, + ) + c.argument( + "project_name", + arg_type=project_type, + ) + c.argument( + "endpoint", + arg_type=endpoint, + ) + c.argument( + "user_id", + type=str, + help="The AAD object id of the user. If value is 'me', the identity is taken from the " + "authentication context", + ) + c.argument( + "environment_name", + options_list=["--name", "-n", "--environment-name"], + type=str, + help="The name " "of the environment.", + ) - # with self.argument_context("devcenter dev dev-box delete") as c: - # c.argument( - # "dev_center", - # arg_type=dev_center_type, - # ) - # c.argument( - # "project_name", - # arg_type=project_type, - # ) - # c.argument( - # "endpoint", - # arg_type=endpoint, - # ) - # c.argument( - # "user_id", - # type=str, - # help="The AAD object id of the user. If value is 'me', the identity is taken from the " - # "authentication context", - # ) - # c.argument( - # "dev_box_name", - # options_list=["--name", "-n", "--dev-box-name"], - # type=str, - # help="The name of a dev " "box.", - # ) - - # with self.argument_context("devcenter dev dev-box show-remote-connection") as c: - # c.argument( - # "dev_center", - # arg_type=dev_center_type, - # ) - # c.argument( - # "project_name", - # arg_type=project_type, - # ) - # c.argument( - # "endpoint", - # arg_type=endpoint, - # ) - # c.argument( - # "user_id", - # type=str, - # help="The AAD object id of the user. If value is 'me', the identity is taken from the " - # "authentication context", - # ) - # c.argument( - # "dev_box_name", - # options_list=["--name", "-n", "--dev-box-name"], - # type=str, - # help="The name of a dev " "box.", - # ) - - # with self.argument_context("devcenter dev dev-box start") as c: - # c.argument( - # "dev_center", - # arg_type=dev_center_type, - # ) - # c.argument( - # "project_name", - # arg_type=project_type, - # ) - # c.argument( - # "endpoint", - # arg_type=endpoint, - # ) - # c.argument( - # "user_id", - # type=str, - # help="The AAD object id of the user. If value is 'me', the identity is taken from the " - # "authentication context", - # ) - # c.argument( - # "dev_box_name", - # options_list=["--name", "-n", "--dev-box-name"], - # type=str, - # help="The name of a dev " "box.", - # ) - - # with self.argument_context("devcenter dev dev-box restart") as c: - # c.argument( - # "dev_center", - # arg_type=dev_center_type, - # ) - # c.argument( - # "project_name", - # arg_type=project_type, - # ) - # c.argument( - # "endpoint", - # arg_type=endpoint, - # ) - # c.argument( - # "user_id", - # type=str, - # help="The AAD object id of the user. If value is 'me', the identity is taken " - # "from the authentication context.", - # ) - # c.argument( - # "dev_box_name", - # options_list=["--name", "-n", "--dev-box-name"], - # type=str, - # help="The name of a dev " "box.", - # ) - - # with self.argument_context("devcenter dev dev-box stop") as c: - # c.argument( - # "dev_center", - # arg_type=dev_center_type, - # ) - # c.argument( - # "project_name", - # arg_type=project_type, - # ) - # c.argument( - # "endpoint", - # arg_type=endpoint, - # ) - # c.argument( - # "user_id", - # type=str, - # help="The AAD object id of the user. If value is 'me', the identity is taken from the " - # "authentication context", - # ) - # c.argument( - # "dev_box_name", - # options_list=["--name", "-n", "--dev-box-name"], - # type=str, - # help="The name of a dev " "box.", - # ) - # c.argument( - # "hibernate", - # arg_type=get_three_state_flag(), - # help="Optional parameter to hibernate the dev box.", - # is_preview=True, - # ) - - # with self.argument_context( - # "devcenter dev dev-box delay-action", validator=validate_time - # ) as c: - # c.argument( - # "dev_center", - # arg_type=dev_center_type, - # ) - # c.argument( - # "project_name", - # arg_type=project_type, - # ) - # c.argument( - # "endpoint", - # arg_type=endpoint, - # ) - # c.argument( - # "user_id", - # type=str, - # help="The AAD object id of the user. If value is 'me', the identity is taken " - # "from the authentication context.", - # ) - # c.argument( - # "dev_box_name", - # options_list=["--name", "-n", "--dev-box-name"], - # type=str, - # help="The name of a dev " "box.", - # ) - # c.argument( - # "action_name", - # type=str, - # help="The name of an action that will take place on a dev box.", - # ) - # c.argument( - # "delay_time", - # help="The delayed timespan from the scheduled action time. Format HH:MM", - # ) - - # with self.argument_context( - # "devcenter dev dev-box delay-all-actions", validator=validate_time - # ) as c: - # c.argument( - # "dev_center", - # arg_type=dev_center_type, - # ) - # c.argument( - # "project_name", - # arg_type=project_type, - # ) - # c.argument( - # "endpoint", - # arg_type=endpoint, - # ) - # c.argument( - # "user_id", - # type=str, - # help="The AAD object id of the user. If value is 'me', the identity is taken " - # "from the authentication context.", - # ) - # c.argument( - # "dev_box_name", - # options_list=["--name", "-n", "--dev-box-name"], - # type=str, - # help="The name of a dev " "box.", - # ) - # c.argument( - # "delay_time", - # help="The delayed timespan from the earliest scheduled time of all actions. Format HH:MM", - # ) - - # with self.argument_context("devcenter dev dev-box list-action") as c: - # c.argument( - # "dev_center", - # arg_type=dev_center_type, - # ) - # c.argument( - # "project_name", - # arg_type=project_type, - # ) - # c.argument( - # "endpoint", - # arg_type=endpoint, - # ) - # c.argument( - # "user_id", - # type=str, - # help="The AAD object id of the user. If value is 'me', the identity is taken " - # "from the authentication context.", - # ) - # c.argument( - # "dev_box_name", - # options_list=["--name", "-n", "--dev-box-name"], - # type=str, - # help="The name of a dev " "box.", - # ) - - # with self.argument_context("devcenter dev dev-box show-action") as c: - # c.argument( - # "dev_center", - # arg_type=dev_center_type, - # ) - # c.argument( - # "project_name", - # arg_type=project_type, - # ) - # c.argument( - # "endpoint", - # arg_type=endpoint, - # ) - # c.argument( - # "user_id", - # type=str, - # help="The AAD object id of the user. If value is 'me', the identity is taken " - # "from the authentication context.", - # ) - # c.argument( - # "dev_box_name", - # options_list=["--name", "-n", "--dev-box-name"], - # type=str, - # help="The name of a dev " "box.", - # ) - # c.argument( - # "action_name", - # type=str, - # help="The name of an action that will take place on a dev box.", - # ) - - # with self.argument_context("devcenter dev dev-box skip-action") as c: - # c.argument( - # "dev_center", - # arg_type=dev_center_type, - # ) - # c.argument( - # "project_name", - # arg_type=project_type, - # ) - # c.argument( - # "endpoint", - # arg_type=endpoint, - # ) - # c.argument( - # "user_id", - # type=str, - # help="The AAD object id of the user. If value is 'me', the identity is taken " - # "from the authentication context.", - # ) - # c.argument( - # "dev_box_name", - # options_list=["--name", "-n", "--dev-box-name"], - # type=str, - # help="The name of a dev " "box.", - # ) - # c.argument( - # "action_name", - # type=str, - # help="The name of an action that will take place on a dev box.", - # ) - - # with self.argument_context("devcenter dev environment list") as c: - # c.argument( - # "dev_center", - # arg_type=dev_center_type, - # ) - # c.argument( - # "project_name", - # arg_type=project_type, - # ) - # c.argument( - # "endpoint", - # arg_type=endpoint, - # ) - # c.argument( - # "user_id", - # type=str, - # help="The AAD object id of the user. If value is 'me', the identity is taken " - # "from the authentication context.", - # ) - - # with self.argument_context("devcenter dev environment show") as c: - # c.argument( - # "dev_center", - # arg_type=dev_center_type, - # ) - # c.argument( - # "project_name", - # arg_type=project_type, - # ) - # c.argument( - # "endpoint", - # arg_type=endpoint, - # ) - # c.argument( - # "user_id", - # type=str, - # help="The AAD object id of the user. If value is 'me', the identity is taken from the " - # "authentication context", - # ) - # c.argument( - # "environment_name", - # options_list=["--name", "-n", "--environment-name"], - # type=str, - # help="The name " "of the environment.", - # ) - - # with self.argument_context("devcenter dev environment create") as c: - # c.argument( - # "dev_center", - # arg_type=dev_center_type, - # ) - # c.argument( - # "project_name", - # arg_type=project_type, - # ) - # c.argument( - # "endpoint", - # arg_type=endpoint, - # ) - # c.argument( - # "user_id", - # type=str, - # help="The AAD object id of the user. If value is 'me', the identity is taken " - # "from the authentication context.", - # ) - # c.argument( - # "environment_name", - # options_list=["--name", "-n", "--environment-name"], - # type=str, - # help="The name " "of the environment.", - # ) - # c.argument( - # "parameters", - # type=validate_file_or_dict, - # help="Parameters object for the environment. Expected " - # "value: json-string/json-file/@json-file.", - # ) - # c.argument("environment_type", type=str, help="Environment type.") - # c.argument("catalog_name", type=str, help="Name of the catalog.") - # c.argument( - # "environment_definition_name", - # options_list=["-e", "--environment-definition-name"], - # type=str, - # help="Name of the environment definition.", - # ) - - # with self.argument_context("devcenter dev environment update") as c: - # c.argument( - # "dev_center", - # arg_type=dev_center_type, - # ) - # c.argument( - # "project_name", - # arg_type=project_type, - # ) - # c.argument( - # "endpoint", - # arg_type=endpoint, - # ) - # c.argument( - # "user_id", - # type=str, - # help="The AAD object id of the user. If value is 'me', the identity is taken " - # "from the authentication context.", - # ) - # c.argument( - # "environment_name", - # options_list=["--name", "-n", "--environment-name"], - # type=str, - # help="The name " "of the environment.", - # ) - # c.argument( - # "parameters", - # type=validate_file_or_dict, - # help="Parameters object for the environment. Expected " - # "value: json-string/json-file/@json-file.", - # ) - - # with self.argument_context("devcenter dev environment deploy") as c: - # c.argument( - # "dev_center", - # arg_type=dev_center_type, - # ) - # c.argument( - # "project_name", - # arg_type=project_type, - # ) - # c.argument( - # "endpoint", - # arg_type=endpoint, - # ) - # c.argument( - # "user_id", - # type=str, - # help="The AAD object id of the user. If value is 'me', the identity is taken " - # "from the authentication context.", - # ) - # c.argument( - # "environment_name", - # options_list=["--name", "-n", "--environment-name"], - # type=str, - # help="The name " "of the environment.", - # ) - # c.argument( - # "parameters", - # type=validate_file_or_dict, - # help="Parameters object for the environment. Expected " - # "value: json-string/json-file/@json-file.", - # ) - - # with self.argument_context("devcenter dev environment delete") as c: - # c.argument( - # "dev_center", - # arg_type=dev_center_type, - # ) - # c.argument( - # "project_name", - # arg_type=project_type, - # ) - # c.argument( - # "endpoint", - # arg_type=endpoint, - # ) - # c.argument( - # "user_id", - # type=str, - # help="The AAD object id of the user. If value is 'me', the identity is taken from the " - # "authentication context", - # ) - # c.argument( - # "environment_name", - # options_list=["--name", "-n", "--environment-name"], - # type=str, - # help="The name " "of the environment.", - # ) - - # with self.argument_context("devcenter dev catalog list") as c: - # c.argument( - # "dev_center", - # arg_type=dev_center_type, - # ) - # c.argument( - # "project_name", - # arg_type=project_type, - # ) - # c.argument( - # "endpoint", - # arg_type=endpoint, - # ) - - # with self.argument_context("devcenter dev catalog show") as c: - # c.argument( - # "dev_center", - # arg_type=dev_center_type, - # ) - # c.argument( - # "project_name", - # arg_type=project_type, - # ) - # c.argument( - # "endpoint", - # arg_type=endpoint, - # ) - # c.argument( - # "catalog_name", - # options_list=["--name", "-n", "--catalog-name"], - # type=str, - # help="The name of the catalog", - # ) - - # with self.argument_context("devcenter dev environment-type list") as c: - # c.argument( - # "dev_center", - # arg_type=dev_center_type, - # ) - # c.argument( - # "project_name", - # arg_type=project_type, - # ) - # c.argument( - # "endpoint", - # arg_type=endpoint, - # ) - - # with self.argument_context("devcenter dev environment-definition list") as c: - # c.argument( - # "dev_center", - # arg_type=dev_center_type, - # ) - # c.argument( - # "project_name", - # required=True, - # arg_type=project_type, - # ) - # c.argument( - # "endpoint", - # arg_type=endpoint, - # ) - # c.argument("catalog_name", type=str, help="The name of the catalog") - - # with self.argument_context("devcenter dev environment-definition show") as c: - # c.argument( - # "dev_center", - # arg_type=dev_center_type, - # ) - # c.argument( - # "project_name", - # required=True, - # arg_type=project_type, - # ) - # c.argument( - # "endpoint", - # arg_type=endpoint, - # ) - # c.argument("catalog_name", type=str, help="The name of the catalog") - # c.argument( - # "definition_name", - # options_list=["--name", "-n", "--definition-name"], - # type=str, - # help="The name of the environment definition", - # ) + with self.argument_context("devcenter dev environment show-operation") as c: + c.argument( + "dev_center", + arg_type=dev_center_type, + ) + c.argument( + "project_name", + arg_type=project_type, + ) + c.argument( + "endpoint", + arg_type=endpoint, + ) + c.argument( + "user_id", + type=str, + help="The AAD object id of the user. If value is 'me', the identity is taken from the " + "authentication context", + ) + c.argument( + "environment_name", + options_list=["--name", "-n", "--environment-name"], + type=str, + help="The name " "of the environment.", + ) + c.argument( + "operation_id", + type=str, + help="The id of the operation on a dev box.", + ) diff --git a/src/devcenter/azext_devcenter/_validators.py b/src/devcenter/azext_devcenter/_validators.py index 178715c94f2..18cdd4d34a6 100644 --- a/src/devcenter/azext_devcenter/_validators.py +++ b/src/devcenter/azext_devcenter/_validators.py @@ -76,9 +76,9 @@ def validate_endpoint(endpoint, dev_center): def validate_env_name_already_exists(env_iterator, name, user_id, project): for env in env_iterator: - if env.name.casefold() == name.casefold(): + if env["name"].casefold() == name.casefold(): if user_id == "me": - user_id = env.user + user_id = env["user"] 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) diff --git a/src/devcenter/azext_devcenter/commands.py b/src/devcenter/azext_devcenter/commands.py index 4050d5b0dbd..6a15a64d306 100644 --- a/src/devcenter/azext_devcenter/commands.py +++ b/src/devcenter/azext_devcenter/commands.py @@ -10,9 +10,7 @@ from azext_devcenter._client_factory import ( cf_dev_center_dp, cf_dev_boxes_dp, - cf_dev_box_operations_dp, cf_environments_dp, - cf_environment_operations_dp ) from .custom import ( AttachedNetworkCreate, @@ -210,13 +208,6 @@ def load_command_table(self, _): client_factory=cf_dev_boxes_dp, ) - dev_box_operations_dp = CliCommandType( - operations_tmpl=( - "azext_devcenter.vendored_sdks.devcenter_dataplane.operations._operations#DevBoxOperationsOperations.{}" - ), - client_factory=cf_dev_box_operations_dp, - ) - environments_dp = CliCommandType( operations_tmpl=( "azext_devcenter.vendored_sdks.devcenter_dataplane.operations._operations#EnvironmentsOperations.{}" @@ -224,11 +215,6 @@ def load_command_table(self, _): client_factory=cf_environments_dp, ) - environment_operations_dp = CliCommandType( - operations_tmpl="azext_devcenter.vendored_sdks.devcenter_dataplane.operations._operations#EnvironmentOperationsOperations.{}", - client_factory=cf_environment_operations_dp, - ) - with self.command_group("devcenter"): pass @@ -243,62 +229,67 @@ def load_command_table(self, _): g.custom_command("list", "devcenter_pool_list_dp") g.custom_show_command("show", "devcenter_pool_show_dp") - with self.command_group("devcenter dev dev-box") as g: - g.custom_command("list", "devcenter_dev_box_list") - g.custom_show_command("show", "devcenter_dev_box_show") - g.custom_command("create", "devcenter_dev_box_create", supports_no_wait=True) - # g.custom_command( - # "delete", - # "devcenter_dev_box_delete", - # supports_no_wait=True, - # confirmation=True, - # ) - # g.custom_command( - # "show-remote-connection", "devcenter_dev_box_get_remote_connection" - # ) - # g.custom_command("start", "devcenter_dev_box_start", supports_no_wait=True) - # g.custom_command("restart", "devcenter_dev_box_restart", supports_no_wait=True) - # g.custom_command("stop", "devcenter_dev_box_stop", supports_no_wait=True) - # g.custom_command("delay-action", "devcenter_dev_box_delay_action") - # g.custom_command("delay-all-actions", "devcenter_dev_box_delay_all_actions") - # g.custom_command("list-action", "devcenter_dev_box_list_action") - # g.custom_command("show-action", "devcenter_dev_box_show_action") - # g.custom_command("skip-action", "devcenter_dev_box_skip_action") - - # with self.command_group("devcenter dev environment", devcenter_environment_dp) as g: - # g.custom_command("list", "devcenter_environment_list") - # g.custom_show_command("show", "devcenter_environment_show") - # g.custom_command( - # "create", "devcenter_environment_create", supports_no_wait=True - # ) - # g.custom_command( - # "update", "devcenter_environment_update", supports_no_wait=True - # ) - # g.custom_command( - # "deploy", "devcenter_environment_update", supports_no_wait=True - # ) - # g.custom_command( - # "delete", - # "devcenter_environment_delete", - # supports_no_wait=True, - # confirmation=True, - # ) - - # with self.command_group( - # "devcenter dev environment-type", devcenter_environment_type_dp - # ) as g: - # g.custom_command("list", "devcenter_environment_type_list_dp") - with self.command_group("devcenter dev schedule", dev_boxes_dp) as g: g.custom_command("list", "devcenter_schedule_list_dp") g.custom_show_command("show", "devcenter_schedule_show_dp") - # with self.command_group("devcenter dev catalog", devcenter_catalog_dp) as g: - # g.custom_command("list", "devcenter_catalog_list_dp") - # g.custom_show_command("show", "devcenter_catalog_show_dp") - - # with self.command_group( - # "devcenter dev environment-definition", devcenter_environment_definition_dp - # ) as g: - # g.custom_command("list", "devcenter_environment_definition_list_dp") - # g.custom_show_command("show", "devcenter_environment_definition_show_dp") + with self.command_group("devcenter dev dev-box") as g: + g.custom_command("list", "devcenter_dev_box_list") + g.custom_show_command("show", "devcenter_dev_box_show") + g.custom_command("create", "devcenter_dev_box_create", supports_no_wait=True) + g.custom_command( + "delete", + "devcenter_dev_box_delete", + supports_no_wait=True, + confirmation=True, + ) + g.custom_command("start", "devcenter_dev_box_start", supports_no_wait=True) + g.custom_command("stop", "devcenter_dev_box_stop", supports_no_wait=True) + g.custom_command("restart", "devcenter_dev_box_restart", supports_no_wait=True) + g.custom_command("repair", "devcenter_dev_box_repair", supports_no_wait=True) + g.custom_command( + "show-remote-connection", "devcenter_dev_box_get_remote_connection" + ) + g.custom_command("list-action", "devcenter_dev_box_list_action") + g.custom_command("show-action", "devcenter_dev_box_show_action") + g.custom_command("skip-action", "devcenter_dev_box_skip_action") + g.custom_command("delay-action", "devcenter_dev_box_delay_action") + g.custom_command("delay-all-actions", "devcenter_dev_box_delay_all_actions") + g.custom_command("list-operation", "devcenter_dev_box_list_operation") + g.custom_command("show-operation", "devcenter_dev_box_show_operation") + + with self.command_group("devcenter dev environment") as g: + g.custom_command("list", "devcenter_environment_list") + g.custom_show_command("show", "devcenter_environment_show") + g.custom_command( + "create", "devcenter_environment_create", supports_no_wait=True + ) + g.custom_command( + "update", "devcenter_environment_update", supports_no_wait=True + ) + g.custom_command( + "deploy", "devcenter_environment_update", supports_no_wait=True + ) + g.custom_command( + "delete", + "devcenter_environment_delete", + supports_no_wait=True, + confirmation=True, + ) + g.custom_command("list-operation", "devcenter_environment_operation_list") + g.custom_command("show-operation", "devcenter_environment_operation_show") + + with self.command_group("devcenter dev catalog", environments_dp) as g: + g.custom_command("list", "devcenter_catalog_list_dp") + g.custom_show_command("show", "devcenter_catalog_show_dp") + + with self.command_group( + "devcenter dev environment-definition", environments_dp + ) as g: + g.custom_command("list", "devcenter_environment_definition_list_dp") + g.custom_show_command("show", "devcenter_environment_definition_show_dp") + + with self.command_group( + "devcenter dev environment-type", environments_dp + ) as g: + g.custom_command("list", "devcenter_environment_type_list_dp") diff --git a/src/devcenter/azext_devcenter/custom.py b/src/devcenter/azext_devcenter/custom.py index 4f380a44228..f8bb6de3d78 100644 --- a/src/devcenter/azext_devcenter/custom.py +++ b/src/devcenter/azext_devcenter/custom.py @@ -4,6 +4,7 @@ # -------------------------------------------------------------------------------------------- # pylint: disable=protected-access +from datetime import datetime from azure.cli.core.aaz import register_callback from azure.cli.core.azclierror import ResourceNotFoundError from azure.cli.core.util import sdk_no_wait @@ -627,7 +628,10 @@ def devcenter_schedule_show_dp( cf_dataplane = cf_devcenter_dataplane( cmd.cli_ctx, endpoint, dev_center, project_name ) - return cf_dataplane.dev_boxes.get_schedule_by_pool(project_name=project_name, pool_name=pool_name, schedule_name="default") + return cf_dataplane.dev_boxes.get_schedule_by_pool( + project_name=project_name, + pool_name=pool_name, + schedule_name="default") def devcenter_dev_box_list( @@ -637,7 +641,7 @@ def devcenter_dev_box_list( cmd.cli_ctx, endpoint, dev_center, project_name ) if project_name is not None and user_id is not None: - return cf_dataplane.dev_boxes.list_dev_boxes_by_user(project_name=project_name,user_id=user_id) + return cf_dataplane.dev_boxes.list_dev_boxes_by_user(project_name=project_name, user_id=user_id) if user_id is not None: return cf_dataplane.dev_center.list_all_dev_boxes_by_user(user_id=user_id) return cf_dataplane.dev_center.list_all_dev_boxes() @@ -649,7 +653,10 @@ def devcenter_dev_box_show( cf_dataplane = cf_devcenter_dataplane( cmd.cli_ctx, endpoint, dev_center, project_name ) - return cf_dataplane.dev_boxes.get_dev_box_by_user(project_name=project_name,user_id=user_id, dev_box_name=dev_box_name) + return cf_dataplane.dev_boxes.get_dev_box_by_user( + project_name=project_name, + user_id=user_id, + dev_box_name=dev_box_name) def devcenter_dev_box_create( @@ -677,358 +684,449 @@ def devcenter_dev_box_create( ) -# def devcenter_dev_box_delete( -# cmd, -# dev_box_name, -# project_name, -# user_id="me", -# no_wait=False, -# dev_center=None, -# endpoint=None, -# ): -# cf_dataplane = cf_devcenter_dataplane( -# cmd.cli_ctx, endpoint, dev_center, project_name -# ) -# return sdk_no_wait( -# no_wait, -# cf_dataplane.dev_box.begin_delete, -# user_id=user_id, -# dev_box_name=dev_box_name, -# ) - - -# def devcenter_dev_box_get_remote_connection( -# cmd, project_name, dev_box_name, user_id="me", dev_center=None, endpoint=None -# ): -# cf_dataplane = cf_devcenter_dataplane( -# cmd.cli_ctx, endpoint, dev_center, project_name -# ) -# return cf_dataplane.dev_box.get_remote_connection( -# user_id=user_id, dev_box_name=dev_box_name -# ) - - -# def devcenter_dev_box_start( -# cmd, -# project_name, -# dev_box_name, -# user_id="me", -# no_wait=False, -# dev_center=None, -# endpoint=None, -# ): -# cf_dataplane = cf_devcenter_dataplane( -# cmd.cli_ctx, endpoint, dev_center, project_name -# ) -# return sdk_no_wait( -# no_wait, -# cf_dataplane.dev_box.begin_start, -# user_id=user_id, -# dev_box_name=dev_box_name, -# ) - - -# def devcenter_dev_box_restart( -# cmd, -# project_name, -# dev_box_name, -# user_id="me", -# no_wait=False, -# dev_center=None, -# endpoint=None, -# ): -# cf_dataplane = cf_devcenter_dataplane( -# cmd.cli_ctx, endpoint, dev_center, project_name -# ) -# return sdk_no_wait( -# no_wait, -# cf_dataplane.dev_box.begin_restart, -# user_id=user_id, -# dev_box_name=dev_box_name, -# ) - - -# def devcenter_dev_box_stop( -# cmd, -# dev_box_name, -# project_name, -# no_wait=False, -# hibernate=None, -# user_id="me", -# dev_center=None, -# endpoint=None, -# ): -# cf_dataplane = cf_devcenter_dataplane( -# cmd.cli_ctx, endpoint, dev_center, project_name -# ) -# return sdk_no_wait( -# no_wait, -# cf_dataplane.dev_box.begin_stop, -# user_id=user_id, -# dev_box_name=dev_box_name, -# hibernate=hibernate, -# ) - - -# def devcenter_dev_box_delay_action( -# cmd, -# project_name, -# dev_box_name, -# delay_time, -# action_name, -# user_id="me", -# dev_center=None, -# endpoint=None, -# ): -# cf_dataplane = cf_devcenter_dataplane( -# cmd.cli_ctx, endpoint, dev_center, project_name -# ) -# upcoming_action = cf_dataplane.dev_box.get_action( -# user_id=user_id, -# dev_box_name=dev_box_name, -# action_name=action_name, -# ) - -# delayed_time = get_delayed_time(delay_time, upcoming_action.next.scheduled_time) - -# return cf_dataplane.dev_box.delay_action( -# user_id=user_id, -# dev_box_name=dev_box_name, -# action_name=action_name, -# until=delayed_time, -# ) - - -# def devcenter_dev_box_delay_all_actions( -# cmd, -# project_name, -# dev_box_name, -# delay_time, -# user_id="me", -# dev_center=None, -# endpoint=None, -# ): -# cf_dataplane = cf_devcenter_dataplane( -# cmd.cli_ctx, endpoint, dev_center, project_name -# ) - -# actions = cf_dataplane.dev_box.list_actions( -# user_id=user_id, dev_box_name=dev_box_name -# ) -# earliest_time = get_earliest_time(actions) -# if earliest_time is None: -# raise ResourceNotFoundError("There are no scheduled actions for this dev box.") - -# delayed_time = get_delayed_time(delay_time, earliest_time) - -# return cf_dataplane.dev_box.delay_actions( -# user_id=user_id, -# dev_box_name=dev_box_name, -# until=delayed_time, -# ) - - -# def devcenter_dev_box_list_action( -# cmd, project_name, dev_box_name, user_id="me", dev_center=None, endpoint=None -# ): -# cf_dataplane = cf_devcenter_dataplane( -# cmd.cli_ctx, endpoint, dev_center, project_name -# ) -# return cf_dataplane.dev_box.list_actions(user_id=user_id, dev_box_name=dev_box_name) - - -# def devcenter_dev_box_show_action( -# cmd, -# project_name, -# dev_box_name, -# action_name, -# user_id="me", -# dev_center=None, -# endpoint=None, -# ): -# cf_dataplane = cf_devcenter_dataplane( -# cmd.cli_ctx, endpoint, dev_center, project_name -# ) -# return cf_dataplane.dev_box.get_action( -# user_id=user_id, -# dev_box_name=dev_box_name, -# action_name=action_name, -# ) - - -# def devcenter_dev_box_skip_action( -# cmd, -# project_name, -# dev_box_name, -# action_name, -# user_id="me", -# dev_center=None, -# endpoint=None, -# ): -# cf_dataplane = cf_devcenter_dataplane( -# cmd.cli_ctx, endpoint, dev_center, project_name -# ) -# return cf_dataplane.dev_box.skip_action( -# user_id=user_id, -# dev_box_name=dev_box_name, -# action_name=action_name, -# ) - - -# def devcenter_environment_list( -# cmd, project_name, user_id=None, dev_center=None, endpoint=None -# ): -# cf_dataplane = cf_devcenter_dataplane( -# cmd.cli_ctx, endpoint, dev_center, project_name -# ) -# if user_id is not None: -# return cf_dataplane.environments.list_by_project_by_user(user_id=user_id) -# return cf_dataplane.environments.list_by_project() - - -# def devcenter_environment_show( -# cmd, project_name, environment_name, user_id="me", dev_center=None, endpoint=None -# ): -# cf_dataplane = cf_devcenter_dataplane( -# cmd.cli_ctx, endpoint, dev_center, project_name -# ) -# return cf_dataplane.environments.get( -# user_id=user_id, environment_name=environment_name -# ) - - -# def devcenter_environment_create( -# cmd, -# environment_name, -# environment_type, -# project_name, -# catalog_name, -# environment_definition_name, -# parameters=None, -# no_wait=False, -# user_id="me", -# dev_center=None, -# endpoint=None, -# ): -# cf_dataplane = cf_devcenter_dataplane( -# cmd.cli_ctx, endpoint, dev_center, project_name -# ) -# environments_iterator = cf_dataplane.environments.list_by_project_by_user( -# user_id=user_id -# ) -# validate_env_name_already_exists( -# environments_iterator, environment_name, user_id, project_name -# ) -# body = {} -# if parameters is not None: -# body["parameters"] = parameters -# body["environment_type"] = environment_type -# body["catalog_name"] = catalog_name -# body["environment_definition_name"] = environment_definition_name -# return sdk_no_wait( -# no_wait, -# cf_dataplane.environments.begin_create_or_replace, -# user_id=user_id, -# environment_name=environment_name, -# body=body, -# ) - - -# def devcenter_environment_update( -# cmd, -# environment_name, -# project_name, -# parameters=None, -# no_wait=False, -# user_id="me", -# dev_center=None, -# endpoint=None, -# ): -# cf_dataplane = cf_devcenter_dataplane( -# cmd.cli_ctx, endpoint, dev_center, project_name -# ) -# environment = cf_dataplane.environments.get( -# user_id=user_id, environment_name=environment_name -# ) -# body = {} -# if parameters is not None: -# body["parameters"] = parameters -# body["environment_type"] = environment.environment_type -# body["catalog_name"] = environment.catalog_name -# body["environment_definition_name"] = environment.environment_definition_name -# return sdk_no_wait( -# no_wait, -# cf_dataplane.environments.begin_create_or_replace, -# user_id=user_id, -# environment_name=environment_name, -# body=body, -# ) - - -# def devcenter_environment_delete( -# cmd, -# environment_name, -# project_name, -# no_wait=False, -# user_id="me", -# dev_center=None, -# endpoint=None, -# ): -# cf_dataplane = cf_devcenter_dataplane( -# cmd.cli_ctx, endpoint, dev_center, project_name -# ) -# return sdk_no_wait( -# no_wait, -# cf_dataplane.environments.begin_delete, -# user_id=user_id, -# environment_name=environment_name, -# ) - - -# def devcenter_environment_type_list_dp( -# cmd, project_name, dev_center=None, endpoint=None -# ): -# cf_dataplane = cf_devcenter_dataplane( -# cmd.cli_ctx, endpoint, dev_center, project_name -# ) -# return cf_dataplane.environment_type.list() - - -# def devcenter_catalog_list_dp(cmd, project_name, dev_center=None, endpoint=None): -# cf_dataplane = cf_devcenter_dataplane( -# cmd.cli_ctx, endpoint, dev_center, project_name -# ) -# return cf_dataplane.catalogs.list() - - -# def devcenter_catalog_show_dp( -# cmd, project_name, catalog_name, dev_center=None, endpoint=None -# ): -# cf_dataplane = cf_devcenter_dataplane( -# cmd.cli_ctx, endpoint, dev_center, project_name -# ) -# return cf_dataplane.catalogs.get(catalog_name=catalog_name) - - -# def devcenter_environment_definition_list_dp( -# cmd, project_name, dev_center=None, endpoint=None, catalog_name=None -# ): -# cf_dataplane = cf_devcenter_dataplane( -# cmd.cli_ctx, endpoint, dev_center, project_name -# ) -# if catalog_name is not None: -# return cf_dataplane.environment_definitions.list_by_catalog( -# catalog_name=catalog_name -# ) -# return cf_dataplane.environment_definitions.list() - - -# def devcenter_environment_definition_show_dp( -# cmd, catalog_name, definition_name, project_name, dev_center=None, endpoint=None -# ): -# cf_dataplane = cf_devcenter_dataplane( -# cmd.cli_ctx, endpoint, dev_center, project_name -# ) -# return cf_dataplane.environment_definitions.get( -# catalog_name=catalog_name, definition_name=definition_name -# ) +def devcenter_dev_box_delete( + cmd, + dev_box_name, + project_name, + user_id="me", + no_wait=False, + dev_center=None, + endpoint=None, +): + cf_dataplane = cf_devcenter_dataplane( + cmd.cli_ctx, endpoint, dev_center, project_name + ) + return sdk_no_wait( + no_wait, + cf_dataplane.dev_boxes.begin_delete_dev_box, + project_name=project_name, + user_id=user_id, + dev_box_name=dev_box_name, + ) + + +def devcenter_dev_box_start( + cmd, + project_name, + dev_box_name, + user_id="me", + no_wait=False, + dev_center=None, + endpoint=None, +): + cf_dataplane = cf_devcenter_dataplane( + cmd.cli_ctx, endpoint, dev_center, project_name + ) + return sdk_no_wait( + no_wait, + cf_dataplane.dev_boxes.begin_start_dev_box, + project_name=project_name, + user_id=user_id, + dev_box_name=dev_box_name, + ) + + +def devcenter_dev_box_stop( + cmd, + dev_box_name, + project_name, + no_wait=False, + hibernate=None, + user_id="me", + dev_center=None, + endpoint=None, +): + cf_dataplane = cf_devcenter_dataplane( + cmd.cli_ctx, endpoint, dev_center, project_name + ) + return sdk_no_wait( + no_wait, + cf_dataplane.dev_boxes.begin_stop_dev_box, + project_name=project_name, + user_id=user_id, + dev_box_name=dev_box_name, + hibernate=hibernate, + ) + + +def devcenter_dev_box_restart( + cmd, + project_name, + dev_box_name, + user_id="me", + no_wait=False, + dev_center=None, + endpoint=None, +): + cf_dataplane = cf_devcenter_dataplane( + cmd.cli_ctx, endpoint, dev_center, project_name + ) + return sdk_no_wait( + no_wait, + cf_dataplane.dev_boxes.begin_restart_dev_box, + project_name=project_name, + user_id=user_id, + dev_box_name=dev_box_name, + ) + + +def devcenter_dev_box_repair( + cmd, + project_name, + dev_box_name, + user_id="me", + no_wait=False, + dev_center=None, + endpoint=None, +): + cf_dataplane = cf_devcenter_dataplane( + cmd.cli_ctx, endpoint, dev_center, project_name + ) + return sdk_no_wait( + no_wait, + cf_dataplane.dev_boxes.begin_repair_dev_box, + project_name=project_name, + user_id=user_id, + dev_box_name=dev_box_name, + ) + + +def devcenter_dev_box_get_remote_connection( + cmd, project_name, dev_box_name, user_id="me", dev_center=None, endpoint=None +): + cf_dataplane = cf_devcenter_dataplane( + cmd.cli_ctx, endpoint, dev_center, project_name + ) + return cf_dataplane.dev_boxes.get_remote_connection( + project_name=project_name, user_id=user_id, dev_box_name=dev_box_name + ) + + +def devcenter_dev_box_list_action( + cmd, project_name, dev_box_name, user_id="me", dev_center=None, endpoint=None +): + cf_dataplane = cf_devcenter_dataplane( + cmd.cli_ctx, endpoint, dev_center, project_name + ) + return cf_dataplane.dev_boxes.list_actions(project_name=project_name, user_id=user_id, dev_box_name=dev_box_name) + + +def devcenter_dev_box_show_action( + cmd, + project_name, + dev_box_name, + action_name, + user_id="me", + dev_center=None, + endpoint=None, +): + cf_dataplane = cf_devcenter_dataplane( + cmd.cli_ctx, endpoint, dev_center, project_name + ) + + return cf_dataplane.dev_boxes.get_action( + project_name=project_name, + user_id=user_id, + dev_box_name=dev_box_name, + action_name=action_name, + ) + + +def devcenter_dev_box_skip_action( + cmd, + project_name, + dev_box_name, + action_name, + user_id="me", + dev_center=None, + endpoint=None, +): + cf_dataplane = cf_devcenter_dataplane( + cmd.cli_ctx, endpoint, dev_center, project_name + ) + return cf_dataplane.dev_boxes.skip_action( + project_name=project_name, + user_id=user_id, + dev_box_name=dev_box_name, + action_name=action_name, + ) + + +def devcenter_dev_box_delay_action( + cmd, + project_name, + dev_box_name, + delay_time, + action_name, + user_id="me", + dev_center=None, + endpoint=None, +): + cf_dataplane = cf_devcenter_dataplane( + cmd.cli_ctx, endpoint, dev_center, project_name + ) + upcoming_action = cf_dataplane.dev_boxes.get_action( + project_name=project_name, + user_id=user_id, + dev_box_name=dev_box_name, + action_name=action_name, + ) + + upcoming_action_time = upcoming_action["next"]["scheduledTime"] + action_time = datetime.strptime(upcoming_action_time, "%Y-%m-%dT%H:%M:%S.%fZ") + + delayed_time = get_delayed_time(delay_time, action_time) + + return cf_dataplane.dev_boxes.delay_action( + project_name=project_name, + user_id=user_id, + dev_box_name=dev_box_name, + action_name=action_name, + until=delayed_time, + ) + + +def devcenter_dev_box_delay_all_actions( + cmd, + project_name, + dev_box_name, + delay_time, + user_id="me", + dev_center=None, + endpoint=None, +): + cf_dataplane = cf_devcenter_dataplane( + cmd.cli_ctx, endpoint, dev_center, project_name + ) + + actions = cf_dataplane.dev_boxes.list_actions( + project_name=project_name, user_id=user_id, dev_box_name=dev_box_name + ) + earliest_time = get_earliest_time(actions) + if earliest_time is None: + raise ResourceNotFoundError("There are no scheduled actions for this dev box.") + + delayed_time = get_delayed_time(delay_time, earliest_time) + + return cf_dataplane.dev_boxes.delay_actions( + project_name=project_name, + user_id=user_id, + dev_box_name=dev_box_name, + until=delayed_time, + ) + + +def devcenter_dev_box_list_operation( + cmd, project_name, dev_box_name, user_id="me", dev_center=None, endpoint=None +): + cf_dataplane = cf_devcenter_dataplane( + cmd.cli_ctx, endpoint, dev_center, project_name + ) + return cf_dataplane.dev_box_operations.list(project_name=project_name, user_id=user_id, dev_box_name=dev_box_name) + + +def devcenter_dev_box_show_operation( + cmd, + project_name, + dev_box_name, + operation_id, + user_id="me", + dev_center=None, + endpoint=None, +): + cf_dataplane = cf_devcenter_dataplane( + cmd.cli_ctx, endpoint, dev_center, project_name + ) + return cf_dataplane.dev_box_operations.get( + project_name=project_name, + user_id=user_id, + dev_box_name=dev_box_name, + operation_id=operation_id, + ) + + +def devcenter_environment_list( + cmd, project_name, user_id=None, dev_center=None, endpoint=None +): + cf_dataplane = cf_devcenter_dataplane( + cmd.cli_ctx, endpoint, dev_center, project_name + ) + + if user_id is not None: + return cf_dataplane.environments.list_environments_by_user(project_name=project_name, user_id=user_id) + return cf_dataplane.environments.list_environments(project_name=project_name) + + +def devcenter_environment_show( + cmd, project_name, environment_name, user_id="me", dev_center=None, endpoint=None +): + cf_dataplane = cf_devcenter_dataplane( + cmd.cli_ctx, endpoint, dev_center, project_name + ) + + return cf_dataplane.environments.get_environment_by_user( + project_name=project_name, user_id=user_id, environment_name=environment_name + ) + + +def devcenter_environment_create( + cmd, + environment_name, + environment_type, + project_name, + catalog_name, + environment_definition_name, + parameters=None, + no_wait=False, + user_id="me", + dev_center=None, + endpoint=None, +): + cf_dataplane = cf_devcenter_dataplane( + cmd.cli_ctx, endpoint, dev_center, project_name + ) + environments_iterator = cf_dataplane.environments.list_environments_by_user( + project_name=project_name, user_id=user_id + ) + validate_env_name_already_exists( + environments_iterator, environment_name, user_id, project_name + ) + body = {} + if parameters is not None: + body["parameters"] = parameters + body["environmentType"] = environment_type + body["catalogName"] = catalog_name + body["environmentDefinitionName"] = environment_definition_name + return sdk_no_wait( + no_wait, + cf_dataplane.environments.begin_create_or_replace_environment, + project_name=project_name, + user_id=user_id, + environment_name=environment_name, + body=body, + ) + + +def devcenter_environment_update( + cmd, + environment_name, + project_name, + parameters=None, + no_wait=False, + user_id="me", + dev_center=None, + endpoint=None, +): + cf_dataplane = cf_devcenter_dataplane( + cmd.cli_ctx, endpoint, dev_center, project_name + ) + environment = cf_dataplane.environments.get_environment_by_user( + project_name=project_name, user_id=user_id, environment_name=environment_name + ) + body = {} + if parameters is not None: + body["parameters"] = parameters + body["environmentType"] = environment["environmentType"] + body["catalogName"] = environment["catalogName"] + body["environmentDefinitionName"] = environment["environmentDefinitionName"] + return sdk_no_wait( + no_wait, + cf_dataplane.environments.begin_create_or_replace_environment, + project_name=project_name, + user_id=user_id, + environment_name=environment_name, + body=body, + ) + + +def devcenter_environment_delete( + cmd, + environment_name, + project_name, + no_wait=False, + user_id="me", + dev_center=None, + endpoint=None, +): + cf_dataplane = cf_devcenter_dataplane( + cmd.cli_ctx, endpoint, dev_center, project_name + ) + return sdk_no_wait( + no_wait, + cf_dataplane.environments.begin_delete_environment, + project_name=project_name, + user_id=user_id, + environment_name=environment_name, + ) + + +def devcenter_catalog_list_dp(cmd, project_name, dev_center=None, endpoint=None): + cf_dataplane = cf_devcenter_dataplane( + cmd.cli_ctx, endpoint, dev_center, project_name + ) + return cf_dataplane.environments.list_catalogs_by_project(project_name=project_name) + + +def devcenter_catalog_show_dp( + cmd, project_name, catalog_name, dev_center=None, endpoint=None +): + cf_dataplane = cf_devcenter_dataplane( + cmd.cli_ctx, endpoint, dev_center, project_name + ) + return cf_dataplane.environments.get_catalog(project_name=project_name, catalog_name=catalog_name) + + +def devcenter_environment_definition_list_dp( + cmd, project_name, dev_center=None, endpoint=None, catalog_name=None +): + cf_dataplane = cf_devcenter_dataplane( + cmd.cli_ctx, endpoint, dev_center, project_name + ) + if catalog_name is not None: + return cf_dataplane.environments.list_environment_definitions_by_catalog( + project_name=project_name, catalog_name=catalog_name + ) + return cf_dataplane.environments.list_environment_definitions_by_project(project_name=project_name) + + +def devcenter_environment_definition_show_dp( + cmd, catalog_name, definition_name, project_name, dev_center=None, endpoint=None +): + cf_dataplane = cf_devcenter_dataplane( + cmd.cli_ctx, endpoint, dev_center, project_name + ) + return cf_dataplane.environments.get_environment_definition( + project_name=project_name, catalog_name=catalog_name, definition_name=definition_name + ) + + +def devcenter_environment_type_list_dp( + cmd, project_name, dev_center=None, endpoint=None +): + cf_dataplane = cf_devcenter_dataplane( + cmd.cli_ctx, endpoint, dev_center, project_name + ) + return cf_dataplane.environments.list_environment_types(project_name=project_name) + + +def devcenter_environment_operation_list( + cmd, project_name, environment_name, user_id="me", dev_center=None, endpoint=None +): + cf_dataplane = cf_devcenter_dataplane( + cmd.cli_ctx, endpoint, dev_center, project_name + ) + + return cf_dataplane.environment_operations.list_by_environment(project_name=project_name, + environment_name=environment_name, user_id=user_id) + + +def devcenter_environment_operation_show( + cmd, project_name, environment_name, operation_id, user_id="me", dev_center=None, endpoint=None +): + cf_dataplane = cf_devcenter_dataplane( + cmd.cli_ctx, endpoint, dev_center, project_name + ) + + return cf_dataplane.environment_operations.get_by_environment( + project_name=project_name, operation_id=operation_id, user_id=user_id, environment_name=environment_name + ) diff --git a/src/devcenter/azext_devcenter/utils.py b/src/devcenter/azext_devcenter/utils.py index 1c78689ae53..60385b073c1 100644 --- a/src/devcenter/azext_devcenter/utils.py +++ b/src/devcenter/azext_devcenter/utils.py @@ -5,7 +5,7 @@ # # -------------------------------------------------------------------------- import json -from datetime import timedelta +from datetime import (timedelta, datetime) from azure.cli.core.azclierror import ResourceNotFoundError, AzureInternalError from azure.cli.core.util import send_raw_request from azure.cli.core._profile import Profile @@ -76,8 +76,9 @@ def get_project_data(cli_ctx, dev_center_name, project_name=None): def get_earliest_time(action_iterator): earliest_time = None for action in action_iterator: - if action.next is not None: - action_time = action.next.scheduled_time + if action["next"] is not None: + action_string = action["next"]["scheduled_time"] + action_time = datetime.strptime(action_string, "%Y-%m-%dT%H:%M:%S.%fZ") if earliest_time is None or action_time < earliest_time: earliest_time = action_time return earliest_time