Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/portal/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/portal/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Microsoft Azure CLI 'portal' Extension
==========================================

This package is for the 'portal' extension.
i.e. 'az portal'
31 changes: 31 additions & 0 deletions src/portal/azext_portal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# --------------------------------------------------------------------------------------------
# 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 .generated._help import helps


class PortalCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
from .generated._client_factory import cf_portal
portal_custom = CliCommandType(
operations_tmpl='azext_portal.custom#{}',
client_factory=cf_portal)
super(PortalCommandsLoader, self).__init__(cli_ctx=cli_ctx,
custom_command_type=portal_custom)

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

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


COMMAND_LOADER_CLS = PortalCommandsLoader
12 changes: 12 additions & 0 deletions src/portal/azext_portal/action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# pylint: disable=wildcard-import
# pylint: disable=unused-wildcard-import

from .generated.action import * # noqa: F403
try:
from .manual.action import * # noqa: F403
except ImportError:
pass
4 changes: 4 additions & 0 deletions src/portal/azext_portal/azext_metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"azext.isPreview": true,
"azext.minCliCoreVersion": "2.0.67"
}
12 changes: 12 additions & 0 deletions src/portal/azext_portal/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# pylint: disable=wildcard-import
# pylint: disable=unused-wildcard-import

from .generated.commands import * # noqa: F403
try:
from .manual.commands import * # noqa: F403
except ImportError:
pass
12 changes: 12 additions & 0 deletions src/portal/azext_portal/custom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# pylint: disable=wildcard-import
# pylint: disable=unused-wildcard-import

from .generated.custom import * # noqa: F403
try:
from .manual.custom import * # noqa: F403
except ImportError:
pass
14 changes: 14 additions & 0 deletions src/portal/azext_portal/generated/_client_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------


def cf_portal(cli_ctx, *_):
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from ..vendored_sdks.portal import Portal
return get_mgmt_service_client(cli_ctx, Portal)


def cf_dashboard(cli_ctx, *_):
return cf_portal(cli_ctx).dashboard
65 changes: 65 additions & 0 deletions src/portal/azext_portal/generated/_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# --------------------------------------------------------------------------------------------
# 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
# pylint: disable=too-many-lines

from knack.help_files import helps


helps['portal dashboard'] = """
type: group
short-summary: portal dashboard
"""

helps['portal dashboard list'] = """
type: command
short-summary: Gets all the dashboards within a subscription.
examples:
- name: List all custom resource providers on the resourceGroup
text: |-
az portal dashboard list --resource-group "testRG"
"""

helps['portal dashboard show'] = """
type: command
short-summary: Gets the Dashboard.
examples:
- name: Get a Dashboard
text: |-
az portal dashboard show --dashboard-name "testDashboard" --resource-group "testRG"
"""

helps['portal dashboard create'] = """
type: command
short-summary: Creates or updates a Dashboard.
examples:
- name: Create or update a Dashboard
text: |-
az portal dashboard create --location "eastus" --properties-lenses "{\\"aLens\\":{\\"order\\":
1,\\"parts\\":{\\"aPart\\":{\\"position\\":{\\"colSpan\\":3,\\"rowSpan\\":4,\\"x\\":1,\\"y\\":2}},\\"bPar
t\\":{\\"position\\":{\\"colSpan\\":6,\\"rowSpan\\":6,\\"x\\":5,\\"y\\":5}}}},\\"bLens\\":{\\"order\\":2,
\\"parts\\":{}}}" --properties-metadata metadata=[object Object] --tags
aKey=aValue anotherKey=anotherValue --dashboard-name "testDashboard" --resource-group
"testRG"
"""

helps['portal dashboard update'] = """
type: command
short-summary: Updates an existing Dashboard.
examples:
- name: Update a Dashboard
text: |-
az portal dashboard update --tags aKey=bValue anotherKey=anotherValue2 --dashboard-name
"testDashboard" --resource-group "testRG"
"""

helps['portal dashboard delete'] = """
type: command
short-summary: Deletes the Dashboard.
examples:
- name: Delete a Dashboard
text: |-
az portal dashboard delete --dashboard-name "testDashboard" --resource-group "testRG"
"""
44 changes: 44 additions & 0 deletions src/portal/azext_portal/generated/_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# --------------------------------------------------------------------------------------------
# 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
# pylint: disable=too-many-lines
# pylint: disable=too-many-statements

from knack.arguments import CLIArgumentType
from azure.cli.core.commands.parameters import (
tags_type,
resource_group_name_type,
get_location_type
)
from azext_portal.action import AddMetadata


def load_arguments(self, _):

with self.argument_context('portal dashboard list') as c:
c.argument('resource_group_name', resource_group_name_type, help='The name of the resource group.')

with self.argument_context('portal dashboard show') as c:
c.argument('resource_group_name', resource_group_name_type, help='The name of the resource group.')
c.argument('dashboard_name', help='The name of the dashboard.')

with self.argument_context('portal dashboard create') as c:
c.argument('resource_group_name', resource_group_name_type, help='The name of the resource group.')
c.argument('dashboard_name', help='The name of the dashboard.')
c.argument('location', arg_type=get_location_type(self.cli_ctx), help='Resource location')
c.argument('tags', tags_type, help='Resource tags')
c.argument('properties_lenses', arg_type=CLIArgumentType(options_list=['--properties-lenses'], help='The dashboard lenses.'))
c.argument('properties_metadata', action=AddMetadata, nargs='+', help='The dashboard metadata.')

with self.argument_context('portal dashboard update') as c:
c.argument('resource_group_name', resource_group_name_type, help='The name of the resource group.')
c.argument('dashboard_name', help='The name of the dashboard.')
c.argument('tags', tags_type, help='Resource tags')
c.argument('properties_lenses', arg_type=CLIArgumentType(options_list=['--properties-lenses'], help='The dashboard lenses.'))
c.argument('properties_metadata', action=AddMetadata, nargs='+', help='The dashboard metadata.')

with self.argument_context('portal dashboard delete') as c:
c.argument('resource_group_name', resource_group_name_type, help='The name of the resource group.')
c.argument('dashboard_name', help='The name of the dashboard.')
18 changes: 18 additions & 0 deletions src/portal/azext_portal/generated/_validators.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 example_name_or_id_validator(cmd, namespace):
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
)
26 changes: 26 additions & 0 deletions src/portal/azext_portal/generated/action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# pylint: disable=protected-access

import argparse
from knack.util import CLIError


class AddMetadata(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
namespace.properties_metadata = action

def get_action(self, values, option_string): # pylint: disable=no-self-use
try:
properties = dict(x.split('=', 1) for x in values)
except ValueError:
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
d[k] = v
return d
20 changes: 20 additions & 0 deletions src/portal/azext_portal/generated/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# --------------------------------------------------------------------------------------------
# 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.commands import CliCommandType


def load_command_table(self, _):

from azext_portal.generated._client_factory import cf_dashboard
portal_dashboard = CliCommandType(
operations_tmpl='azext_portal.vendored_sdks.portal.operations._dashboard_operations#DashboardOperations.{}',
client_factory=cf_dashboard)
with self.command_group('portal dashboard', portal_dashboard, client_factory=cf_dashboard) as g:
g.custom_command('list', 'portal_dashboard_list')
g.custom_show_command('show', 'portal_dashboard_show')
g.custom_command('create', 'portal_dashboard_create')
g.custom_command('update', 'portal_dashboard_update')
g.custom_command('delete', 'portal_dashboard_delete')
48 changes: 48 additions & 0 deletions src/portal/azext_portal/generated/custom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# --------------------------------------------------------------------------------------------
# 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
# pylint: disable=too-many-lines

import json


def portal_dashboard_list(cmd, client,
resource_group_name=None):
if resource_group_name is not None:
return client.list_by_resource_group(resource_group_name=resource_group_name)
return client.list_by_subscription()


def portal_dashboard_show(cmd, client,
resource_group_name,
dashboard_name):
return client.get(resource_group_name=resource_group_name, dashboard_name=dashboard_name)


def portal_dashboard_create(cmd, client,
resource_group_name,
dashboard_name,
location,
tags=None,
properties_lenses=None,
properties_metadata=None):
properties_lenses = json.loads(properties_lenses) if isinstance(properties_lenses, str) else properties_lenses
return client.create_or_update(resource_group_name=resource_group_name, dashboard_name=dashboard_name, location=location, tags=tags, lenses=properties_lenses, metadata=properties_metadata)


def portal_dashboard_update(cmd, client,
resource_group_name,
dashboard_name,
tags=None,
properties_lenses=None,
properties_metadata=None):
properties_lenses = json.loads(properties_lenses) if isinstance(properties_lenses, str) else properties_lenses
return client.update(resource_group_name=resource_group_name, dashboard_name=dashboard_name, tags=tags, lenses=properties_lenses, metadata=properties_metadata)


def portal_dashboard_delete(cmd, client,
resource_group_name,
dashboard_name):
return client.delete(resource_group_name=resource_group_name, dashboard_name=dashboard_name)
4 changes: 4 additions & 0 deletions src/portal/azext_portal/tests/latest/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
Loading