Repository: Azure/azure-cli

Issue:
ACS create fails with no username
--admin-username defaults to 'root' which is not allowed:

$ az acs create --resource-group rgacsazcli --orchestrator-type DCOS --name rgacsazcli --dns-name-prefix rgacsazcli
Error loading command module 'iot'
At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-debug for usage details. {
  "error": {
    "code": "InvalidParameter",
    "target": "windowsProfile.adminUsername",
    "message": "Linux admin user name cannot be 'root' or be longer than 64 characters."
  }
}



Discussion:

Patch:
diff --git a/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/_actions.py b/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/_actions.py
index 78fb78969..0f91655a8 100644
--- a/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/_actions.py
+++ b/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/_actions.py
@@ -268,8 +268,8 @@ def _handle_container_ssh_file(**kwargs):
             private_key_filepath = public_key_filepath[:-4]
         else:
             private_key_filepath = public_key_filepath + '.private'
-        logger.warning('Creating SSH key files: %s,%s', private_key_filepath, public_key_filepath)
         content = _generate_ssh_keys(private_key_filepath, public_key_filepath)
+        logger.warning('Created SSH key files: %s,%s', private_key_filepath, public_key_filepath)
     args.ssh_key_value = content
 
 def _generate_ssh_keys(private_key_filepath, public_key_filepath):
diff --git a/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/_params.py b/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/_params.py
index b189d5967..5f2c070f5 100644
--- a/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/_params.py
+++ b/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/_params.py
@@ -71,8 +71,10 @@ register_cli_argument('vm access', 'password', options_list=('--password', '-p')
 
 register_cli_argument('acs', 'name', arg_type=name_arg_type)
 register_cli_argument('acs', 'orchestrator_type', **enum_choice_list(ContainerServiceOchestratorTypes))
-register_cli_argument('acs', 'admin_username', admin_username_type)
+#some admin names are prohibited in acs, such as root, admin, etc. Because we have no control on the orchestrators, so default to a safe name.
+register_cli_argument('acs', 'admin_username', options_list=('--admin-username',), default='azureuser', required=False)
 register_cli_argument('acs', 'ssh_key_value', required=False, help='SSH key file value or key file path.', default=os.path.join(os.path.expanduser('~'), '.ssh', 'id_rsa.pub'), completer=FilesCompleter())
+register_cli_argument('acs', 'dns_name_prefix', options_list=('--dns-prefix', '-d'))
 register_extra_cli_argument('acs create', 'generate_ssh_keys', action='store_true', help='Generate SSH public and private key files if missing')
 register_cli_argument('acs', 'container_service_name', options_list=('--name', '-n'), help='The name of the container service', completer=get_resource_name_completion_list('Microsoft.ContainerService/ContainerServices'))
 register_cli_argument('acs create', 'agent_vm_size', completer=get_vm_size_completion_list)


Test patch:
diff --git a/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/tests/test_vm_commands.py b/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/tests/test_vm_commands.py
index 4576239d4..7877af690 100644
--- a/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/tests/test_vm_commands.py
+++ b/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/tests/test_vm_commands.py
@@ -1254,7 +1254,7 @@ class AzureContainerServiceScenarioTest(ResourceGroupVCRTestBase): #pylint: disa
         dns_prefix = 'myacs123'
 
         #create
-        self.cmd('acs create -g {} -n {} --dns-name-prefix {}'.format(self.resource_group, acs_name, dns_prefix), checks=[
+        self.cmd('acs create -g {} -n {} --dns-prefix {}'.format(self.resource_group, acs_name, dns_prefix), checks=[
             JMESPathCheck('masterFQDN', '{}mgmt.{}.cloudapp.azure.com'.format(dns_prefix, self.location)),
             JMESPathCheck('agentFQDN', '{}agents.{}.cloudapp.azure.com'.format(dns_prefix, self.location))
             ])