def create_file_server(client, location, resource_group, nfs_name, subnet_id=None): """Creates NFS :param BatchAIManagementClient client: client instance. :param str location: location. :param str resource_group: resource group name. :param str nfs_name: file server name. :param models.ResourceId subnet_id: id of the subnet. :return models.FileServer: created file server. """ client.workspaces.create(resource_group, Helpers.DEFAULT_WORKSPACE_NAME, location).result() return client.file_servers.create( resource_group, Helpers.DEFAULT_WORKSPACE_NAME, nfs_name, models.FileServerCreateParameters( vm_size='STANDARD_D1', ssh_configuration=models.SshConfiguration( user_account_settings=models.UserAccountSettings( admin_user_name=Helpers.ADMIN_USER_NAME, admin_user_password=Helpers.ADMIN_USER_PASSWORD, )), data_disks=models.DataDisks( disk_size_in_gb=10, disk_count=2, storage_account_type='Standard_LRS'), subnet=subnet_id)).result()
def _update_user_account_settings(params, admin_user_name, ssh_key, password): """Update account settings of cluster or file server creation parameters :param models.ClusterCreateParameters or models.FileServerCreateParameters params: params to update :param str or None admin_user_name: name of admin user to create. :param str or None ssh_key: ssh public key value or path to the file containing the key. :param str or None password: password. :return models.ClusterCreateParameters: updated parameters. """ result = copy.deepcopy(params) if hasattr(result, 'user_account_settings'): parent = result else: if result.ssh_configuration is None: result.ssh_configuration = models.SshConfiguration(user_account_settings=None) parent = result.ssh_configuration if parent.user_account_settings is None: parent.user_account_settings = models.UserAccountSettings() # Get effective user name, password and key trying them in the following order: provided via command line, # provided in the config file, current user name and his default public ssh key. effective_user_name = admin_user_name or parent.user_account_settings.admin_user_name or getpass.getuser() effective_password = password or parent.user_account_settings.admin_user_password # Use default ssh public key only if no password is configured. effective_key = (ssh_key or parent.user_account_settings.admin_user_ssh_public_key or (None if effective_password else _get_default_ssh_public_key_location())) if effective_key: if os.path.exists(os.path.expanduser(effective_key)): with open(os.path.expanduser(effective_key)) as f: effective_key = f.read() try: if effective_key and not keys.is_valid_ssh_rsa_public_key(effective_key): raise CLIError('Incorrect ssh public key value.') except Exception: raise CLIError('Incorrect ssh public key value.') parent.user_account_settings.admin_user_name = effective_user_name parent.user_account_settings.admin_user_ssh_public_key = effective_key parent.user_account_settings.admin_user_password = effective_password if not parent.user_account_settings.admin_user_name: raise CLIError('Please provide admin user name.') if (not parent.user_account_settings.admin_user_ssh_public_key and not parent.user_account_settings.admin_user_password): raise CLIError('Please provide admin user password or ssh key.') return result
def _update_user_account_settings(params, admin_user_name, ssh_key, password): """Update account settings of cluster or file server creation parameters :param models.ClusterCreateParameters or models.FileServerCreateParameters params: params to update :param str or None admin_user_name: name of admin user to create. :param str or None ssh_key: ssh public key value or path to the file containing the key. :param str or None password: password. :return models.ClusterCreateParameters: updated parameters. """ result = copy.deepcopy(params) key = ssh_key if ssh_key: if os.path.exists(os.path.expanduser(ssh_key)): with open(os.path.expanduser(ssh_key)) as f: key = f.read() if not is_valid_ssh_rsa_public_key(key): raise CLIError('Incorrect ssh public key value.') if hasattr(result, 'user_account_settings'): parent = result else: if result.ssh_configuration is None: result.ssh_configuration = models.SshConfiguration(None) parent = result.ssh_configuration if parent.user_account_settings is None: parent.user_account_settings = models.UserAccountSettings( admin_user_name=admin_user_name, admin_user_ssh_public_key=key) if admin_user_name: parent.user_account_settings.admin_user_name = admin_user_name if key: parent.user_account_settings.admin_user_ssh_public_key = key if password: parent.user_account_settings.admin_user_password = password if not parent.user_account_settings.admin_user_name: raise CLIError('Please provide admin user name.') if (not parent.user_account_settings.admin_user_ssh_public_key and not parent.user_account_settings.admin_user_password): raise CLIError('Please provide admin user password or ssh key.') return result