def roll_ui_credentials(new_credentials: Dict, clients: List[VNS3Client], enable_ui=False): """Update UI credentials to common credentials Arguments: new_credentials {dict} -- {username: str, password: str} clients {List} -- List of VNS3 clients enable_ui {Bool} -- whether to enable UI Returns: BulkOperationResult """ assert "username" in new_credentials, '"username" required in new_credentials arg' assert "password" in new_credentials, '"password" required in new_credentials arg' def _update_ui_credentials(_client): resp = _client.config.put_update_admin_ui( **{ "admin_username": new_credentials.get("username"), "admin_password": new_credentials.get("password"), "enabled": enable_ui, }) # required to avoid 502 from api resetting itself time.sleep(2.0) return resp return api_operations.__bulk_call_client(clients, _update_ui_credentials, parallelize=True)
def accept_clients_license( clients, license_parameters ) -> data_types.BulkOperationResult: """Accept licenses for all. These will have DIFFERENT keysets. See keyset operations if all controllers are to be in the same clientpack topology. Assumes same license parameters will be accepted for all clients Arguments: clients {List[VNS3Client]} license_parameters {UpdateLicenseParametersRequest} - dict { 'subnet': 'str', 'managers': 'str', 'asns': 'str', 'clients': 'str', 'my_manager_vip': 'str', 'default': 'bool' } Returns: BulkOperationResult """ def _accept_license(_client): return _client.licensing.put_set_license_parameters(**license_parameters) return api_operations.__bulk_call_client(clients, _accept_license)
def verify_client_connectivity( clients: List[VNS3Client], ) -> data_types.BulkOperationResult: """Verify the connectivty of provided clients by pinging API Arguments: clients {List[VNS3Client]} Returns: data_types.BulkOperationResult """ def _ping_api(_client): return _client.sys_admin.get_config() return api_operations.__bulk_call_client(clients, _ping_api)
def license_clients(clients, license_file_path) -> data_types.BulkOperationResult: """Upload license file to all clients. These will have DIFFERENT keysets. See keyset operations if all controllers are to be in the same clientpack topology Arguments: clients {List[VNS3Client]} license_file_path {str} - full path to license file Returns: BulkOperationResult """ license_file = open(license_file_path).read().strip() def _upload_license(_client): return _client.licensing.upload_license(license_file) return api_operations.__bulk_call_client(clients, _upload_license)
def disable_uis(clients: List[VNS3Client]): """disable_uis Disable all UIs for clients Arguments: clients {List} -- List of VNS3Clients Returns: BulkOperationResult """ def _disable_ui(_client): resp = _client.config.put_update_admin_ui(enabled=False) # required to avoid 502 from api resetting itself time.sleep(2.0) return resp return api_operations.__bulk_call_client(clients, _disable_ui)
def fetch_keysets(clients, root_host, keyset_token, wait_timeout=80.0): """fetch_keysets Fetch keysets for all clients from root_host Arguments: clients {List[VNS3Client]} root_host {str} keyset_token {str} Returns: BulkOperationResult """ def _fetch_keyset(_client): return fetch_keyset_from_source( _client, root_host, keyset_token, wait_timeout=wait_timeout ) return api_operations.__bulk_call_client(clients, _fetch_keyset, parallelize=False)
def roll_api_password( new_password, clients: List[VNS3Client]) -> data_types.BulkOperationResult: """roll_api_password Update all passwords for clients Arguments: new_password {str} clients {List[VNS3Client]} Returns: BulkOperationResult - tuple containing the clients that succeeded and the clients that failed with their exceptions """ def _update_password(_client): resp = _client.config.put_update_api_password(password=new_password) _client.configuration.password = new_password return resp return api_operations.__bulk_call_client(clients, _update_password, parallelize=True)