How to use the jumbo.utils.session.load_config function in jumbo

To help you get started, we’ve selected a few jumbo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github adaltas / jumbo / jumbo / core / vagrant.py View on Github external
def cmd(cmd, *, cluster):
    """Run a command in the vagrantfile folder and print output
    """

    ss.load_config(cluster)
    ss.dump_config()
    try:
        res = subprocess.Popen(cmd,
                               cwd=os.path.join(JUMBODIR, cluster),
                               stdout=subprocess.PIPE,
                               stderr=subprocess.STDOUT
                               )

        for line in res.stdout:
            print(line.decode('utf-8').rstrip())

        if cmd[1] == 'up':
            # Start services after a vagrant up
            start_services()

    except KeyboardInterrupt:
github adaltas / jumbo / jumbo / core / nodes.py View on Github external
if 'ldap' in types:
        if len(types) > 1:
            raise ex.CreationError('node', name, 'type', 'ldap',
                                   'LDAPNotCompatible')

    m = {
        'name': name,
        'ip': ip,
        'ram': ram,
        'types': types,
        'cpus': cpus,
        'components': [],
        'groups': []
    }

    ss.load_config(cluster=cluster)
    ss.add_node(m)
    ss.dump_config()
github adaltas / jumbo / jumbo / core / clusters.py View on Github external
def list_nodes(*, cluster):
    """List the nodes of a cluster.

    :param cluster: Cluster name
    :type cluster: str
    :return: The list of the cluster's nodes
    :rtype: dict
    """
    ss.load_config(cluster)
    return ss.svars['nodes']
github adaltas / jumbo / jumbo / core / nodes.py View on Github external
def edit_node(name, ip=None, ram=None, cpus=None, *, cluster):
    """Modify an existing node in a cluster.

    """
    ss.load_config(cluster=cluster)

    if not check_node(cluster=cluster, node=name):
        raise ex.LoadError('node', name, 'NotExist')

    if check_ip(ip, cluster=cluster):
        raise ex.CreationError('node', name, 'IP', ip, 'Exists')


    changed = []

    for i, m in enumerate(ss.svars['nodes']):
        if m['name'] == name:
            if ip:
                changed.append(["IP", ss.svars['nodes'][i]['ip'], ip])
                ss.svars['nodes'][i]['ip'] = ip
            if ram:
github adaltas / jumbo / jumbo / core / services.py View on Github external
def remove_component(component, *, node, cluster):
    """Remove a service of a specified node in a specified cluster.

    :param name: Service name
    :type name: str
    :param node: Machine name
    :type node: str
    :param cluster: Cluster name
    :type cluster: str
    :raises ex.LoadError: [description]
    :raises ex.CreationError: [description]
    """

    ss.load_config(cluster)

    if not nodes.check_node(cluster=cluster, node=node):
        raise ex.LoadError('node', node, 'NotExist')

    service = check_component(component)
    if not service:
        raise ex.LoadError('component', component, 'NotExist')

    for i, m in enumerate(ss.svars['nodes']):
        if m['name'] == node:
            m_index = i

    if component not in ss.svars['nodes'][m_index]['components']:
        raise ex.CreationError('node', node, 'component', component,
                               'NotInstalled')
github adaltas / jumbo / jumbo / core / services.py View on Github external
def add_service(name, ha=False, *, cluster):
    """Add a service to a specified cluster.

    :param name: Service name
    :type name: str
    :param cluster: Cluster name
    :type cluster: str
    :raises ex.LoadError: [description]
    :raises ex.CreationError: [description]
    """

    ss.load_config(cluster)

    if not check_service(name):
        raise ex.LoadError('service', name, 'NotExist')

    if name in ss.svars['services']:
        raise ex.CreationError('cluster', cluster,
                               'service', name,
                               'Installed')

    if check_service_cluster(name):
        raise ex.CreationError(
            'cluster', cluster, 'service', name, 'Installed')

    missing_serv, missing_comp = check_service_req_service(name, ha)
    if missing_serv:
        raise ex.CreationError('service', name, 'services',
github adaltas / jumbo / jumbo / cli / main.py View on Github external
def use(ctx, name):
    """Set a cluster to manage. Persist --cluster option.

    :param name: Cluster name
    """

    click.echo('Loading %s...' % name)

    try:
        ss.load_config(cluster=name)
        ss.dump_config(services.get_services_components_hosts())
    except ex.LoadError as e:
        print_with_color(e.message, 'red')
        if e.type == 'NoConfFile':
            click.echo('Use "repair" to regenerate `jumbo_config`.')
    else:
        click.echo('Cluster "%s" loaded.' % name)
        set_context(ctx, name)
github adaltas / jumbo / jumbo / core / nodes.py View on Github external
def remove_node(*, cluster, node):
    """Remove a node in a cluster.

    :param cluster: Cluster namee
    :type cluster: str
    :param name: Machine name
    :type name: str
    :raises ex.LoadError: If the node or the cluster couldn't be loaded
    :return: True if the session context has changed
    :rtype: bool
    """
    ss.load_config(cluster)

    if not check_node(cluster=cluster, node=node):
        raise ex.LoadError('node', node, 'NotExist')

    for i, m in enumerate(ss.svars['nodes']):
        if m['name'] == node:
            del(ss.svars['nodes'][i])

    ss.dump_config()
github adaltas / jumbo / jumbo / core / services.py View on Github external
def auto_assign(service, ha, *, cluster):
    """Auto-install a service and its components on the best fitting hosts.

    :param service: Service name
    :type service: str
    :param cluster: Cluster name
    :type cluster: str
    :raises ex.LoadError: If the cluster doesn't exist
    :raises ex.CreationError: If the requirements are not met to install
    """

    ss.load_config(cluster)

    scfg = check_service(service)
    if not scfg:
        raise ex.LoadError('service', service, 'NotExist')

    # dist is 'default' or 'ha'
    dist = 'ha' if ha else 'default'
    # Check loop for atomicity
    for component in scfg['components']:
        left = auto_assign_service_comp(component, dist, cluster, check=True)
        if left == -1:
            raise ex.CreationError('component', component['name'],
                                   'hosts type (need at least 1 of them)',
                                   (' - %s'
                                    % c for c in component['hosts_types']),
                                   'ReqNotMet')