Skip to content

Commit

Permalink
Add enum list for vmsize and thumbprint algorithm.
Browse files Browse the repository at this point in the history
  • Loading branch information
xingwu1 committed Feb 2, 2017
1 parent 2186a7f commit a6a510c
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 14 deletions.
Expand Up @@ -195,13 +195,13 @@ def group_title(path):
:param str path: The complex object path of the argument.
:returns: str
"""
def filter(group):
def filter_group(group):
for suffix in ["_patch_parameter", "_update_parameter", "_parameter"]:
if group.endswith(suffix):
group = group[:0 - len(suffix)]
return group
group_path = path.split('.')
group_path = list(map(filter, group_path))
group_path = list(map(filter_group, group_path)) # pylint: disable=bad-builtin
title = ': '.join(group_path)
for group in group_path:
title = title.replace(group, " ".join([n.title() for n in group.split('_')]), 1)
Expand Down Expand Up @@ -830,5 +830,5 @@ def cli_batch_data_plane_command(name, operation, client_factory, transform=None
command.cmd.add_argument('account_endpoint', '--account-endpoint', required=False, default=None,
arg_group=group_name,
help='Batch service endpoint. Alternatively, set by environment'
'variable: AZURE_BATCH_ENDPOINT')
' variable: AZURE_BATCH_ENDPOINT')
command_table[command.cmd.name] = command.cmd
Expand Up @@ -80,10 +80,12 @@
for command in ['job create', 'job set', 'job reset', 'job-schedule create', 'job-schedule set', 'job-schedule reset']:
register_cli_argument('batch {}'.format(command), 'pool_id', options_list=('--pool-id',), help='The id of an existing pool. All the tasks of the job will run on the specified pool.')

register_cli_argument('batch pool create', 'os_family', **enum_choice_list(['2', '3', '4', '5']))

register_cli_argument('batch certificate', 'thumbprint', help='The certificate thumbprint.')
register_cli_argument('batch certificate show', 'thumbprint', help='The certificate thumbprint.', validator=validate_cert_settings)
register_cli_argument('batch certificate', 'password', help='The password to access the certificate\'s private key.')
register_cli_argument('batch certificate', 'file', type=file_type, help='The certificate file: cer file or pfx file.', validator=validate_cert_file, completer=FilesCompleter())
register_cli_argument('batch certificate', 'certificate_file', type=file_type, help='The certificate file: cer file or pfx file.', validator=validate_cert_file, completer=FilesCompleter())
register_cli_argument('batch certificate delete', 'abort', action='store_true', help='Cancel the failed certificate deletion operation.')

register_cli_argument('batch task create', 'json_file', type=file_type, help='The file containing the task(s) to create in JSON format, if this parameter is specified, all other parameters are ignored.', validator=validate_json_file, completer=FilesCompleter())
Expand Down
Expand Up @@ -162,10 +162,10 @@ def validate_json_file(namespace):
def validate_cert_file(namespace):
"""Validate the give cert file existing"""
try:
with open(namespace.file, "rb"):
with open(namespace.certificate_file, "rb"):
pass
except EnvironmentError:
raise ValueError("Cannot access certificate file: " + namespace.file)
raise ValueError("Cannot access certificate file: " + namespace.certificate_file)


def validate_options(namespace):
Expand Down
Expand Up @@ -6,7 +6,8 @@
from azure.cli.core.commands import cli_command

from azure.cli.command_modules.batch._command_type import cli_batch_data_plane_command
from azure.cli.command_modules.batch._validators import validate_pool_settings, validate_cert_settings
from azure.cli.command_modules.batch._validators import (
validate_pool_settings, validate_cert_settings)
from azure.cli.command_modules.batch._client_factory import (
account_mgmt_client_factory,
account_client_factory,
Expand Down
Expand Up @@ -148,15 +148,15 @@ def _handle_batch_exception(action):


@transfer_doc(CertificateAddParameter)
def create_certificate(client, file, thumbprint, password=None):
def create_certificate(client, certificate_file, thumbprint, password=None):
thumbprint_algorithm = 'sha1'

def action():
client.add(cert)
return client.get(thumbprint_algorithm, thumbprint)

certificate_format = 'pfx' if password else 'cer'
with open(file, "rb") as f:
with open(certificate_file, "rb") as f:
data_bytes = f.read()
data = base64.b64encode(data_bytes).decode('utf-8')
cert = CertificateAddParameter(thumbprint, thumbprint_algorithm, data,
Expand Down Expand Up @@ -205,8 +205,8 @@ def action():
@transfer_doc(PoolUpdatePropertiesParameter, StartTask)
def update_pool(client, pool_id, json_file=None, start_task_command_line=None, # pylint:disable=too-many-arguments
certificate_references=None, application_package_references=None, metadata=None,
start_task_run_elevated=None, start_task_environment_settings=None, start_task_wait_for_success=None,
start_task_max_task_retry_count=None):
start_task_run_elevated=None, start_task_environment_settings=None,
start_task_wait_for_success=None, start_task_max_task_retry_count=None):
def action():
client.update_properties(pool_id=pool_id, pool_update_properties_parameter=param)
return client.get(pool_id)
Expand Down
Expand Up @@ -24,7 +24,7 @@ def test_batch_certificate_cmd(self):

def body(self):
# test create certificate with default set
self.cmd('batch certificate create --thumbprint {} --file "{}"'.
self.cmd('batch certificate create --thumbprint {} --certificate-file "{}"'.
format(self.cert_thumbprint, self.create_cert_file_path),
checks=[
JMESPathCheck('thumbprint', self.cert_thumbprint),
Expand Down Expand Up @@ -104,8 +104,8 @@ def body(self):
JMESPathCheck('id', self.create_pool_id),
JMESPathCheck('startTask.commandLine', "cmd /c echo updated")])

self.cmd('batch pool reset --pool-id {} --start-task-command-line hostname --metadata a=b c=d'.
format(self.create_pool_id),
self.cmd('batch pool reset --pool-id {} --start-task-command-line '
'hostname --metadata a=b c=d'.format(self.create_pool_id),
checks=[JMESPathCheck('allocationState', 'steady'),
JMESPathCheck('id', self.create_pool_id),
JMESPathCheck('startTask.commandLine', "hostname"),
Expand Down

0 comments on commit a6a510c

Please sign in to comment.