예제 #1
0
def get_plugin_source(plugin, blueprint_id=None):

    source = plugin.get('source') or ''
    if not source:
        return None
    source = source.strip()

    # validate source url
    if '://' in source:
        split = source.split('://')
        schema = split[0]
        if schema not in ['http', 'https']:
            # invalid schema
            raise NonRecoverableError('Invalid schema: {0}'.format(schema))
    else:
        # Else, assume its a relative path from <blueprint_home>/plugins
        # to a directory containing the plugin archive.
        # in this case, the archived plugin is expected to reside on the
        # manager file server as a zip file.
        if blueprint_id is None:
            raise ValueError('blueprint_id must be specified when plugin '
                             'source does not contain a schema')
        blueprints_root = get_manager_file_server_blueprints_root_url()
        blueprint_plugins_url = '{0}/{1}/plugins'.format(
            blueprints_root, blueprint_id)

        source = '{0}/{1}.zip'.format(blueprint_plugins_url, source)

    return source
예제 #2
0
def get_plugin_source(plugin, blueprint_id=None):

    source = plugin.get('source') or ''
    if not source:
        return None
    source = source.strip()

    # validate source url
    if '://' in source:
        split = source.split('://')
        schema = split[0]
        if schema not in ['http', 'https']:
            # invalid schema
            raise NonRecoverableError('Invalid schema: {0}'.format(schema))
    else:
        # Else, assume its a relative path from <blueprint_home>/plugins
        # to a directory containing the plugin archive.
        # in this case, the archived plugin is expected to reside on the
        # manager file server as a zip file.
        if blueprint_id is None:
            raise ValueError('blueprint_id must be specified when plugin '
                             'source does not contain a schema')
        blueprints_root = get_manager_file_server_blueprints_root_url()
        blueprint_plugins_url = '{0}/{1}/plugins'.format(
            blueprints_root, blueprint_id)

        source = '{0}/{1}.zip'.format(blueprint_plugins_url, source)

    return source
예제 #3
0
def create_env_string(cloudify_agent):
    env = {
        LOCAL_IP_KEY:
        cloudify_agent['host'],
        MANAGER_IP_KEY:
        get_manager_ip(),
        MANAGER_FILE_SERVER_BLUEPRINTS_ROOT_URL_KEY:
        get_manager_file_server_blueprints_root_url(),
        MANAGER_FILE_SERVER_URL_KEY:
        get_manager_file_server_url(),
        MANAGER_REST_PORT_KEY:
        get_manager_rest_service_port()
    }
    env_string = ''
    for key, value in env.iteritems():
        env_string = '{0} {1}={2}' \
            .format(env_string, key, value)
    return env_string.strip()
예제 #4
0
def create_env_string(cloudify_agent):
    env = {
        LOCAL_IP_KEY:
        cloudify_agent['host'],
        MANAGER_IP_KEY:
        get_manager_ip(),
        MANAGER_FILE_SERVER_BLUEPRINTS_ROOT_URL_KEY:
        get_manager_file_server_blueprints_root_url(),
        MANAGER_FILE_SERVER_URL_KEY:
        get_manager_file_server_url(),
        MANAGER_REST_PORT_KEY:
        get_manager_rest_service_port()
    }
    env_string = ''
    for key, value in env.iteritems():
        env_string = '{0} {1}={2}' \
            .format(env_string, key, value)
    return env_string.strip()
예제 #5
0
def get_url(blueprint_id, plugin):

    source = plugin['source']
    if '://' in source:
        split = source.split('://')
        schema = split[0]
        if schema in ['http', 'https']:
            # in case of a URL, return as is.
            return source
        # invalid schema
        raise NonRecoverableError('Invalid schema: {0}'.format(schema))

    # Else, assume its a relative path from <blueprint_home>/plugins
    # to a directory containing the plugin project.
    # in this case, the archived plugin will reside in the manager file server.

    blueprint_plugins_url = '{0}/{1}/plugins'.format(
        utils.get_manager_file_server_blueprints_root_url(), blueprint_id)
    return '{0}/{1}.zip'.format(blueprint_plugins_url, source)
def create_env_string(cloudify_agent):
    env = {
        constants.CELERY_WORK_DIR_PATH_KEY:
        RUNTIME_AGENT_PATH,
        constants.LOCAL_IP_KEY:
        cloudify_agent['host'],
        constants.MANAGER_IP_KEY:
        utils.get_manager_ip(),
        constants.MANAGER_FILE_SERVER_BLUEPRINTS_ROOT_URL_KEY:
        utils.get_manager_file_server_blueprints_root_url(),
        constants.MANAGER_FILE_SERVER_URL_KEY:
        utils.get_manager_file_server_url(),
        constants.MANAGER_REST_PORT_KEY:
        utils.get_manager_rest_service_port()
    }
    env_string = ''
    for key, value in env.iteritems():
        env_string = '{0} {1}={2}' \
            .format(env_string, key, value)
    return env_string.strip()
예제 #7
0
def get_url(blueprint_id, plugin):

    source = plugin['source']
    if '://' in source:
        split = source.split('://')
        schema = split[0]
        if schema in ['http', 'https']:
            # in case of a URL, return as is.
            return source
        # invalid schema
        raise NonRecoverableError('Invalid schema: {0}'.format(schema))

    # else, assume its a relative path from <blueprint_home>/plugins
    # to a directory containing the plugin project.
    # in this case, the archived plugin will reside in the manager file server.
    blueprint_plugins_url = '{0}/{1}/plugins'.format(
        utils.get_manager_file_server_blueprints_root_url(),
        blueprint_id
    )
    return '{0}/{1}.zip'.format(blueprint_plugins_url, source)
예제 #8
0
def create_env_string(cloudify_agent):
    env = {
        constants.CELERY_WORK_DIR_PATH_KEY:
        RUNTIME_AGENT_PATH,
        constants.LOCAL_IP_KEY:
        cloudify_agent['host'],
        constants.MANAGER_IP_KEY:
        utils.get_manager_ip(),
        constants.MANAGER_FILE_SERVER_BLUEPRINTS_ROOT_URL_KEY:
        utils.get_manager_file_server_blueprints_root_url(),
        constants.MANAGER_FILE_SERVER_URL_KEY:
        utils.get_manager_file_server_url(),
        constants.MANAGER_REST_PORT_KEY:
        utils.get_manager_rest_service_port()
    }
    env_string = ''
    for key, value in env.iteritems():
        env_string = '{0} {1}={2}' \
            .format(env_string, key, value)
    return env_string.strip()
예제 #9
0
def get_url_and_args(blueprint_id, plugin_dict):

    source = plugin_dict.get('source') or ''
    if source:
        source = source.strip()
    else:
        raise NonRecoverableError('Plugin source is not defined')

    install_args = plugin_dict.get('install_arguments') or ''
    install_args = install_args.strip()

    # validate source url
    if '://' in source:
        split = source.split('://')
        schema = split[0]
        if schema not in ['http', 'https']:
            # invalid schema
            raise NonRecoverableError('Invalid schema: {0}'.format(schema))
        else:
            # in case of a URL, return source and args as is.
            return source, install_args

    else:
        # Else, assume its a relative path from <blueprint_home>/plugins
        # to a directory containing the plugin archive.
        # in this case, the archived plugin is expected to reside on the
        # manager file server as a zip file.
        blueprints_root = utils.get_manager_file_server_blueprints_root_url()
        if not blueprints_root:
            raise NonRecoverableError('blueprints root "{0}" is empty'
                                      .format(blueprints_root))

        blueprint_plugins_url = '{0}/{1}/plugins'.format(blueprints_root,
                                                         blueprint_id)

        blueprint_plugins_url_as_zip = '{0}/{1}.zip'.\
                                       format(blueprint_plugins_url, source)
        return blueprint_plugins_url_as_zip, install_args
예제 #10
0
def setup_environment(ctx):
    """
    Add some useful environment variables to the environment
    """

    env = os.environ.copy()
    # See in context.py
    # https://github.com/CloudifySource
    # /cosmo-celery-common/blob/develop/cloudify/context.py
    env['CLOUDIFY_NODE_ID'] = ctx.node_id.encode('utf-8')
    env['CLOUDIFY_BLUEPRINT_ID'] = ctx.blueprint_id.encode('utf-8')
    env['CLOUDIFY_DEPLOYMENT_ID'] = ctx.deployment_id.encode('utf-8')
    env['CLOUDIFY_MANAGER_IP'] = get_manager_ip().encode('utf-8')
    env['CLOUDIFY_EXECUTION_ID'] = ctx.execution_id.encode('utf-8')

    logging_script_path = os.path.join(dirname(resources.__file__),
                                       "logging.sh")

    file_server_script_path = os.path.join(dirname(resources.__file__),
                                           "file_server.sh")

    env['CLOUDIFY_LOGGING'] = logging_script_path
    env['CLOUDIFY_FILE_SERVER'] = file_server_script_path

    url = '{0}/{1}'.format(
        utils.get_manager_file_server_blueprints_root_url(),
        ctx.blueprint_id)

    env['CLOUDIFY_FILE_SERVER_BLUEPRINT_ROOT'] = url.encode('utf-8')

    # assuming properties are flat.
    # inject each property as an environment variable.
    for key, value in flatten(ctx.properties).iteritems():
        env[key] = value.encode('utf-8') \
            if isinstance(value, unicode) \
            or isinstance(value, str) else repr(value)

    return env
예제 #11
0
def get_url_and_args(blueprint_id, plugin_dict):

    source = plugin_dict.get('source') or ''
    if source:
        source = source.strip()
    else:
        raise NonRecoverableError('Plugin source is not defined')

    install_args = plugin_dict.get('install_arguments') or ''
    install_args = install_args.strip()

    # validate source url
    if '://' in source:
        split = source.split('://')
        schema = split[0]
        if schema not in ['http', 'https']:
            # invalid schema
            raise NonRecoverableError('Invalid schema: {0}'.format(schema))
        else:
            # in case of a URL, return source and args as is.
            return source, install_args

    else:
        # Else, assume its a relative path from <blueprint_home>/plugins
        # to a directory containing the plugin archive.
        # in this case, the archived plugin is expected to reside on the
        # manager file server as a zip file.
        blueprints_root = utils.get_manager_file_server_blueprints_root_url()
        if not blueprints_root:
            raise NonRecoverableError(
                'blueprints root "{0}" is empty'.format(blueprints_root))

        blueprint_plugins_url = '{0}/{1}/plugins'.format(
            blueprints_root, blueprint_id)

        blueprint_plugins_url_as_zip = '{0}/{1}.zip'.\
                                       format(blueprint_plugins_url, source)
        return blueprint_plugins_url_as_zip, install_args
예제 #12
0
def get_agent_resource_url(ctx, agent_config, resource):
    """returns an agent's resource url

    The resource will be looked for in the agent's properties.
    If it isn't found, it will look for it in the default location.
    """
    if agent_config.get(resource):
        origin = utils.get_manager_file_server_blueprints_root_url() + \
            '/' + ctx.blueprint.id + '/' + agent_config[resource]
    else:
        resource_path = DEFAULT_AGENT_RESOURCES.get(resource)
        if not resource_path:
            raise NonRecoverableError('no such resource: {0}'.format(resource))
        if resource == 'agent_package_path':
            origin = utils.get_manager_file_server_url() + \
                resource_path.format(agent_config['distro'],
                                     agent_config['distro_codename'])
        else:
            origin = utils.get_manager_file_server_url() + \
                resource_path.format(agent_config['distro'])

    ctx.logger.debug('resource origin: {0}'.format(origin))
    return origin
예제 #13
0
def get_agent_resource_url(ctx, agent_config, resource):
    """returns an agent's resource url

    The resource will be looked for in the agent's properties.
    If it isn't found, it will look for it in the default location.
    """
    if agent_config.get(resource):
        origin = utils.get_manager_file_server_blueprints_root_url() + \
            '/' + ctx.blueprint.id + '/' + agent_config[resource]
    else:
        resource_path = DEFAULT_AGENT_RESOURCES.get(resource)
        if not resource_path:
            raise NonRecoverableError('no such resource: {0}'.format(resource))
        if resource == 'agent_package_path':
            origin = utils.get_manager_file_server_url() + \
                resource_path.format(agent_config['distro'],
                                     agent_config['distro_codename'])
        else:
            origin = utils.get_manager_file_server_url() + \
                resource_path.format(agent_config['distro'])

    ctx.logger.debug('resource origin: {0}'.format(origin))
    return origin
예제 #14
0
def setup_environment(ctx):
    """
    Add some useful environment variables to the environment
    """

    env = os.environ.copy()
    # See in context.py
    # https://github.com/CloudifySource
    # /cosmo-celery-common/blob/develop/cloudify/context.py
    env['CLOUDIFY_NODE_ID'] = ctx.node_id.encode('utf-8')
    env['CLOUDIFY_BLUEPRINT_ID'] = ctx.blueprint_id.encode('utf-8')
    env['CLOUDIFY_DEPLOYMENT_ID'] = ctx.deployment_id.encode('utf-8')
    env['CLOUDIFY_MANAGER_IP'] = get_manager_ip().encode('utf-8')
    env['CLOUDIFY_EXECUTION_ID'] = ctx.execution_id.encode('utf-8')

    logging_script_path = os.path.join(dirname(resources.__file__),
                                       "logging.sh")

    file_server_script_path = os.path.join(dirname(resources.__file__),
                                           "file_server.sh")

    env['CLOUDIFY_LOGGING'] = logging_script_path
    env['CLOUDIFY_FILE_SERVER'] = file_server_script_path

    url = '{0}/{1}'.format(utils.get_manager_file_server_blueprints_root_url(),
                           ctx.blueprint_id)

    env['CLOUDIFY_FILE_SERVER_BLUEPRINT_ROOT'] = url.encode('utf-8')

    # assuming properties are flat.
    # inject each property as an environment variable.
    for key, value in flatten(ctx.properties).iteritems():
        env[key] = value.encode('utf-8') \
            if isinstance(value, unicode) \
            or isinstance(value, str) else repr(value)

    return env