forked from Azure/azure-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add support to list resources by resource group. Add resource set command to add or clear tags from a resource. * Address code review comments and add 'resource provider list' and 'resource provider show' commands.
- Loading branch information
1 parent
20fe360
commit e1b6120
Showing
20 changed files
with
1,339 additions
and
616 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/command_modules/azure-cli-resource/azure/cli/command_modules/resource/_actions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from azure.cli.parser import IncorrectUsageError | ||
|
||
from ._factory import _resource_client_factory | ||
|
||
def _resolve_api_version(rcf, resource_type, parent=None): | ||
|
||
provider = rcf.providers.get(resource_type.namespace) | ||
resource_type_str = '{}/{}'.format(parent.type, resource_type.type) \ | ||
if parent else resource_type.type | ||
|
||
rt = [t for t in provider.resource_types if t.resource_type == resource_type_str] | ||
if not rt: | ||
raise IncorrectUsageError('Resource type {} not found.' | ||
.format(resource_type_str)) | ||
if len(rt) == 1 and rt[0].api_versions: | ||
npv = [v for v in rt[0].api_versions if 'preview' not in v.lower()] | ||
return npv[0] if npv else rt[0].api_versions[0] | ||
else: | ||
raise IncorrectUsageError( | ||
'API version is required and could not be resolved for resource {}/{}' | ||
.format(resource_type.namespace, resource_type.type)) | ||
|
||
def handle_resource_parameters(**kwargs): | ||
args = vars(kwargs['args']) | ||
|
||
param_set = set(['resource_type', 'api_version', | ||
'resource_provider_namespace', 'parent_resource_path']) | ||
if not param_set.issubset(set(args.keys())): | ||
return | ||
|
||
resource_tuple = args.get('resource_type') | ||
parent_tuple = args.get('parent_resource_path') | ||
|
||
rcf = _resource_client_factory() | ||
args['api_version'] = args.get('api_version') or \ | ||
_resolve_api_version(rcf, resource_tuple, parent_tuple) | ||
args['resource_type'] = resource_tuple.type | ||
args['resource_provider_namespace'] = resource_tuple.namespace | ||
args['parent_resource_path'] = '{}/{}'.format( | ||
parent_tuple.type, | ||
parent_tuple.name) if parent_tuple else '' |
7 changes: 7 additions & 0 deletions
7
src/command_modules/azure-cli-resource/azure/cli/command_modules/resource/_factory.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from azure.mgmt.resource.resources import (ResourceManagementClient, | ||
ResourceManagementClientConfiguration) | ||
|
||
from azure.cli.commands._command_creation import get_mgmt_service_client | ||
|
||
def _resource_client_factory(**_): | ||
return get_mgmt_service_client(ResourceManagementClient, ResourceManagementClientConfiguration) |
29 changes: 16 additions & 13 deletions
29
src/command_modules/azure-cli-resource/azure/cli/command_modules/resource/_params.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,31 @@ | ||
from azure.mgmt.resource.resources import (ResourceManagementClient, | ||
ResourceManagementClientConfiguration) | ||
import argparse | ||
|
||
from azure.cli.commands import COMMON_PARAMETERS as GLOBAL_COMMON_PARAMETERS, patch_aliases | ||
from azure.cli.commands._command_creation import get_mgmt_service_client | ||
from azure.cli._locale import L | ||
|
||
from ._validators import validate_resource_type, validate_parent | ||
|
||
# FACTORIES | ||
|
||
def _resource_client_factory(**_): | ||
return get_mgmt_service_client(ResourceManagementClient, ResourceManagementClientConfiguration) | ||
|
||
# BASIC PARAMETER CONFIGURATION | ||
|
||
PARAMETER_ALIASES = patch_aliases(GLOBAL_COMMON_PARAMETERS, { | ||
'api_version': { | ||
'name': '--api-version', | ||
'help': 'The api version of the resource (omit for latest)', | ||
'required': False | ||
}, | ||
'resource_provider_namespace': { | ||
'name': '--resource-provider-namespace', | ||
'help': argparse.SUPPRESS, | ||
'required': False | ||
}, | ||
'resource_type': { | ||
'name': '--resource-type', | ||
'help': L('the resource type in <namespace>/<type> format'), | ||
'help': 'The resource type in <namespace>/<type> format', | ||
'type': validate_resource_type | ||
}, | ||
'parent': { | ||
'parent_resource_path': { | ||
'name': '--parent', | ||
'help': L('the parent resource type in <type>/<name> format'), | ||
'type': validate_parent | ||
'help': 'The parent resource type in <type>/<name> format', | ||
'type': validate_parent, | ||
'required': False | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.