def use(management_ip, provider, rest_port): logger = get_logger() # first check this server is available. client = utils.get_rest_client(manager_ip=management_ip, rest_port=rest_port) try: status_result = client.manager.get_status() except CloudifyClientError: status_result = None if not status_result: msg = ("Can't use management server {0}: No response.".format( management_ip)) raise CloudifyCliError(msg) # check if cloudify was initialized. if not utils.is_initialized(): utils.dump_cloudify_working_dir_settings() utils.dump_configuration_file() try: response = utils.get_rest_client(management_ip).manager.get_context() provider_name = response['name'] provider_context = response['context'] except CloudifyClientError: provider_name = None provider_context = None with utils.update_wd_settings() as wd_settings: wd_settings.set_management_server(management_ip) wd_settings.set_provider_context(provider_context) wd_settings.set_provider(provider_name) wd_settings.set_rest_port(rest_port) wd_settings.set_is_provider_config(provider) logger.info('Using management server {0} with port {1}'.format( management_ip, rest_port))
def use(management_ip, rest_port): logger = get_logger() # first check this server is available. client = utils.get_rest_client( manager_ip=management_ip, rest_port=rest_port) try: status_result = client.manager.get_status() except CloudifyClientError: status_result = None if not status_result: msg = ("Can't use management server {0}: No response." .format(management_ip)) raise CloudifyCliError(msg) # check if cloudify was initialized. if not utils.is_initialized(): utils.dump_cloudify_working_dir_settings() utils.dump_configuration_file() try: response = utils.get_rest_client( management_ip).manager.get_context() provider_context = response['context'] except CloudifyClientError: provider_context = None with utils.update_wd_settings() as wd_settings: wd_settings.set_management_server(management_ip) wd_settings.set_provider_context(provider_context) wd_settings.set_rest_port(rest_port) logger.info('Using management server {0} with port {1}' .format(management_ip, rest_port)) # delete the previous manager deployment if exists. bs.delete_workdir()
def get(node_instance_id): logger = get_logger() rest_host = utils.get_rest_host() client = utils.get_rest_client(rest_host) logger.info('Retrieving node instance with ID: \'{0}\' [manager={1}]' .format(node_instance_id, rest_host)) try: node_instance = client.node_instances.get(node_instance_id) except CloudifyClientError as e: if e.status_code != 404: raise raise CloudifyCliError('Node instance {0} not found') columns = ['id', 'deployment_id', 'host_id', 'node_id', 'state'] pt = utils.table(columns, [node_instance]) pt.max_width = 50 utils.print_table('Instance:', pt) # print node instance runtime properties logger.info('Instance runtime properties:') for prop_name, prop_value in utils.decode_dict( node_instance.runtime_properties).iteritems(): logger.info('\t{0}: {1}'.format(prop_name, prop_value)) logger.info('')
def create(blueprint_id, deployment_id, inputs): logger = get_logger() rest_host = utils.get_rest_host() inputs = utils.inputs_to_dict(inputs, 'inputs') logger.info('Creating new deployment from blueprint {0} at ' 'management server {1}' .format(blueprint_id, rest_host)) client = utils.get_rest_client(rest_host) try: deployment = client.deployments.create(blueprint_id, deployment_id, inputs=inputs) except MissingRequiredDeploymentInputError as e: logger.info('Unable to create deployment. Not all ' 'required inputs have been specified...') _print_deployment_inputs(client, blueprint_id) raise SuppressedCloudifyCliError(str(e)) except UnknownDeploymentInputError as e: logger.info( 'Unable to create deployment, an unknown input was specified...') _print_deployment_inputs(client, blueprint_id) raise SuppressedCloudifyCliError(str(e)) logger.info("Deployment created. The deployment's id is {0}".format( deployment.id))
def cancelByExecutionId(execution_id, force, wait, timeout=900): logger = get_logger() management_ip = utils.get_management_server_ip() client = utils.get_rest_client(management_ip) logger.info('{0}Cancelling execution {1} on management server {2}'.format( 'Force-' if force else '', execution_id, management_ip)) execution = client.executions.cancel(execution_id, force) logger.info( 'A cancel request for execution {0} has been sent to management ' "server {1}. To track the execution's status, use:\n" "cfy executions get -e {0}".format(execution_id, management_ip)) if wait: try: logger.info( 'Waiting for execution {0} to finish being cancelled'.format( execution_id)) execution = wait_for_cancel(client, execution, timeout=timeout) if execution.error: logger.info("Cancellation of execution '{0}' " "failed. [error={2}]".format( execution_id, execution.error)) raise SuppressedCloudifyCliError() else: logger.info( "Finished cancelling execution '{0}'".format(execution_id)) except ExecutionTimeoutError, e: logger.info("Cancellation of execution '{0}' timed out. ".format( e.execution_id)) raise SuppressedCloudifyCliError()
def ls(blueprint_id, sort_by=None, descending=False): logger = get_logger() rest_host = utils.get_rest_host() client = utils.get_rest_client(rest_host) if blueprint_id: logger.info("Listing deployments for blueprint: " "'{0}'... [manager={1}]" .format(blueprint_id, rest_host)) else: logger.info('Listing all deployments...[manager={0}]' .format(rest_host)) deployments = client.deployments.list( sort=sort_by, is_descending=descending) if blueprint_id: deployments = filter(lambda deployment: deployment['blueprint_id'] == blueprint_id, deployments) pt = utils.table( ['id', 'blueprint_id', 'created_at', 'updated_at'], deployments) utils.print_table('Deployments:', pt)
def download(blueprint_id, output): logger = get_logger() management_ip = utils.get_management_server_ip() logger.info('Downloading blueprint {0}...'.format(blueprint_id)) client = utils.get_rest_client(management_ip) target_file = client.blueprints.download(blueprint_id, output) logger.info('Blueprint downloaded as {1}'.format(target_file))
def _get_provider_name_and_context(mgmt_ip): logger = get_logger() # trying to retrieve provider context from server try: response = utils.get_rest_client(mgmt_ip).manager.get_context() return response['name'], response['context'] except rest_exception.CloudifyClientError as e: logger.warn('Failed to get provider context from server: {0}'.format( str(e))) # using the local provider context instead (if it's relevant for the # target server) cosmo_wd_settings = utils.load_cloudify_working_dir_settings() if cosmo_wd_settings.get_provider_context(): default_mgmt_server_ip = cosmo_wd_settings.get_management_server() if default_mgmt_server_ip == mgmt_ip: provider_name = utils.get_provider() return provider_name, cosmo_wd_settings.get_provider_context() else: # the local provider context data is for a different server msg = "Failed to get provider context from target server" else: msg = "Provider context is not set in working directory settings (" \ "The provider is used during the bootstrap and teardown " \ "process. This probably means that the manager was started " \ "manually, without the bootstrap command therefore calling " \ "teardown is not supported)." raise RuntimeError(msg)
def status(): logger = get_logger() management_ip = utils.get_management_server_ip() logger.info('Getting management services status... [ip={0}]' .format(management_ip)) client = utils.get_rest_client(management_ip) try: status_result = client.manager.get_status() except UserUnauthorizedError: logger.info("Can't query management server status: User is " "unauthorized") return False except CloudifyClientError: logger.info('REST service at management server ' '{0} is not responding!' .format(management_ip)) return False services = [] for service in status_result['services']: state = service['instances'][0]['state'] \ if 'instances' in service and \ len(service['instances']) > 0 else 'unknown' services.append({ 'service': service['display_name'].ljust(30), 'status': state }) pt = utils.table(['service', 'status'], data=services) utils.print_table('Services:', pt) return True
def cancelByExecutionId(execution_id, force, wait, timeout=900): logger = get_logger() management_ip = utils.get_management_server_ip() client = utils.get_rest_client(management_ip) logger.info( '{0}Cancelling execution {1} on management server {2}' .format('Force-' if force else '', execution_id, management_ip)) execution = client.executions.cancel(execution_id, force) logger.info( 'A cancel request for execution {0} has been sent to management ' "server {1}. To track the execution's status, use:\n" "cfy executions get -e {0}" .format(execution_id, management_ip)) if wait: try: logger.info('Waiting for execution {0} to finish being cancelled' .format(execution_id)) execution = wait_for_cancel(client, execution, timeout=timeout) if execution.error: logger.info("Cancellation of execution '{0}' " "failed. [error={2}]" .format(execution_id, execution.error)) raise SuppressedCloudifyCliError() else: logger.info("Finished cancelling execution '{0}'" .format(execution_id)) except ExecutionTimeoutError, e: logger.info("Cancellation of execution '{0}' timed out. " .format(e.execution_id)) raise SuppressedCloudifyCliError()
def download(snapshot_id, output): logger = get_logger() management_ip = utils.get_management_server_ip() logger.info('Downloading snapshot {0}...'.format(snapshot_id)) client = utils.get_rest_client(management_ip) target_file = client.snapshots.download(snapshot_id, output) logger.info('Snapshot downloaded as {0}'.format(target_file))
def publish_archive(archive_location, blueprint_filename, blueprint_id): logger = get_logger() management_ip = utils.get_management_server_ip() for archive_type in SUPPORTED_ARCHIVE_TYPES: if archive_location.endswith('.{0}'.format(archive_type)): break else: raise CloudifyCliError( "Can't publish archive {0} - it's of an unsupported archive type. " "Supported archive types: {1}".format(archive_location, SUPPORTED_ARCHIVE_TYPES)) archive_location_type = 'URL' if not urlparse.urlparse(archive_location).scheme: # archive_location is not a URL - validate it's a file path if not os.path.isfile(archive_location): raise CloudifyCliError( "Can't publish archive {0} - it's not a valid URL nor a path " "to an archive file".format(archive_location)) archive_location_type = 'path' archive_location = os.path.expanduser(archive_location) logger.info('Publishing blueprint archive from {0} {1} to management ' 'server {2}' .format(archive_location_type, archive_location, management_ip)) client = utils.get_rest_client(management_ip) blueprint = client.blueprints.publish_archive( archive_location, blueprint_id, blueprint_filename) logger.info("Published blueprint archive, blueprint's id is: {0}" .format(blueprint.id))
def ls(execution_id, include_logs): logger = get_logger() management_ip = utils.get_management_server_ip() logger.info("Getting events from management server {0} for " "execution id '{1}' " "[include_logs={2}]".format(management_ip, execution_id, include_logs)) client = utils.get_rest_client(management_ip) try: execution_events = ExecutionEventsFetcher( client, execution_id, include_logs=include_logs) events = execution_events.fetch_all() events_logger = get_events_logger() events_logger(events) logger.info('\nTotal events: {0}'.format(len(events))) except CloudifyClientError, e: if e.status_code != 404: raise msg = ("Execution '{0}' not found on management server" .format(execution_id)) raise CloudifyCliError(msg)
def ls(deployment_id, include_system_workflows, sort_by=None, descending=False): logger = get_logger() rest_host = utils.get_rest_host() client = utils.get_rest_client(rest_host) try: if deployment_id: logger.info('Listing executions for deployment: \'{0}\' ' '[manager={1}]'.format(deployment_id, rest_host)) else: logger.info( 'Listing all executions: [manager={0}]'.format( rest_host)) executions = client.executions.list( deployment_id=deployment_id, include_system_workflows=include_system_workflows, sort=sort_by, is_descending=descending) except exceptions.CloudifyClientError as e: if e.status_code != 404: raise raise CloudifyCliError('Deployment {0} does not exist'.format( deployment_id)) columns = ['id', 'workflow_id', 'deployment_id', 'status', 'created_at'] pt = utils.table(columns, executions) utils.print_table('Executions:', pt) if any(execution.status in (execution.CANCELLING, execution.FORCE_CANCELLING) for execution in executions): logger.info(_STATUS_CANCELING_MESSAGE)
def delete(snapshot_id): logger = get_logger() management_ip = utils.get_management_server_ip() logger.info('Deleting snapshot {0}...'.format(snapshot_id)) client = utils.get_rest_client(management_ip) client.snapshots.delete(snapshot_id) logger.info('Snapshot deleted successfully')
def _upload_resources(manager_node, fabric_env, management_ip, rest_port, protocol, retries, wait_interval): """ Uploads resources supplied in the manager blueprint. uses both fabric for the dsl_resources, and the upload plugins mechanism for plugin_resources. :param manager_node: The manager node from which to retrieve the properties from. :param fabric_env: fabric env in order to upload the dsl_resources. :param management_ip: used to retrieve rest client for the the manager. :param rest_port: used to retrieve rest client for the the manager. :param protocol: used to retrieve rest client for the the manager. """ upload_resources = \ manager_node.properties['cloudify'].get('upload_resources', {}) params = upload_resources.get('parameters', {}) fetch_timeout = params.get('fetch_timeout') or 30 rest_client = utils.get_rest_client(management_ip, rest_port, protocol) # Every resource is first moved/downloaded to this temp dir. temp_dir = tempfile.mkdtemp() try: _upload_plugins(upload_resources.get('plugin_resources', ()), temp_dir, management_ip, rest_client, retries, wait_interval, fetch_timeout) _upload_dsl_resources(upload_resources.get('dsl_resources', ()), temp_dir, fabric_env, retries, wait_interval, fetch_timeout) finally: shutil.rmtree(temp_dir, ignore_errors=True)
def download(plugin_id, output): logger = get_logger() rest_host = utils.get_rest_host() logger.info("Downloading plugin '{0}' from management server {1}...".format(plugin_id, rest_host)) client = utils.get_rest_client(rest_host) target_file = client.plugins.download(plugin_id, output) logger.info("Plugin downloaded as {0}".format(target_file))
def uninstall(deployment_id, workflow_id, parameters, allow_custom_parameters, timeout, include_logs, json): # Although the `uninstall` command does not use the `force` argument, # we are using the `executions start` handler as a part of it. # As a result, we need to provide it with a `force` argument, which is # defined below. force = False # if no workflow was supplied, execute the `uninstall` workflow if not workflow_id: workflow_id = DEFAULT_UNINSTALL_WORKFLOW executions.start(workflow_id=workflow_id, deployment_id=deployment_id, timeout=timeout, force=force, allow_custom_parameters=allow_custom_parameters, include_logs=include_logs, parameters=parameters, json=json) # before deleting the deployment, save its blueprint_id, so we will be able # to delete the blueprint after deleting the deployment client = utils.get_rest_client() deployment = client.deployments.get(deployment_id, _include=['blueprint_id']) blueprint_id = deployment.blueprint_id deployments.delete(deployment_id, ignore_live_nodes=False) blueprints.delete(blueprint_id)
def ls(sort_by=None, descending=False): logger = get_logger() rest_host = utils.get_rest_host() client = utils.get_rest_client(rest_host) logger.info('Getting blueprints list... [manager={0}]' .format(rest_host)) def trim_description(blueprint): if blueprint['description'] is not None: if len(blueprint['description']) >= DESCRIPTION_LIMIT: blueprint['description'] = '{0}..'.format( blueprint['description'][:DESCRIPTION_LIMIT - 2]) else: blueprint['description'] = '' return blueprint blueprints = [trim_description(b) for b in client.blueprints.list( sort=sort_by, is_descending=descending)] pt = utils.table(['id', 'description', 'main_file_name', 'created_at', 'updated_at'], data=blueprints) utils.print_table('Available blueprints:', pt)
def get(blueprint_id): logger = get_logger() management_ip = utils.get_management_server_ip() client = utils.get_rest_client(management_ip) logger.info('Getting blueprint: ' '\'{0}\' [manager={1}]'.format(blueprint_id, management_ip)) blueprint = client.blueprints.get(blueprint_id) deployments = client.deployments.list(_include=['id'], blueprint_id=blueprint_id) blueprint['#deployments'] = len(deployments) pt = utils.table( ['id', 'main_file_name', 'created_at', 'updated_at', '#deployments'], [blueprint]) pt.max_width = 50 utils.print_table('Blueprint:', pt) logger.info('Description:') logger.info('{0}\n'.format(blueprint['description'] if blueprint['description'] is not None else '')) logger.info('Existing deployments:') logger.info('{0}\n'.format(json.dumps([d['id'] for d in deployments])))
def publish_archive(archive_location, blueprint_filename, blueprint_id): logger = get_logger() management_ip = utils.get_management_server_ip() for archive_type in SUPPORTED_ARCHIVE_TYPES: if archive_location.endswith('.{0}'.format(archive_type)): break else: raise CloudifyCliError( "Can't publish archive {0} - it's of an unsupported archive type. " "Supported archive types: {1}".format(archive_location, SUPPORTED_ARCHIVE_TYPES)) archive_location_type = 'URL' if not urlparse.urlparse(archive_location).scheme: # archive_location is not a URL - validate it's a file path if not os.path.isfile(archive_location): raise CloudifyCliError( "Can't publish archive {0} - it's not a valid URL nor a path " "to an archive file".format(archive_location)) archive_location_type = 'path' archive_location = os.path.expanduser(archive_location) logger.info('Publishing blueprint archive from {0} {1} to management ' 'server {2}'.format(archive_location_type, archive_location, management_ip)) client = utils.get_rest_client(management_ip) blueprint = client.blueprints.publish_archive(archive_location, blueprint_id, blueprint_filename) logger.info("Published blueprint archive, blueprint's id is: {0}".format( blueprint.id))
def delete(blueprint_id): logger = get_logger() management_ip = utils.get_management_server_ip() logger.info('Deleting blueprint {0}...'.format(blueprint_id)) client = utils.get_rest_client(management_ip) client.blueprints.delete(blueprint_id) logger.info('Blueprint deleted')
def get(execution_id): logger = get_logger() rest_host = utils.get_rest_host() client = utils.get_rest_client(rest_host) try: logger.info('Getting execution: ' '\'{0}\' [manager={1}]' .format(execution_id, rest_host)) execution = client.executions.get(execution_id) except exceptions.CloudifyClientError as e: if e.status_code != 404: raise raise CloudifyCliError('Execution {0} not found'.format(execution_id)) pt = utils.table(['id', 'workflow_id', 'status', 'deployment_id', 'created_at', 'error'], [execution]) pt.max_width = 50 utils.print_table('Executions:', pt) # print execution parameters logger.info('Execution Parameters:') for param_name, param_value in utils.decode_dict( execution.parameters).iteritems(): logger.info('\t{0}: \t{1}'.format(param_name, param_value)) if execution.status in (execution.CANCELLING, execution.FORCE_CANCELLING): logger.info(_STATUS_CANCELING_MESSAGE) logger.info('')
def get(blueprint_id): logger = get_logger() management_ip = utils.get_management_server_ip() client = utils.get_rest_client(management_ip) logger.info('Getting blueprint: ' '\'{0}\' [manager={1}]' .format(blueprint_id, management_ip)) blueprint = client.blueprints.get(blueprint_id) deployments = client.deployments.list(_include=['id'], blueprint_id=blueprint_id) blueprint['#deployments'] = len(deployments) pt = utils.table(['id', 'main_file_name', 'created_at', 'updated_at', '#deployments'], [blueprint]) pt.max_width = 50 utils.print_table('Blueprint:', pt) logger.info('Description:') logger.info('{0}\n'.format(blueprint['description'] if blueprint['description'] is not None else '')) logger.info('Existing deployments:') logger.info('{0}\n'.format(json.dumps([d['id'] for d in deployments])))
def download(plugin_id, output): logger = get_logger() management_ip = utils.get_management_server_ip() logger.info('Downloading plugin {0}...'.format(plugin_id)) client = utils.get_rest_client(management_ip) target_file = client.plugins.download(plugin_id, output) logger.info('Plugin downloaded as {0}'.format(target_file))
def upload(snapshot_path, snapshot_id): logger = get_logger() management_ip = utils.get_management_server_ip() logger.info("Uploading snapshot '{0}' to management server {1}".format( snapshot_path.name, management_ip)) client = utils.get_rest_client(management_ip) snapshot = client.snapshots.upload(snapshot_path.name, snapshot_id) logger.info("Uploaded snapshot with id: {0}".format(snapshot.id))
def delete(blueprint_id): logger = get_logger() rest_host = utils.get_rest_host() logger.info('Deleting blueprint {0} from management server {1}' .format(blueprint_id, rest_host)) client = utils.get_rest_client(rest_host) client.blueprints.delete(blueprint_id) logger.info('Blueprint deleted')
def delete(snapshot_id): logger = get_logger() management_ip = utils.get_management_server_ip() logger.info("Deleting snapshot '{0}' from management server {1}" .format(snapshot_id, management_ip)) client = utils.get_rest_client(management_ip) client.snapshots.delete(snapshot_id) logger.info('Deleted snapshot successfully')
def delete(deployment_id, ignore_live_nodes): logger = get_logger() rest_host = utils.get_rest_host() logger.info('Deleting deployment {0} from management server {1}' .format(deployment_id, rest_host)) client = utils.get_rest_client(rest_host) client.deployments.delete(deployment_id, ignore_live_nodes) logger.info("Deployment deleted")
def download(blueprint_id, output): logger = get_logger() management_ip = utils.get_management_server_ip() logger.info(messages.DOWNLOADING_BLUEPRINT.format(blueprint_id)) client = utils.get_rest_client(management_ip) target_file = client.blueprints.download(blueprint_id, output) logger.info(messages.DOWNLOADING_BLUEPRINT_SUCCEEDED .format(blueprint_id, target_file))
def delete(blueprint_id): logger = get_logger() management_ip = utils.get_management_server_ip() logger.info('Deleting blueprint {0} from management server {1}' .format(blueprint_id, management_ip)) client = utils.get_rest_client(management_ip) client.blueprints.delete(blueprint_id) logger.info('Deleted blueprint successfully')
def delete(snapshot_id): logger = get_logger() management_ip = utils.get_management_server_ip() logger.info("Deleting snapshot '{0}' from management server {1}".format( snapshot_id, management_ip)) client = utils.get_rest_client(management_ip) client.snapshots.delete(snapshot_id) logger.info('Deleted snapshot successfully')
def download(snapshot_id, output): logger = get_logger() rest_host = utils.get_rest_host() logger.info("Downloading snapshot '{0}'... [manager={1}]".format( snapshot_id, rest_host)) client = utils.get_rest_client(rest_host) target_file = client.snapshots.download(snapshot_id, output) logger.info('Snapshot downloaded as {0}'.format(target_file))
def delete(blueprint_id): logger = get_logger() management_ip = utils.get_management_server_ip() logger.info('Deleting blueprint {0} from management server {1}'.format( blueprint_id, management_ip)) client = utils.get_rest_client(management_ip) client.blueprints.delete(blueprint_id) logger.info('Deleted blueprint successfully')
def delete(deployment_id, ignore_live_nodes): logger = get_logger() management_ip = utils.get_management_server_ip() logger.info('Deleting deployment {0} from management server {1}' .format(deployment_id, management_ip)) client = utils.get_rest_client(management_ip) client.deployments.delete(deployment_id, ignore_live_nodes) logger.info("Deleted deployment successfully")
def deactivate(): logger = get_logger() management_ip = utils.get_management_server_ip() client = utils.get_rest_client(management_ip) logger.info('Deactivating maintenance mode...') client.maintenance_mode.deactivate() logger.info('Maintenance mode deactivated.')
def ls(): logger = get_logger() management_ip = utils.get_management_server_ip() client = utils.get_rest_client(management_ip) logger.info('Listing snapshots...') pt = utils.table(['id', 'created_at', 'status', 'error'], data=client.snapshots.list()) print_table('Snapshots:', pt)
def upload(snapshot_path, snapshot_id): logger = get_logger() management_ip = utils.get_management_server_ip() logger.info('Uploading snapshot {0}...'.format(snapshot_path.name)) client = utils.get_rest_client(management_ip) snapshot = client.snapshots.upload(snapshot_path.name, snapshot_id) logger.info("Snapshot uploaded. The snapshot's id is {0}".format( snapshot.id))
def create(snapshot_id, include_metrics, exclude_credentials): logger = get_logger() management_ip = utils.get_management_server_ip() logger.info("Creating snapshot '{0}' to management server {1}".format( snapshot_id, management_ip)) client = utils.get_rest_client(management_ip) execution = client.snapshots.create(snapshot_id, include_metrics, not exclude_credentials) logger.info('Started workflow\'s execution id: {0}'.format(execution.id))
def ls(): logger = get_logger() management_ip = utils.get_management_server_ip() client = utils.get_rest_client(management_ip) logger.info( 'Retrieving snapshots list... [manager={0}]'.format(management_ip)) pt = utils.table(['id', 'created_at', 'status', 'error'], data=client.snapshots.list()) print_table('Snapshots:', pt)
def delete(plugin_id): logger = get_logger() management_ip = utils.get_management_server_ip() client = utils.get_rest_client(management_ip) logger.info(messages.PLUGIN_DELETE.format(plugin_id, management_ip)) client.plugins.delete(plugin_id) logger.info(messages.PLUGIN_DELETE_SUCCEEDED.format(plugin_id))
def restore(snapshot_id, without_deployments_envs, force): logger = get_logger() management_ip = utils.get_management_server_ip() logger.info("Restoring snapshot '{0}' at management server {1}".format( snapshot_id, management_ip)) client = utils.get_rest_client(management_ip) execution = client.snapshots.restore(snapshot_id, not without_deployments_envs, force) logger.info('Started workflow\'s execution id: {0}'.format(execution.id))
def download(plugin_id, output): logger = get_logger() management_ip = utils.get_management_server_ip() logger.info(messages.DOWNLOADING_PLUGIN.format(plugin_id)) client = utils.get_rest_client(management_ip) target_file = client.plugins.download(plugin_id, output) logger.info(messages.DOWNLOADING_PLUGIN_SUCCEEDED.format(plugin_id, target_file))
def download(blueprint_id, output): logger = get_logger() management_ip = utils.get_management_server_ip() logger.info(messages.DOWNLOADING_BLUEPRINT.format(blueprint_id)) client = utils.get_rest_client(management_ip) target_file = client.blueprints.download(blueprint_id, output) logger.info( messages.DOWNLOADING_BLUEPRINT_SUCCEEDED.format( blueprint_id, target_file))
def ls(): logger = get_logger() management_ip = utils.get_management_server_ip() client = utils.get_rest_client(management_ip) logger.info(messages.PLUGINS_LIST.format(management_ip)) plugins = client.plugins.list(_include=fields) pt = utils.table(fields, data=plugins) print_table('Plugins:', pt)
def download(snapshot_id, output): logger = get_logger() management_ip = utils.get_management_server_ip() logger.info("Downloading snapshot '{0}'... [manager={1}]".format( snapshot_id, management_ip)) client = utils.get_rest_client(management_ip) target_file = client.snapshots.download(snapshot_id, output) logger.info( "Snapshot '{0}' has been downloaded successfully as '{1}'".format( snapshot_id, target_file))
def get(plugin_id): logger = get_logger() management_ip = utils.get_management_server_ip() client = utils.get_rest_client(management_ip) logger.info(messages.PLUGINS_GET.format(plugin_id, management_ip)) plugin = client.plugins.get(plugin_id, _include=fields) pt = utils.table(fields, data=[plugin]) print_table('Plugin:', pt)
def _objects_args_completer(prefix, **kwargs): cosmo_wd_settings = utils.load_cloudify_working_dir_settings( suppress_error=True) if not cosmo_wd_settings: return [] mgmt_ip = cosmo_wd_settings.get_management_server() rest_client = utils.get_rest_client(mgmt_ip) objs_ids_list = getattr(rest_client, objects_type).list( _include=['id']) return (obj.id for obj in objs_ids_list if obj.id.startswith(prefix))
def main(deployment_id): management_ip = utils.get_management_server_ip() client = utils.get_rest_client(management_ip) outputs_resp = client.deployments.outputs.get(deployment_id) endpoint = outputs_resp.outputs['endpoint'] # Making sure that Nodecellar works response = requests.get( 'http://{0}:{1}'.format(endpoint["ip_address"], endpoint["port"]) ) assert 200 == response.status_code, "Nodecellar is not up.."
def cancel(execution_id, force): logger = get_logger() management_ip = utils.get_management_server_ip() client = utils.get_rest_client(management_ip) logger.info('{0}Cancelling execution {1} on management server {2}'.format( 'Force-' if force else '', execution_id, management_ip)) client.executions.cancel(execution_id, force) logger.info( 'A cancel request for execution {0} has been sent to management ' "server {1}. To track the execution's status, use:\n" "cfy executions get -e {0}".format(execution_id, management_ip))
def ls(): logger = get_logger() management_ip = utils.get_management_server_ip() client = utils.get_rest_client(management_ip) logger.info( 'Getting blueprints list... [manager={0}]'.format(management_ip)) pt = utils.table(['id', 'created_at', 'updated_at'], data=client.blueprints.list()) print_table('Blueprints:', pt)
def upload(blueprint_path, blueprint_id): logger = get_logger() management_ip = utils.get_management_server_ip() validate(blueprint_path) logger.info('Uploading blueprint {0} to management server {1}'.format( blueprint_path.name, management_ip)) client = utils.get_rest_client(management_ip) blueprint = client.blueprints.upload(blueprint_path.name, blueprint_id) logger.info("Uploaded blueprint, blueprint's id is: {0}".format( blueprint.id))
def _get_number_of_deployments(management_ip): client = utils.get_rest_client(management_ip) try: return len(client.deployments.list()) except CloudifyClientError: raise exceptions.CloudifyCliError( "Failed querying manager server {0} about existing " "deployments; The Manager server may be down. If you wish to " "skip this check, you may use the " '--ignore-deployments' " " "flag, in which case teardown will occur regardless of " "the deployments status.".format(management_ip))
def upload(blueprint_path, blueprint_id, pre_validate): logger = get_logger() management_ip = utils.get_management_server_ip() if pre_validate: validate(blueprint_path) else: logger.debug("Skipping blueprint validation") logger.info('Uploading blueprint {0} to management server {1}'.format( blueprint_path.name, management_ip)) client = utils.get_rest_client(management_ip) blueprint = client.blueprints.upload(blueprint_path.name, blueprint_id) logger.info("Uploaded blueprint, blueprint's id is: {0}".format( blueprint.id))
def _get_manager_version_data(self): dir_settings = load_cloudify_working_dir_settings(suppress_error=True) if not (dir_settings and dir_settings.get_management_server()): return None management_ip = dir_settings.get_management_server() if not self._connected_to_manager(management_ip): return None client = get_rest_client(management_ip) try: version_data = client.manager.get_version() except CloudifyClientError: return None version_data['ip'] = management_ip return version_data
def test_get_secured_rest_client(self): protocol = 'https' host = 'localhost' port = 443 client = utils.get_rest_client(manager_ip=host, rest_port=port, protocol=protocol) self.assertEqual(CERT_PATH, client._client.cert) self.assertTrue(client._client.trust_all) self.assertEqual( '{0}://{1}:{2}/api/{3}'.format(protocol, host, port, API_VERSION), client._client.url)
def get(node_instance_id): logger = get_logger() management_ip = utils.get_management_server_ip() client = utils.get_rest_client(management_ip) logger.info('Getting node instance with ID: \'{0}\' [manager={1}]'.format( node_instance_id, management_ip)) try: node_instance = client.node_instances.get(node_instance_id) except CloudifyClientError, e: if e.status_code != 404: raise msg = ("Node instance with ID '{0}' was not found on the management " "server".format(node_instance_id)) raise CloudifyCliError(msg)