def list_machines(api_key, params, **kwargs): del_if_value_is_none(kwargs) params = params or {} kwargs = kwargs or {} validate_mutually_exclusive(params.values(), kwargs.values(), "You can use either --params dictionary or single filter arguments") machines_api = http_client.API(config.CONFIG_HOST, api_key=api_key) command = machines_commands.ListMachinesCommand(api=machines_api) filters = params or kwargs command.execute(filters=filters)
def _get_client(self, api_key, logger_): if hasattr(self, "client"): return self.client http_client_ = http_client.API(config.config.CONFIG_HOST, api_key=api_key, logger=logger_) http_client_.ps_client_name = cli_constants.CLI_PS_CLIENT_NAME client = JobRunClient(http_client_, api_key=api_key, logger=logger_, ps_client_name=CLI_PS_CLIENT_NAME) return client
def create_machine(api_key, **kwargs): del_if_value_is_none(kwargs) assign_public_ip = kwargs.get("assignPublicIp") dynamic_public_ip = kwargs.get("dynamicPublicIp") validate_mutually_exclusive([assign_public_ip], [dynamic_public_ip], "--assignPublicIp cannot be used with --dynamicPublicIp") team_id = kwargs.get("teamId") email = kwargs.get("email") password = kwargs.get("password") first_name = kwargs.get("firstName") last_name = kwargs.get("lastName") validate_mutually_exclusive([team_id], [email, password, first_name, last_name], "--userId is mutually exclusive with --email, --password, --firstName and --lastName") machines_api = http_client.API(config.CONFIG_HOST, api_key=api_key) command = machines_commands.CreateMachineCommand(api=machines_api) command.execute(kwargs)
import six import terminaltables from halo import halo from gradient import version, logger as gradient_logger, api_sdk, exceptions from gradient.api_sdk.clients import http_client from gradient.config import config from gradient.commands import common from gradient.utils import get_terminal_lines default_headers = { "X-API-Key": config.PAPERSPACE_API_KEY, "ps_client_name": "gradient-cli", "ps_client_version": version.version } deployments_api = http_client.API(config.CONFIG_HOST, headers=default_headers) class _DeploymentCommandBase(common.CommandBase): def _log_message(self, response, success_msg_template, error_msg): if response.ok: try: j = response.json() handle = j["deployment"] except (ValueError, KeyError): self.logger.error(success_msg_template) else: msg = success_msg_template.format(**handle) self.logger.log(msg) else: try:
def get_workspace_handler(api_key): client = http_client.API(config.CONFIG_EXPERIMENTS_HOST, api_key=api_key) logger_ = logger.Logger() workspace_handler = workspace.S3WorkspaceHandlerWithProgressbar(experiments_api=client, logger_=logger_) return workspace_handler
def wait_for_machine_state(machine_id, state, api_key): machines_api = http_client.API(config.CONFIG_HOST, api_key=api_key) command = machines_commands.WaitForMachineStateCommand(api=machines_api) command.execute(machine_id, state)
def show_machine_utilization(machine_id, billing_month, api_key): machines_api = http_client.API(config.CONFIG_HOST, api_key=api_key) command = machines_commands.ShowMachineUtilisationCommand(api=machines_api) command.execute(machine_id, billing_month)
def stop_machine(machine_id, api_key): machines_api = http_client.API(config.CONFIG_HOST, api_key=api_key) command = machines_commands.StopMachineCommand(api=machines_api) command.execute(machine_id)
def check_machine_availability(region, machine_type, api_key): machines_api = http_client.API(config.CONFIG_HOST, api_key=api_key) command = machines_commands.CheckAvailabilityCommand(api=machines_api) command.execute(region, machine_type)
def update_machine(machine_id, api_key, **kwargs): del_if_value_is_none(kwargs) machines_api = http_client.API(config.CONFIG_HOST, api_key=api_key) command = machines_commands.UpdateMachineCommand(api=machines_api) command.execute(machine_id, kwargs)
def show_machine_details(machine_id, api_key): machines_api = http_client.API(config.CONFIG_HOST, api_key=api_key) command = machines_commands.ShowMachineCommand(api=machines_api) command.execute(machine_id)
def destroy_machine(machine_id, release_public_ip, api_key): machines_api = http_client.API(config.CONFIG_HOST, api_key=api_key) command = machines_commands.DestroyMachineCommand(api=machines_api) command.execute(machine_id, release_public_ip)