def teardown(force, ignore_deployments): logger = get_logger() management_ip = utils.get_management_server_ip() if not force: msg = ("This action requires additional " "confirmation. Add the '-f' or '--force' " "flags to your command if you are certain " "this command should be executed.") raise exceptions.CloudifyCliError(msg) client = utils.get_rest_client(management_ip) try: if not ignore_deployments and len(client.deployments.list()) > 0: msg = \ ("Manager server {0} has existing deployments. Delete all " "deployments first or add the '--ignore-deployments' flag to " "your command to ignore these deployments and execute " "teardown.".format(management_ip)) raise exceptions.CloudifyCliError(msg) except IOError: msg = \ "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 Manager ' \ "server's status.".format(management_ip) raise exceptions.CloudifyCliError(msg) logger.info("tearing down {0}".format(management_ip)) # runtime properties might have changed since the last time we # executed 'use', because of recovery. so we need to retrieve # the provider context again try: logger.info('Retrieving provider context') management_ip = utils.get_management_server_ip() use(management_ip, utils.get_rest_port()) except BaseException as e: logger.warning('Failed retrieving provider context: {0}. This ' 'may cause a leaking management server ' 'in case it has gone through a ' 'recovery process'.format(str(e))) # reload settings since the provider context maybe changed settings = utils.load_cloudify_working_dir_settings() provider_context = settings.get_provider_context() bs.read_manager_deployment_dump_if_needed( provider_context.get('cloudify', {}).get('manager_deployment')) bs.teardown() # cleaning relevant data from working directory settings with utils.update_wd_settings() as wd_settings: # wd_settings.set_provider_context(provider_context) wd_settings.remove_management_server_context() logger.info("teardown complete")
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 update_inputs(inputs=None): inputs = utils.inputs_to_dict(inputs, 'inputs') or {} inputs.update({'private_ip': _load_private_ip(inputs)}) inputs.update({'ssh_key_filename': _load_management_key(inputs)}) inputs.update({'ssh_user': _load_management_user(inputs)}) inputs.update({'public_ip': utils.get_management_server_ip()}) return inputs
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 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 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 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 get_agents(client=None, manager_ip=None): if client is None: client = _get_rest_client() if manager_ip is None: manager_ip = cli_utils.get_management_server_ip() mgr_version = client.manager.get_version()['version'] version = next((v for v in ['3.2.1', '3.2'] if mgr_version.startswith(v)), None) if version is None: raise RuntimeError('Unknown manager version {0}'.format(mgr_version)) bootstrap_agent = client.manager.get_context().get('context', {}).get( 'cloudify', {}).get('cloudify_agent', {}) result = {} for deployment in client.deployments.list(): deployment_result = {} for node in client.nodes.list(deployment_id=deployment.id): if _is_compute(node): node_result = {} for node_instance in client.node_instances.list( deployment_id=deployment.id, node_name=node.id): node_result[node_instance.id] = _get_node_instance_agent( node_instance, node, bootstrap_agent, manager_ip, version) deployment_result[node.id] = node_result result[deployment.id] = deployment_result return result
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 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 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(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 dev(args, task, tasks_file): management_ip = utils.get_management_server_ip() _execute(username=get_management_user(), key=get_management_key(), ip=management_ip, task=task, tasks_file=tasks_file, args=args)
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 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 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 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 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 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 restore(snapshot_id, without_deployments_envs, force): logger = get_logger() management_ip = utils.get_management_server_ip() logger.info('Restoring snapshot {0}...'.format(snapshot_id)) client = utils.get_rest_client(management_ip) execution = client.snapshots.restore( snapshot_id, not without_deployments_envs, force) logger.info("Started workflow execution. The execution's id is {0}".format( execution.id))
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 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 delete(plugin_id, force): logger = get_logger() management_ip = utils.get_management_server_ip() client = utils.get_rest_client(management_ip) logger.info('Deleting plugin {0}...'.format(plugin_id)) client.plugins.delete(plugin_id=plugin_id, force=force) logger.info('Plugin deleted')
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 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 create(snapshot_id, include_metrics, exclude_credentials): logger = get_logger() management_ip = utils.get_management_server_ip() logger.info('Creating snapshot {0}...'.format(snapshot_id)) client = utils.get_rest_client(management_ip) execution = client.snapshots.create(snapshot_id, include_metrics, not exclude_credentials) logger.info("Started workflow execution. The execution's id is {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('Listing all plugins...') plugins = client.plugins.list(_include=fields) pt = utils.table(fields, data=plugins) print_table('Plugins:', pt)
def get(plugin_id): logger = get_logger() management_ip = utils.get_management_server_ip() client = utils.get_rest_client(management_ip) logger.info('Retrieving plugin {0}...'.format(plugin_id)) plugin = client.plugins.get(plugin_id, _include=fields) pt = utils.table(fields, data=[plugin]) print_table('Plugin:', 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 ls(deployment_id): logger = get_logger() management_ip = utils.get_management_server_ip() client = utils.get_rest_client(management_ip) try: if deployment_id: logger.info('Getting executions list for deployment: \'{0}\' ' '[manager={1}]'.format(deployment_id, management_ip)) else: logger.info( 'Getting a list of all executions: [manager={0}]'.format( management_ip)) executions = client.executions.list(deployment_id=deployment_id) except exceptions.CloudifyClientError, e: if not e.status_code != 404: raise msg = ('Deployment {0} does not exist on management server'.format( deployment_id)) raise CloudifyCliError(msg)
def teardown(force, ignore_deployments): _validate_force(force) try: management_ip = utils.get_management_server_ip() except exceptions.CloudifyCliError: # management ip does not exist in the local context # this can mean one of two things: # 1. bootstrap was unsuccessful # 2. we are in the wrong directory try: bs.load_env() # this means we are probably in the right directory # which means the teardown was unsuccessful, try to teardown # anyway except BaseException: # this means we are in the wrong directory, have the user # execute the 'use' command to retrieve manager deployment, # because other wise we cannot bootstrap from here. If the # manager is down, the user must return to the original # directory in order to teardown raise exceptions.CloudifyCliError( "You are attempting to execute 'teardown' from an " "invalid directory. Please execute 'cfy use' before " "running this command. If the management server is " "unavailable, you must execute this command from the " "directory you initially bootstrapped from, or from the last " "directory a 'cfy use' command was executed on this manager.") else: _do_teardown() else: # make sure we don't teardown the manager if there are running # deployments, unless the user explicitly specified it. _validate_deployments(ignore_deployments, management_ip) # update local provider context since the server id might have # changed in case it has gone through a recovery process. _update_local_provider_context(management_ip) # execute teardown _do_teardown()
def ls(blueprint_id): logger = get_logger() management_ip = utils.get_management_server_ip() client = utils.get_rest_client(management_ip) if blueprint_id: logger.info("Getting deployments list for blueprint: " "'{0}'... [manager={1}]".format(blueprint_id, management_ip)) else: logger.info( 'Getting deployments list...[manager={0}]'.format(management_ip)) deployments = client.deployments.list() 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 ls(deployment_id, node_name=None): logger = get_logger() management_ip = utils.get_management_server_ip() client = utils.get_rest_client(management_ip) try: if deployment_id: logger.info('Getting instances list for deployment: \'{0}\' ' '[manager={1}]'.format(deployment_id, management_ip)) else: logger.info( 'Getting a list of all instances: [manager={0}]'.format( management_ip)) instances = client.node_instances.list(deployment_id=deployment_id, node_name=node_name) except CloudifyClientError, e: if not e.status_code != 404: raise msg = 'Deployment {0} does not exist on management server'\ .format(deployment_id) raise CloudifyCliError(msg)
def get(deployment_id, workflow_id): logger = get_logger() management_ip = utils.get_management_server_ip() client = utils.get_rest_client(management_ip) try: logger.info('Getting workflow ' '\'{0}\' of deployment \'{1}\' [manager={2}]'.format( workflow_id, deployment_id, management_ip)) deployment = client.deployments.get(deployment_id) workflow = next( (wf for wf in deployment.workflows if wf.name == workflow_id), None) if not workflow: msg = ("Workflow '{0}' not found on management server for " "deployment {1}".format(workflow_id, deployment_id)) raise CloudifyCliError(msg) except CloudifyClientError, e: if e.status_code != 404: raise msg = ("Deployment '{0}' not found on management server".format( deployment_id)) raise CloudifyCliError(msg)
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)) 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()] pt = utils.table( ['id', 'description', 'main_file_name', 'created_at', 'updated_at'], data=blueprints) print_table('Blueprints:', pt)
def teardown(force, ignore_deployments, config_file_path, ignore_validation): logger = get_logger() management_ip = utils.get_management_server_ip() if not force: msg = ("This action requires additional " "confirmation. Add the '-f' or '--force' " "flags to your command if you are certain " "this command should be executed.") raise exceptions.CloudifyCliError(msg) client = utils.get_rest_client(management_ip) if not ignore_deployments and len(client.deployments.list()) > 0: msg = ("Management server {0} has active deployments. Add the " "'--ignore-deployments' flag to your command to ignore " "these deployments and execute topology teardown.".format( management_ip)) raise exceptions.CloudifyCliError(msg) settings = utils.load_cloudify_working_dir_settings() if settings.get_is_provider_config(): provider_common.provider_teardown(config_file_path, ignore_validation) else: logger.info("tearing down {0}".format(management_ip)) provider_context = settings.get_provider_context() bs.read_manager_deployment_dump_if_needed( provider_context.get('cloudify', {}).get('manager_deployment')) bs.teardown(name='manager', task_retries=0, task_retry_interval=0, task_thread_pool_size=1) # cleaning relevant data from working directory settings with utils.update_wd_settings() as wd_settings: # wd_settings.set_provider_context(provider_context) wd_settings.remove_management_server_context() logger.info("teardown complete")
def main(args): workflow_id = args[1] configure_loggers() logger = get_logger() manager_ip = utils.get_management_server_ip() client = utils.get_rest_client(manager_ip) deployments = client.deployments.list() results = map(lambda d: deployment_failed_tasks(client, workflow_id, d), deployments) failure_detected = False for res in results: if res.get('type') == RESULT_TASKS: tasks = res.get('failed_tasks') exc = res.get('execution') if tasks: failure_detected = True msg = FAILURE_MSG_FORMAT.format(exc.deployment_id, workflow_id, exc.id) logger.info(msg) get_events_logger()(tasks) logger.info('Total tasks failed: {0}\n'.format(len(tasks))) else: msg = OK_MSG_FORMAT.format(exc.deployment_id, workflow_id, exc.id) logger.info(msg) elif res.get('type') == RESULT_NOT_INSTALLED: deployment = res.get('deployment') logger.info(NOT_INSTALLED_MSG_FORMAT.format(deployment.id)) else: deployment = res.get('deployment') failure_detected = True logger.info( NO_EXECUTION_MSG_FORMAT.format(deployment.id, workflow_id)) if failure_detected: logger.info('Failure detected.') return int(failure_detected)
def upload(plugin_path): server_ip = utils.get_management_server_ip() utils.upload_plugin(plugin_path, server_ip, utils.get_rest_client(server_ip), validate)
import sys import os from cloudify_cli import utils deployment_id = sys.argv[1] management_ip = utils.get_management_server_ip() client = utils.get_rest_client(management_ip) dep = client.deployments.get(deployment_id, _include=['outputs']) response = client.deployments.outputs.get(deployment_id) outputs = response.outputs print(""" export DDS_DNS_SERVER={0} export DDS_HTTP_ENDPOINT={1} """.format(outputs["dns_server"], outputs["http_endpoint"]))
import os, sys from cloudify_cli.utils import (get_management_user, get_management_server_ip, get_management_key) command = 'ssh -n -o BatchMode=yes -i %s %s@%s true 2> /dev/null' % ( get_management_key(), get_management_user(), get_management_server_ip()) command_result = os.system(command) sys.exit(os.WEXITSTATUS(command_result))
def cancelByDeploymentId(deployment_id, force, wait, timeout=900): executions = [] logger = get_logger() management_ip = utils.get_management_server_ip() client = utils.get_rest_client(management_ip) # Retrieve all executions for the provided deployment executionsRaw = client.executions.list( deployment_id=deployment_id, _include=['id', 'status', 'created_at']) # Find only executions that aren't complete for execution in executionsRaw: logger.info('{0} is {1}'.format(execution['id'], execution['status'])) if execution['status'] == 'started': executions.append(execution) if len(executions) > 0: logger.info('{0}Cancelling {1} execution(s) ' 'on management server {2}'.format( 'Force-' if force else '', len(executions), management_ip)) else: logger.info('There are no active executions ' 'for the specified deployment ID') return # Cancel each non-terminated execution one-by-one for execution in executions: 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 the management server {1}'.format( execution['id'], management_ip)) logger.info('To track the execution\'s status, ' 'use:\n cfy executions get -e {0}'.format( execution['id'])) 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 start(workflow_id, deployment_id, timeout, force, allow_custom_parameters, include_logs, parameters): logger = get_logger() parameters = utils.inputs_to_dict(parameters, 'parameters') management_ip = utils.get_management_server_ip() logger.info("Executing workflow '{0}' on deployment '{1}' at" " management server {2} [timeout={3} seconds]".format( workflow_id, deployment_id, management_ip, timeout)) events_logger = get_events_logger() events_message = "* Run 'cfy events list --include-logs " \ "--execution-id {0}' to retrieve the " \ "execution's events/logs" try: client = utils.get_rest_client(management_ip) try: execution = client.executions.start( deployment_id, workflow_id, parameters=parameters, allow_custom_parameters=allow_custom_parameters, force=force) except (exceptions.DeploymentEnvironmentCreationInProgressError, exceptions.DeploymentEnvironmentCreationPendingError) as e: # wait for deployment environment creation workflow if isinstance( e, exceptions.DeploymentEnvironmentCreationPendingError): status = 'pending' else: status = 'in progress' logger.info( 'Deployment environment creation is {0}!'.format(status)) logger.info('Waiting for create_deployment_environment ' 'workflow execution to finish...') now = time.time() wait_for_execution(client, _get_deployment_environment_creation_execution( client, deployment_id), events_handler=events_logger, include_logs=include_logs, timeout=timeout) remaining_timeout = time.time() - now timeout -= remaining_timeout # try to execute user specified workflow execution = client.executions.start( deployment_id, workflow_id, parameters=parameters, allow_custom_parameters=allow_custom_parameters, force=force) execution = wait_for_execution(client, execution, events_handler=events_logger, include_logs=include_logs, timeout=timeout) if execution.error: logger.info("Execution of workflow '{0}' for deployment " "'{1}' failed. [error={2}]".format( workflow_id, deployment_id, execution.error)) logger.info(events_message.format(execution.id)) raise SuppressedCloudifyCliError() else: logger.info("Finished executing workflow '{0}' on deployment" " '{1}'".format(workflow_id, deployment_id)) logger.info(events_message.format(execution.id)) except ExecutionTimeoutError, e: logger.info("Execution of workflow '{0}' " "for deployment '{1}' timed out. " "* Run 'cfy executions cancel " "--execution-id {2}' to cancel" " the running workflow.".format(workflow_id, deployment_id, e.execution_id)) events_tail_message = "* Run 'cfy events list --tail --include-logs " \ "--execution-id {0}' to retrieve the " \ "execution's events/logs" logger.info(events_tail_message.format(e.execution_id)) raise SuppressedCloudifyCliError()
def _get_rest_client(): management_ip = cli_utils.get_management_server_ip() return cli_utils.get_rest_client(management_ip)