def generate_content_source(server_config, name, **kwargs):
    """Generate a content source file and returns its remote path.

    See `Defining a Content Source`_ for more information.

    .. _Defining a Content Source:
        http://docs.pulpproject.org/user-guide/content-sources.html#defining-a-content-source

    :param server_config: A :class:`pulp_smash.config.ServerConfig` object.
    :param name: file name and content source id (string inside []).
    :param kwargs: each item will be converted to content source properties
        where the key is the property name and the value its value.
    :returns: the remote path of the created content source file.
    """
    content_source = StringIO()
    content_source.write('[{}]\n'.format(name))
    path = os.path.join(
        '{}'.format(CONTENT_SOURCES_PATH), '{}.conf'.format(name))
    if 'name' not in kwargs:
        content_source.write('{}: {}\n'.format('name', name))
    for key, value in kwargs.items():
        content_source.write('{}: {}\n'.format(key, value))
    client = cli.Client(server_config)
    sudo = '' if is_root(server_config) else 'sudo '
    client.machine.session().run(
        'echo "{}" | {}tee {} > /dev/null'.format(
            content_source.getvalue(),
            sudo,
            path
        )
    )
    content_source.close()
    return path
Esempio n. 2
0
def generate_repo_file(server_config, name, **kwargs):
    """Generate a repository file and returns its remote path.

    :param server_config: A :class:`pulp_smash.config.ServerConfig` object.
    :param name: file name and repo id (string inside []).
    :param kwargs: each item will be converted to repository properties where
        the key is the property name and the value its value.
    :returns: the remote path of the created repository file.
    """
    repo = StringIO()
    repo.write('[{}]\n'.format(name))
    path = os.path.join(
        '{}'.format('/etc/yum.repos.d/'), '{}.repo'.format(name))
    if 'name' not in kwargs:
        repo.write('{}: {}\n'.format('name', name))
    for key, value in kwargs.items():
        repo.write('{}: {}\n'.format(key, value))
    client = cli.Client(server_config)
    sudo = '' if is_root(server_config) else 'sudo '
    client.machine.session().run(
        'echo "{}" | {}tee {} > /dev/null'.format(
            repo.getvalue(),
            sudo,
            path
        )
    )
    repo.close()
    return path
Esempio n. 3
0
def generate_content_source(server_config, name, **kwargs):
    """Generate a content source file and returns its remote path.

    See `Defining a Content Source`_ for more information.

    .. _Defining a Content Source:
        http://docs.pulpproject.org/user-guide/content-sources.html#defining-a-content-source

    :param server_config: A :class:`pulp_smash.config.ServerConfig` object.
    :param name: file name and content source id (string inside []).
    :param kwargs: each item will be converted to content source properties
        where the key is the property name and the value its value.
    :returns: the remote path of the created content source file.
    """
    content_source = StringIO()
    content_source.write('[{}]\n'.format(name))
    path = os.path.join('{}'.format(CONTENT_SOURCES_PATH),
                        '{}.conf'.format(name))
    if 'name' not in kwargs:
        content_source.write('{}: {}\n'.format('name', name))
    for key, value in kwargs.items():
        content_source.write('{}: {}\n'.format(key, value))
    client = cli.Client(server_config)
    sudo = '' if is_root(server_config) else 'sudo '
    client.machine.session().run('echo "{}" | {}tee {} > /dev/null'.format(
        content_source.getvalue(), sudo, path))
    content_source.close()
    return path