Skip to content

Commit

Permalink
az connectedmachine extension (Azure#1031)
Browse files Browse the repository at this point in the history
* Az cli extension for connected machines

* add code owners

* add code owners

* update name
  • Loading branch information
farehar authored and ManuInNZ committed Apr 11, 2020
1 parent 2acff04 commit b0b33da
Show file tree
Hide file tree
Showing 30 changed files with 4,775 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,6 @@

/src/peering/ @zikalino

/src/connectedmachine/ @farehar

/src/ip-group/ @haroldrandom
8 changes: 8 additions & 0 deletions src/connectedmachine/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. :changelog:
Release History
===============

0.1.0
++++++
* Initial release.
5 changes: 5 additions & 0 deletions src/connectedmachine/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Microsoft Azure CLI 'connectedmachine' Extension
==========================================

This package is for the 'connectedmachine' extension.
i.e. 'az connectedmachine'
32 changes: 32 additions & 0 deletions src/connectedmachine/azext_connectedmachine/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core import AzCommandsLoader

from azext_connectedmachine._help import helps # pylint: disable=unused-import


class ConnectedmachineCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
from azext_connectedmachine._client_factory import cf_connectedmachine
connectedmachine_custom = CliCommandType(
operations_tmpl='azext_connectedmachine.custom#{}',
client_factory=cf_connectedmachine)
super(ConnectedmachineCommandsLoader, self).__init__(cli_ctx=cli_ctx,
custom_command_type=connectedmachine_custom)

def load_command_table(self, args):
from azext_connectedmachine.commands import load_command_table
load_command_table(self, args)
return self.command_table

def load_arguments(self, command):
from azext_connectedmachine._params import load_arguments
load_arguments(self, command)


COMMAND_LOADER_CLS = ConnectedmachineCommandsLoader
11 changes: 11 additions & 0 deletions src/connectedmachine/azext_connectedmachine/_client_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------


def cf_connectedmachine(cli_ctx, *_):

from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azext_connectedmachine.vendored_sdks import HybridComputeManagementClient
return get_mgmt_service_client(cli_ctx, HybridComputeManagementClient)
28 changes: 28 additions & 0 deletions src/connectedmachine/azext_connectedmachine/_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# coding=utf-8
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from knack.help_files import helps # pylint: disable=unused-import


helps['connectedmachine'] = """
type: group
short-summary: Commands to manage Connected machines.
"""

helps['connectedmachine list'] = """
type: command
short-summary: List Connected machines.
"""

helps['connectedmachine delete'] = """
type: command
short-summary: Delete a Connected machine.
"""

helps['connectedmachine show'] = """
type: command
short-summary: Show details of a Connected machine.
"""
23 changes: 23 additions & 0 deletions src/connectedmachine/azext_connectedmachine/_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# pylint: disable=line-too-long

from knack.arguments import CLIArgumentType


def load_arguments(self, _):

from azure.cli.core.commands.parameters import tags_type
from azure.cli.core.commands.validators import get_default_location_from_resource_group

name_type = CLIArgumentType(options_list='--name', help='Name of the Connected machine.', id_part='name')

with self.argument_context('connectedmachine') as c:
c.argument('tags', tags_type)
c.argument('location', validator=get_default_location_from_resource_group)
c.argument('name', name_type, options_list=['--name', '-n'])

with self.argument_context('connectedmachine list') as c:
c.argument('name', name_type, id_part=None)
21 changes: 21 additions & 0 deletions src/connectedmachine/azext_connectedmachine/_validators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------


def example_name_or_id_validator(cmd, namespace):
# Example of a storage account name or ID validator.
# See:
# https://github.com/Azure/azure-cli/blob/dev/doc/authoring_command_modules/authoring_commands.md#supporting-name-or-id-parameters
from azure.cli.core.commands.client_factory import get_subscription_id
from msrestazure.tools import is_valid_resource_id, resource_id
if namespace.storage_account:
if not is_valid_resource_id(namespace.RESOURCE):
namespace.storage_account = resource_id(
subscription=get_subscription_id(cmd.cli_ctx),
resource_group=namespace.resource_group_name,
namespace='Microsoft.Storage',
type='storageAccounts',
name=namespace.storage_account
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"azext.isPreview": true,
"azext.minCliCoreVersion": "2.0.67",
"azext.maxCliCoreVersion": "2.1.0"
}
23 changes: 23 additions & 0 deletions src/connectedmachine/azext_connectedmachine/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

# pylint: disable=line-too-long
from azure.cli.core.commands import CliCommandType
from azext_connectedmachine._client_factory import cf_connectedmachine


def load_command_table(self, _):

connectedmachine_sdk = CliCommandType(
operations_tmpl='azext_connectedmachine.vendored_sdks.operations#MachinesOperations.{}',
client_factory=cf_connectedmachine)

with self.command_group('connectedmachine', connectedmachine_sdk, client_factory=cf_connectedmachine) as g:
g.custom_command('delete', 'delete_connectedmachine')
g.custom_command('list', 'list_connectedmachine')
g.custom_command('show', 'show_connectedmachine')

with self.command_group('connectedmachine', is_preview=True):
pass
18 changes: 18 additions & 0 deletions src/connectedmachine/azext_connectedmachine/custom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------


def list_connectedmachine(client, resource_group_name=None):
if resource_group_name:
return client.machines.list_by_resource_group(resource_group_name)
return client.machines.list_by_subscription()


def show_connectedmachine(client, resource_group_name, name):
return client.machines.get(resource_group_name, name)


def delete_connectedmachine(client, resource_group_name, name):
return client.machines.delete(resource_group_name, name)
5 changes: 5 additions & 0 deletions src/connectedmachine/azext_connectedmachine/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -----------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -----------------------------------------------------------------------------
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -----------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -----------------------------------------------------------------------------
Loading

0 comments on commit b0b33da

Please sign in to comment.