зеркало из https://github.com/microsoft/azure-cli.git
Merge branch 'master' of https://github.com/tjprescott/azure-cli into AddStorageDataPlaneCommands
This commit is contained in:
Коммит
be5ad5a255
|
@ -29,7 +29,7 @@
|
||||||
<Compile Include="azure\cli\commands\login.py" />
|
<Compile Include="azure\cli\commands\login.py" />
|
||||||
<Compile Include="azure\cli\commands\logout.py" />
|
<Compile Include="azure\cli\commands\logout.py" />
|
||||||
<Compile Include="azure\cli\commands\network.py" />
|
<Compile Include="azure\cli\commands\network.py" />
|
||||||
<Compile Include="azure\cli\commands\resourcegroup.py" />
|
<Compile Include="azure\cli\commands\resource.py" />
|
||||||
<Compile Include="azure\cli\commands\storage.py" />
|
<Compile Include="azure\cli\commands\storage.py" />
|
||||||
<Compile Include="azure\cli\commands\vm.py" />
|
<Compile Include="azure\cli\commands\vm.py" />
|
||||||
<Compile Include="azure\cli\commands\_auto_command.py" />
|
<Compile Include="azure\cli\commands\_auto_command.py" />
|
||||||
|
|
|
@ -48,6 +48,9 @@ def configure_logging(argv, config):
|
||||||
logger.level = stderr_handler.level = level
|
logger.level = stderr_handler.level = level
|
||||||
logger.handlers.append(stderr_handler)
|
logger.handlers.append(stderr_handler)
|
||||||
|
|
||||||
|
# Set logging level for all loggers
|
||||||
|
_logging.basicConfig(level=level)
|
||||||
|
|
||||||
if logfile:
|
if logfile:
|
||||||
# Configure the handler that logs code to a text file
|
# Configure the handler that logs code to a text file
|
||||||
log_handler = _logging.StreamHandler(open(logfile, 'w', encoding='utf-8'))
|
log_handler = _logging.StreamHandler(open(logfile, 'w', encoding='utf-8'))
|
||||||
|
|
|
@ -7,7 +7,7 @@ COMMAND_MODULES = [
|
||||||
'login',
|
'login',
|
||||||
'logout',
|
'logout',
|
||||||
'network',
|
'network',
|
||||||
'resourcegroup',
|
'resource',
|
||||||
'storage',
|
'storage',
|
||||||
'vm',
|
'vm',
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
from .._profile import Profile
|
from .._profile import Profile
|
||||||
import azure.cli._debug as _debug
|
import azure.cli._debug as _debug
|
||||||
import azure.cli as cli
|
import azure.cli as cli
|
||||||
from .._logging import logger
|
|
||||||
|
|
||||||
def get_mgmt_service_client(client_type, config_type):
|
def get_mgmt_service_client(client_type, config_type):
|
||||||
profile = Profile()
|
profile = Profile()
|
||||||
config = config_type(*profile.get_login_credentials())
|
config = config_type(*profile.get_login_credentials())
|
||||||
config.log_name = 'az'
|
|
||||||
config.log_level = logger.level
|
|
||||||
|
|
||||||
client = client_type(config)
|
client = client_type(config)
|
||||||
_debug.allow_debug_connection(client)
|
_debug.allow_debug_connection(client)
|
||||||
|
|
|
@ -0,0 +1,99 @@
|
||||||
|
from .._argparse import IncorrectUsageError
|
||||||
|
from ..commands import command, description, option
|
||||||
|
from ._command_creation import get_mgmt_service_client
|
||||||
|
from .._locale import L
|
||||||
|
|
||||||
|
from azure.mgmt.resource.resources import (ResourceManagementClient,
|
||||||
|
ResourceManagementClientConfiguration)
|
||||||
|
|
||||||
|
@command('resource group list')
|
||||||
|
@description('List resource groups')
|
||||||
|
@option('--tag-name -tn <tagName>', L("the resource group's tag name"))
|
||||||
|
@option('--tag-value -tv <tagValue>', L("the resource group's tag value"))
|
||||||
|
def list_groups(args, unexpected): #pylint: disable=unused-argument
|
||||||
|
from azure.mgmt.resource.resources.models import ResourceGroup, ResourceGroupFilter
|
||||||
|
|
||||||
|
rmc = get_mgmt_service_client(ResourceManagementClient, ResourceManagementClientConfiguration)
|
||||||
|
|
||||||
|
filters = []
|
||||||
|
if args.get('tag-name'):
|
||||||
|
filters.append("tagname eq '{}'".format(args.get('tag-name')))
|
||||||
|
if args.get('tag-value'):
|
||||||
|
filters.append("tagvalue eq '{}'".format(args.get('tag-value')))
|
||||||
|
|
||||||
|
filter_text = ' and '.join(filters) if len(filters) > 0 else None
|
||||||
|
|
||||||
|
groups = rmc.resource_groups.list(filter=filter_text)
|
||||||
|
return list(groups)
|
||||||
|
|
||||||
|
@command('resource show')
|
||||||
|
@description(L('Show details of a specific resource in a resource group or subscription'))
|
||||||
|
@option('--resource-group -g <resourceGroup>', L('the resource group name'), required=True)
|
||||||
|
@option('--name -n <name>', L('the resource name'), required=True)
|
||||||
|
@option('--resource-type -r <resourceType>',
|
||||||
|
L('the resource type in format: <provider-namespace>/<type>'), required=True)
|
||||||
|
@option('--api-version -o <apiVersion>', L('the API version of the resource provider'))
|
||||||
|
@option('--parent <parent>',
|
||||||
|
L('the name of the parent resource (if needed), in <parent-type>/<parent-name> format'))
|
||||||
|
def show_resource(args, unexpected): #pylint: disable=unused-argument
|
||||||
|
rmc = get_mgmt_service_client(ResourceManagementClient, ResourceManagementClientConfiguration)
|
||||||
|
|
||||||
|
full_type = args.get('resource-type').split('/')
|
||||||
|
try:
|
||||||
|
provider_namespace = full_type[0]
|
||||||
|
resource_type = full_type[1]
|
||||||
|
except IndexError:
|
||||||
|
raise IncorrectUsageError('Parameter --resource-type must be in <namespace>/<type> format.')
|
||||||
|
|
||||||
|
api_version = _resolve_api_version(args, rmc)
|
||||||
|
if not api_version:
|
||||||
|
raise IncorrectUsageError(
|
||||||
|
L('API version is required and could not be resolved for resource {}'
|
||||||
|
.format(full_type)))
|
||||||
|
|
||||||
|
results = rmc.resources.get(
|
||||||
|
resource_group_name=args.get('resource-group'),
|
||||||
|
resource_name=args.get('name'),
|
||||||
|
resource_provider_namespace=provider_namespace,
|
||||||
|
resource_type=resource_type,
|
||||||
|
api_version=api_version,
|
||||||
|
parent_resource_path=args.get('parent', '')
|
||||||
|
)
|
||||||
|
return results
|
||||||
|
|
||||||
|
def _resolve_api_version(args, rmc):
|
||||||
|
api_version = args.get('api-version')
|
||||||
|
if api_version:
|
||||||
|
return api_version
|
||||||
|
|
||||||
|
# if api-version not supplied, attempt to resolve using provider namespace
|
||||||
|
parent = args.get('parent')
|
||||||
|
full_type = args.get('resource-type').split('/')
|
||||||
|
try:
|
||||||
|
provider_namespace = full_type[0]
|
||||||
|
resource_type = full_type[1]
|
||||||
|
except IndexError:
|
||||||
|
raise IncorrectUsageError('Parameter --resource-type must be in <namespace>/<type> format.')
|
||||||
|
|
||||||
|
if parent:
|
||||||
|
try:
|
||||||
|
parent_type = parent.split('/')[0]
|
||||||
|
except IndexError:
|
||||||
|
raise IncorrectUsageError('Parameter --parent must be in <type>/<name> format.')
|
||||||
|
|
||||||
|
resource_type = "{}/{}".format(parent_type, resource_type)
|
||||||
|
else:
|
||||||
|
resource_type = resource_type
|
||||||
|
provider = rmc.providers.get(provider_namespace)
|
||||||
|
for t in provider.resource_types:
|
||||||
|
if t.resource_type == resource_type:
|
||||||
|
# Return first non-preview version
|
||||||
|
for version in t.api_versions:
|
||||||
|
if not version.find('preview'):
|
||||||
|
return version
|
||||||
|
# No non-preview version found. Take first preview version
|
||||||
|
try:
|
||||||
|
return t.api_versions[0]
|
||||||
|
except IndexError:
|
||||||
|
return None
|
||||||
|
return None
|
|
@ -1,27 +0,0 @@
|
||||||
from ..commands import command, description, option
|
|
||||||
from ._command_creation import get_mgmt_service_client
|
|
||||||
from .._locale import L
|
|
||||||
|
|
||||||
@command('resource group list')
|
|
||||||
@description('List resource groups')
|
|
||||||
@option('--tag-name -tn <tagName>', L("the resource group's tag name"))
|
|
||||||
@option('--tag-value -tv <tagValue>', L("the resource group's tag value"))
|
|
||||||
@option('--top -t <number>', L('Top N resource groups to retrieve'))
|
|
||||||
def list_groups(args, unexpected): #pylint: disable=unused-argument
|
|
||||||
from azure.mgmt.resource.resources import ResourceManagementClient, \
|
|
||||||
ResourceManagementClientConfiguration
|
|
||||||
from azure.mgmt.resource.resources.models import ResourceGroup, ResourceGroupFilter
|
|
||||||
|
|
||||||
rmc = get_mgmt_service_client(ResourceManagementClient, ResourceManagementClientConfiguration)
|
|
||||||
|
|
||||||
filters = []
|
|
||||||
if args.get('tag-name'):
|
|
||||||
filters.append("tagname eq '{}'".format(args.get('tag-name')))
|
|
||||||
if args.get('tag-value'):
|
|
||||||
filters.append("tagvalue eq '{}'".format(args.get('tag-value')))
|
|
||||||
|
|
||||||
filter_text = ' and '.join(filters) if len(filters) > 0 else None
|
|
||||||
|
|
||||||
# TODO: top param doesn't work in SDK [bug #115521665]
|
|
||||||
groups = rmc.resource_groups.list(filter=filter_text, top=args.get('top'))
|
|
||||||
return list(groups)
|
|
Загрузка…
Ссылка в новой задаче