Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2560574
Intial rework.
tjprescott May 4, 2016
9b2caab
Much closer to completion!
tjprescott May 5, 2016
582aa54
Finally storage works again!!!!!!
tjprescott May 5, 2016
ff3ea55
Merge branch 'master' of https://github.com/tjprescott/azure-cli into…
tjprescott May 5, 2016
4b53467
Merge branch 'AddResourceGroupCommand' of https://github.com/tjpresco…
tjprescott May 5, 2016
45f2beb
Fix resource group commands
tjprescott May 5, 2016
cb30be5
Progress porting VM commands away from decorator-style.
tjprescott May 5, 2016
ac5f3a8
Updates to work with "patches vm" commands and VM create command.
tjprescott May 5, 2016
7b3f45b
Merge branch 'master' of https://github.com/tjprescott/azure-cli into…
tjprescott May 5, 2016
4b73df7
Progress on converting network.
tjprescott May 5, 2016
36fafe3
Merge branch 'master' of https://github.com/tjprescott/azure-cli into…
tjprescott May 5, 2016
c3402dd
Fix issue with LRO attempting to execute twice.
tjprescott May 6, 2016
7556884
Merge branch 'master' of https://github.com/tjprescott/azure-cli into…
tjprescott May 6, 2016
d64fc6c
Fixed issues with VM conversion. All tests re-run and re-recorded.
tjprescott May 6, 2016
bc0229f
Rename AutoCommandDefintion to just CommandDefinition
tjprescott May 6, 2016
b05dd0c
Convert component package to semi-auto
tjprescott May 6, 2016
055d9c5
Merge branch 'master' of https://github.com/tjprescott/azure-cli into…
tjprescott May 6, 2016
ca6cfa2
Merge branch 'master' of https://github.com/tjprescott/azure-cli into…
tjprescott May 6, 2016
4652170
Fix import error.
tjprescott May 6, 2016
c87b004
Convert profile package.
tjprescott May 6, 2016
4521a41
Convert task help and clean up.
tjprescott May 6, 2016
05085ee
Merge branch 'master' of https://github.com/tjprescott/azure-cli into…
tjprescott May 6, 2016
4f60b0d
Progress on resource group scenario tests and test framework enhancem…
tjprescott May 9, 2016
19c7998
Merge branch 'master' of https://github.com/tjprescott/azure-cli into…
tjprescott May 9, 2016
55761a7
Import Derek's test enhancements and fixes.
tjprescott May 9, 2016
949fc75
Merge Yugang's changes to VM
tjprescott May 9, 2016
ec1ca8b
Post merge fixes.
tjprescott May 9, 2016
e7a9f3a
Merge branch 'master' of https://github.com/tjprescott/azure-cli into…
tjprescott May 9, 2016
d3308a2
Pylint fixes.
tjprescott May 9, 2016
81cb325
Make storage tests fully automatic.
tjprescott May 9, 2016
ec37436
Update VM test cassettes.
tjprescott May 9, 2016
3fbf53d
Code review comments.
tjprescott May 9, 2016
ada85dc
Fix _vm_get so client only required if vm_name and resource_group pro…
tjprescott May 9, 2016
94fa3f9
Code review comments.
tjprescott May 10, 2016
28cc5ac
Merge branch 'master' of https://github.com/tjprescott/azure-cli into…
tjprescott May 10, 2016
c33abe5
Merge branch 'master' of https://github.com/tjprescott/azure-cli into…
tjprescott May 10, 2016
0acd909
Re-record a couple VM tests.
tjprescott May 10, 2016
122ef11
Move help entry to dedicated file.
tjprescott May 10, 2016
f91b517
PYLINT!
tjprescott May 10, 2016
dae6b5b
Eliminate duplicate test statement.
tjprescott May 10, 2016
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
45 changes: 40 additions & 5 deletions azure-cli.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,20 @@
<Compile Include="azure\cli\main.py" />
<Compile Include="azure\cli\tests\test_add_resourcegroup_transform.py" />
<Compile Include="azure\cli\tests\test_logging.py" />
<Compile Include="azure\cli\tests\test_test_script.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="azure\cli\tests\test_validators.py" />
<Compile Include="azure\cli\utils\command_test_script.py" />
<Compile Include="command_modules\azure-cli-component\azure\cli\command_modules\component\custom.py" />
<Compile Include="command_modules\azure-cli-component\azure\cli\command_modules\component\generated.py" />
<Compile Include="command_modules\azure-cli-component\azure\cli\command_modules\component\_params.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\custom.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\generated.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt\lib\credentials.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt\lib\exceptions.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt\lib\models\basic_dependency.py" />
Expand All @@ -62,6 +74,18 @@
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt\__init__.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\_params.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="command_modules\azure-cli-profile\azure\cli\command_modules\profile\custom.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="command_modules\azure-cli-profile\azure\cli\command_modules\profile\generated.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="command_modules\azure-cli-profile\azure\cli\command_modules\profile\_params.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="command_modules\azure-cli-resource\azure\cli\command_modules\resource\custom.py" />
<Compile Include="command_modules\azure-cli-resource\azure\cli\command_modules\resource\generated.py" />
<Compile Include="command_modules\azure-cli-resource\azure\cli\command_modules\resource\tests\test_validators.py" />
Expand All @@ -70,8 +94,20 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="command_modules\azure-cli-storage\azure\cli\command_modules\storage\tests\test_validators.py" />
<Compile Include="command_modules\azure-cli-storage\azure\cli\command_modules\storage\custom.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="command_modules\azure-cli-storage\azure\cli\command_modules\storage\generated.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="command_modules\azure-cli-storage\azure\cli\command_modules\storage\_params.py" />
<Compile Include="command_modules\azure-cli-storage\azure\cli\command_modules\storage\_validators.py" />
<Compile Include="command_modules\azure-cli-taskhelp\azure\cli\command_modules\taskhelp\custom.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="command_modules\azure-cli-taskhelp\azure\cli\command_modules\taskhelp\generated.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="command_modules\azure-cli-vm\azure\cli\command_modules\vm\mgmt\lib\credentials.py" />
<Compile Include="command_modules\azure-cli-vm\azure\cli\command_modules\vm\mgmt\lib\exceptions.py" />
<Compile Include="command_modules\azure-cli-vm\azure\cli\command_modules\vm\mgmt\lib\models\basic_dependency.py" />
Expand All @@ -82,7 +118,6 @@
<Compile Include="command_modules\azure-cli-vm\azure\cli\command_modules\vm\mgmt\lib\models\deployment_properties_extended.py" />
<Compile Include="command_modules\azure-cli-vm\azure\cli\command_modules\vm\mgmt\lib\models\deployment_vm.py" />
<Compile Include="command_modules\azure-cli-vm\azure\cli\command_modules\vm\mgmt\lib\models\parameters_link.py" />
<Compile Include="command_modules\azure-cli-vm\azure\cli\command_modules\vm\mgmt\lib\models\provider - Copy.py" />
<Compile Include="command_modules\azure-cli-vm\azure\cli\command_modules\vm\mgmt\lib\models\provider.py" />
<Compile Include="command_modules\azure-cli-vm\azure\cli\command_modules\vm\mgmt\lib\models\provider_resource_type.py" />
<Compile Include="command_modules\azure-cli-vm\azure\cli\command_modules\vm\mgmt\lib\models\template_link.py" />
Expand Down Expand Up @@ -139,10 +174,6 @@
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\tests\test_commands.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\__init__.py" />
<Compile Include="command_modules\azure-cli-network\setup.py" />
<Compile Include="command_modules\azure-cli-profile\azure\cli\command_modules\profile\account.py" />
<Compile Include="command_modules\azure-cli-profile\azure\cli\command_modules\profile\command_tables.py" />
<Compile Include="command_modules\azure-cli-profile\azure\cli\command_modules\profile\login.py" />
<Compile Include="command_modules\azure-cli-profile\azure\cli\command_modules\profile\logout.py" />
<Compile Include="command_modules\azure-cli-profile\azure\cli\command_modules\profile\__init__.py" />
<Compile Include="command_modules\azure-cli-profile\setup.py" />
<Compile Include="command_modules\azure-cli-resource\azure\cli\command_modules\resource\tests\command_specs.py">
Expand All @@ -167,6 +198,10 @@
<Compile Include="command_modules\azure-cli-vm\azure\cli\command_modules\vm\custom.py" />
<Compile Include="command_modules\azure-cli-vm\azure\cli\command_modules\vm\tests\test_vm_image.py" />
<Compile Include="command_modules\azure-cli-vm\azure\cli\command_modules\vm\tests\__init__.py" />
<Compile Include="command_modules\azure-cli-vm\azure\cli\command_modules\vm\_actions.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="command_modules\azure-cli-vm\azure\cli\command_modules\vm\_factory.py" />
<Compile Include="command_modules\azure-cli-vm\azure\cli\command_modules\vm\_validators.py">
<SubType>Code</SubType>
</Compile>
Expand Down
19 changes: 8 additions & 11 deletions src/azure/cli/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,49 +20,46 @@

logger.info('Installed command modules %s', INSTALLED_COMMAND_MODULES)

RESOURCE_GROUP_ARG_NAME = 'resource_group_name'

COMMON_PARAMETERS = {
'deployment_name': {
'name': '--deployment-name',
'metavar': 'DEPLOYMENTNAME',
'help': 'Name of the resource deployment',
'default': 'azurecli' + str(time.time()) + str(random.randint(0, 10000000)),
'required': False
},
'location': {
'name': '--location -l',
'metavar': 'LOCATION',
'help': 'Location',
'required': True
},
'resource_group_name': {
'name': '--resource-group -g',
'dest': RESOURCE_GROUP_ARG_NAME,
'metavar': 'RESOURCEGROUP',
'help': 'The name of the resource group',
'required': True
},
'tag' : {
'name': '--tag',
'metavar': 'TAG',
'help': L('a single tag in \'key[=value]\' format'),
'required': False,
'type': validate_tag
},
'tags' : {
'name': '--tags',
'metavar': 'TAGS',
'help': L('multiple semicolon separated tags in \'key[=value]\' format'),
'required': False,
'type': validate_tags
},
}

def extend_parameter(parameter_metadata, **kwargs):
modified_parameter_metadata = parameter_metadata.copy()
modified_parameter_metadata.update(kwargs)
return modified_parameter_metadata
extended_param = parameter_metadata.copy()
extended_param.update(kwargs)
return extended_param

def patch_aliases(aliases, patch):
patched_aliases = aliases.copy()
patched_aliases.update(patch)
return patched_aliases

class LongRunningOperation(object): #pylint: disable=too-few-public-methods

Expand Down
71 changes: 37 additions & 34 deletions src/azure/cli/commands/_auto_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from ..commands import COMMON_PARAMETERS

EXCLUDED_PARAMS = frozenset(['self', 'raw', 'custom_headers', 'operation_config',
'content_version'])
'content_version', 'kwargs'])

class AutoCommandDefinition(object): #pylint: disable=too-few-public-methods
class CommandDefinition(object): #pylint: disable=too-few-public-methods

def __init__(self, operation, return_type, command_alias=None):
self.operation = operation
Expand All @@ -35,13 +35,15 @@ def _get_member(obj, path):
pass
return obj

def _make_func(client_factory, member_path, return_type_or_func, unbound_func):
def call_client(args):
client = client_factory(args)
def _make_func(client_factory, member_path, return_type_or_func, unbound_func, extra_parameters):
def call_client(kwargs):
client = client_factory(**kwargs)
for param in extra_parameters.keys() if extra_parameters else []:
kwargs.pop(param)
ops_instance = _get_member(client, member_path)

try:
result = unbound_func(ops_instance, **args)
result = unbound_func(ops_instance, **kwargs)
if not return_type_or_func:
return {}
if callable(return_type_or_func):
Expand All @@ -59,32 +61,33 @@ def call_client(args):
def _option_descriptions(operation):
"""Pull out parameter help from doccomments of the command
"""
lines = inspect.getdoc(operation).splitlines()
option_descs = {}
index = 0
while index < len(lines):
l = lines[index]
regex = r'\s*(:param)\s+(.+)\s*:(.*)'
match = re.search(regex, l)
if match:
# 'arg name' portion might have type info, we don't need it
arg_name = str.split(match.group(2))[-1]
arg_desc = match.group(3).strip()
#look for more descriptions on subsequent lines
index += 1
while index < len(lines):
temp = lines[index].strip()
if temp.startswith(':'):
break
else:
if temp:
arg_desc += (' ' + temp)
index += 1

option_descs[arg_name] = arg_desc
else:
index += 1

lines = inspect.getdoc(operation)
if lines:
lines = lines.splitlines()
index = 0
while index < len(lines):
l = lines[index]
regex = r'\s*(:param)\s+(.+)\s*:(.*)'
match = re.search(regex, l)
if match:
# 'arg name' portion might have type info, we don't need it
arg_name = str.split(match.group(2))[-1]
arg_desc = match.group(3).strip()
#look for more descriptions on subsequent lines
index += 1
while index < len(lines):
temp = lines[index].strip()
if temp.startswith(':'):
break
else:
if temp:
arg_desc += (' ' + temp)
index += 1

option_descs[arg_name] = arg_desc
else:
index += 1
return option_descs


Expand All @@ -99,7 +102,7 @@ def build_operation(command_name,

for op in operations:

func = _make_func(client_type, member_path, op.return_type, op.operation)
func = _make_func(client_type, member_path, op.return_type, op.operation, extra_parameters)

args = []
try:
Expand Down Expand Up @@ -152,8 +155,8 @@ def build_operation(command_name,
# append any 'extra' args needed (for example to obtain a client) that aren't required
# by the SDK.
if extra_parameters:
for arg in extra_parameters:
options.append(arg.copy())
for arg in extra_parameters.keys():
options.append(extra_parameters[arg].copy())

command_table[func] = {
'name': ' '.join([command_name, op.opname]),
Expand Down
18 changes: 9 additions & 9 deletions src/azure/cli/tests/test_autocommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from azure.cli.commands._auto_command import build_operation, _option_descriptions
from azure.cli.commands import CommandTable
from azure.cli.commands._auto_command import AutoCommandDefinition
from azure.cli.commands._auto_command import CommandDefinition
from azure.cli.main import main as cli

from six import StringIO
Expand Down Expand Up @@ -45,7 +45,7 @@ def test_autocommand_basic(self):
"",
None,
[
AutoCommandDefinition(Test_autocommand.sample_vm_get, None)
CommandDefinition(Test_autocommand.sample_vm_get, None)
],
command_table)

Expand Down Expand Up @@ -78,7 +78,7 @@ def test_autocommand_with_parameter_alias(self):
"",
None,
[
AutoCommandDefinition(Test_autocommand.sample_vm_get, None)
CommandDefinition(Test_autocommand.sample_vm_get, None)
],
command_table,
VM_SPECIFIC_PARAMS
Expand All @@ -99,19 +99,19 @@ def test_autocommand_with_parameter_alias(self):

def test_autocommand_with_extra_parameters(self):
command_table = CommandTable()
NEW_PARAMETERS= [
{
NEW_PARAMETERS = {
'added_param': {
'name': '--added-param',
'metavar': 'ADDED',
'help': 'Just added this right now!',
'required': True
}
]
}
build_operation("test autocommand",
"",
None,
[
AutoCommandDefinition(Test_autocommand.sample_vm_get, None)
CommandDefinition(Test_autocommand.sample_vm_get, None)
],
command_table,
None, NEW_PARAMETERS
Expand All @@ -137,7 +137,7 @@ def test_autocommand_with_command_alias(self):
"",
None,
[
AutoCommandDefinition(Test_autocommand.sample_vm_get, None, 'woot')
CommandDefinition(Test_autocommand.sample_vm_get, None, 'woot')
],
command_table
)
Expand Down Expand Up @@ -165,7 +165,7 @@ def sample_sdk_method_with_weired_docstring(self, param_a, param_b, param_c):
"",
None,
[
AutoCommandDefinition(sample_sdk_method_with_weired_docstring, None)
CommandDefinition(sample_sdk_method_with_weired_docstring, None)
],
command_table)

Expand Down
45 changes: 45 additions & 0 deletions src/azure/cli/tests/test_test_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import json
import unittest
from six import StringIO

from azure.cli.utils.command_test_script import _check_json as check_json

class Test_test_script_checks(unittest.TestCase):

@classmethod
def setUpClass(cls):
pass

@classmethod
def tearDownClass(cls):
pass

def setUp(self):
self.io = StringIO()

def tearDown(self):
self.io.close()

def test_json_string(self):
''' Verify a simple string value can be used to match a property on a source object. '''
source = json.loads(json.dumps({'a': 'b', 'c': 'd'}))
check = {'c': 'd'}
check_json(source, check)

def test_json_dict(self):
''' Verify a dict can be used to search within child objects without having to match the
child object exactly.'''
source = json.loads(json.dumps({'a': {'foo': 'bar', 'fizz': 'buzz'}}))
check = {'a': {'fizz': 'buzz'}}
check_json(source, check)

def test_json_list(self):
''' Verify that if the source is a list, the check need only pass for any element of the
list. '''
source = json.loads(json.dumps([{'a': {'b': 1, 'c': 2}}, {'a': {'b': 3, 'c': 5}}]))
check = {'a': {'c': 5}}
check_json(source, check)


if __name__ == '__main__':
unittest.main()
Loading