How to use the jumbo.utils.exceptions 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 / vault.py View on Github external
def create_keys(d, str_keys, value):
    """Create keys in the dictionnary d from dotted notation string in str_key.
    eg. str_keys = "AMBARI.pwd" creates d['AMBARI']['pwd'] = value 
    """

    keys = str_keys.split(".")
    for k in keys[:-1]:
        if not k in d:
            d[k] = {}
        d = d[k]
    if keys[-1] in d:
        raise ex.CreationError("vault entry", str_keys,
                               "key", str_keys, 'Exists')
    d[keys[-1]] = value
github adaltas / jumbo / jumbo / utils / checks.py View on Github external
def check_and_call(*args, **kwargs):
        if not kwargs['cluster']:
            raise ex.LoadError('cluster', None, 'NoContext')
        elif not check_cluster(kwargs['cluster']):
            raise ex.LoadError('cluster', kwargs['cluster'], 'NotExist')
        elif kwargs['cluster'] != ss.svars['cluster']:
            if ss.svars['cluster']:
                raise ex.LoadError('cluster', ss.svars['cluster'], 'MustExit')

        return func(*args, **kwargs)
    return check_and_call
github adaltas / jumbo / jumbo / core / vault.py View on Github external
vault = Vault(password)
    data = {}

    if os.path.isfile(vault_file):
        data = vault.load(open(vault_file).read())
    else:
        raise ex.LoadError('vault for cluster', cluster, 'NotExist')

    if vault_key == '*':
        print(yaml.dump(data, default_flow_style=False))
    else:
        try:
            print(get_key(data, vault_key))
        except KeyError:
            raise ex.LoadError('key', vault_key, 'NotExist')
github adaltas / jumbo / jumbo / utils / session.py View on Github external
def load_config(cluster):
    """Load a cluster in the session.

    :param cluster: Cluster name
    :type cluster: str
    :return: True on success
    """
    global svars

    if not checks.check_cluster(cluster):
        raise ex.LoadError('cluster', cluster, 'NotExist')

    if not clusters.check_config(cluster):
        raise ex.LoadError('cluster', cluster, 'NoConfFile')
    else:
        try:
            with open(JUMBODIR + cluster + '/jumbo_config', 'r') as jc:
                svars = json.load(jc)
        except IOError as e:
            raise ex.LoadError('cluster', cluster, e.strerror)

    vs.update_versions_file()

    return True
github adaltas / jumbo / jumbo / cli / main.py View on Github external
def create(ctx, name, domain, template):
    """Create a new cluster.

    :param name: New cluster name
    """

    click.echo('Creating "%s"...' % name)
    try:
        clusters.create_cluster(cluster=name,
                                domain=domain,
                                template=template)
    except ex.CreationError as e:
        print_with_color(e.message, 'red')
    else:
        click.echo('Cluster "{}" created (domain name = "{}").'.format(
            name,
            domain if domain else '%s.local' % name))
        set_context(ctx, name)
github adaltas / jumbo / jumbo / utils / session.py View on Github external
def generate_hivesite_ha(hive_comp):
    raise ex.CreationError('service', 'HIVE', 'mode', 'High Availability',
                           'NotSupported')
github adaltas / jumbo / jumbo / core / clusters.py View on Github external
"""Delete a cluster.

    :param name: Cluster name
    :type name: str
    :raises ex.LoadError: If the cluster doesn't exist
    :return: True if the deletion was successfull
    """
    try:
        # Vagrant destroy
        current_dir = os.getcwd()
        os.chdir(JUMBODIR + cluster + '/')
        subprocess.check_output(['vagrant', 'destroy', '-f'])
        os.chdir(current_dir)
        rmtree(JUMBODIR + cluster)
    except IOError as e:
        raise ex.LoadError('cluster', cluster, e.strerror)

    ss.clear()
    return True
github adaltas / jumbo / jumbo / core / nodes.py View on Github external
:param types: Machine's types
    :type types: list str
    :param cluster: Cluster in which to create the node
    :type cluster: str
    :param cpus: Machine's number of CPUs, defaults to 1
    :param cpus: int, optional
    :raises ex.LoadError: If the cluster doesn't exist or was not specified
    :raises ex.CreationError: If the node couldn't be created
    :return: True if the session context has changed
    :rtype: bool
    """
    if check_node(cluster=cluster, node=name):
        raise ex.CreationError('node', name, 'name', name, 'Exists')

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

    if name[0] in string.digits:
        raise ex.CreationError('node', name, 'name',
                               'A node name cannot start with a digit.',
                               'NameNotAllowed')

    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,
github adaltas / jumbo / jumbo / utils / checks.py View on Github external
def check_and_call(*args, **kwargs):
        if not kwargs['cluster']:
            raise ex.LoadError('cluster', None, 'NoContext')
        elif not check_cluster(kwargs['cluster']):
            raise ex.LoadError('cluster', kwargs['cluster'], 'NotExist')
        elif kwargs['cluster'] != ss.svars['cluster']:
            if ss.svars['cluster']:
                raise ex.LoadError('cluster', ss.svars['cluster'], 'MustExit')

        return func(*args, **kwargs)
    return check_and_call
github adaltas / jumbo / jumbo / core / services.py View on Github external
:param name: Component 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]
    """

    for i, m in enumerate(ss.svars['nodes']):
        if m['name'] == node:
            m_index = i
            break
    else:
        raise ex.LoadError('node', node, 'NotExist')

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

    if not check_service_cluster(service):
        raise ex.CreationError(
            'cluster', cluster, 'service', service, 'NotInstalled')

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

    if ha is None:
        ha = check_comp_number(service, name)