How to use the jumbo.utils.exceptions.CreationError 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 / services.py View on Github external
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)

    missing_serv, missing_comp = check_service_req_service(service, ha)
    if missing_serv:
        raise ex.CreationError('component', name, 'services', missing_serv,
                               'ReqNotMet')
    if missing_comp:
        print_missing = []
        print_missing.append('Default:')
        for k, v in missing_comp['default'].items():
            print_missing.append(' - {} {}'.format(v, k))
        print_missing.append('or High Availability:')
        for k, v in missing_comp['ha'].items():
            print_missing.append(' - {} {}'.format(v, k))
        raise ex.CreationError('service', name, 'components', print_missing,
                               'ReqNotMet')

    if name in ss.svars['nodes'][m_index]['components']:
        raise ex.CreationError('node', node, 'component', name,
                               'Installed')
github adaltas / jumbo / jumbo / core / clusters.py View on Github external
def create_cluster(domain, template=None, *, cluster):
    """Create a new cluster and load it in the session.

    :param name: New cluster name
    :type name: str
    :param domain: New cluster domain name
    :type domain: str
    :raises ex.CreationError: If name already used
    :return: True on creation success
    """

    if checks.check_cluster(cluster):
        raise ex.CreationError('cluster', cluster, 'name', cluster, 'Exists')

    allowed_chars = string.ascii_letters + string.digits + '-'
    for l in cluster:
        if l not in allowed_chars:
            raise ex.CreationError('cluster', cluster, 'name',
                                   'Allowed characters: ' + allowed_chars,
                                   'NameNotAllowed')

    ss.clear()
    data_dir = os.path.dirname(os.path.abspath(__file__)) + '/data/'
    config_dir = os.path.dirname(os.path.abspath(__file__)) + '/config/'
    if template:
        try:
            with open(config_dir + 'templates/' + template + '.json') \
                    as template_file:
                ss.svars = json.load(template_file)
github adaltas / jumbo / jumbo / core / services.py View on Github external
if ha is None:
        ha = check_comp_number(service, name)

    missing_serv, missing_comp = check_service_req_service(service, ha)
    if missing_serv:
        raise ex.CreationError('component', name, 'services', missing_serv,
                               'ReqNotMet')
    if missing_comp:
        print_missing = []
        print_missing.append('Default:')
        for k, v in missing_comp['default'].items():
            print_missing.append(' - {} {}'.format(v, k))
        print_missing.append('or High Availability:')
        for k, v in missing_comp['ha'].items():
            print_missing.append(' - {} {}'.format(v, k))
        raise ex.CreationError('service', name, 'components', print_missing,
                               'ReqNotMet')

    if name in ss.svars['nodes'][m_index]['components']:
        raise ex.CreationError('node', node, 'component', name,
                               'Installed')

    ss.svars['nodes'][m_index]['components'].append(name)
    ss.dump_config(get_services_components_hosts())
github adaltas / jumbo / jumbo / core / services.py View on Github external
if missing_serv:
        raise ex.CreationError('component', name, 'services', missing_serv,
                               'ReqNotMet')
    if missing_comp:
        print_missing = []
        print_missing.append('Default:')
        for k, v in missing_comp['default'].items():
            print_missing.append(' - {} {}'.format(v, k))
        print_missing.append('or High Availability:')
        for k, v in missing_comp['ha'].items():
            print_missing.append(' - {} {}'.format(v, k))
        raise ex.CreationError('service', name, 'components', print_missing,
                               'ReqNotMet')

    if name in ss.svars['nodes'][m_index]['components']:
        raise ex.CreationError('node', node, 'component', name,
                               'Installed')

    ss.svars['nodes'][m_index]['components'].append(name)
    ss.dump_config(get_services_components_hosts())
github adaltas / jumbo / jumbo / core / clusters.py View on Github external
:param name: New cluster name
    :type name: str
    :param domain: New cluster domain name
    :type domain: str
    :raises ex.CreationError: If name already used
    :return: True on creation success
    """

    if checks.check_cluster(cluster):
        raise ex.CreationError('cluster', cluster, 'name', cluster, 'Exists')

    allowed_chars = string.ascii_letters + string.digits + '-'
    for l in cluster:
        if l not in allowed_chars:
            raise ex.CreationError('cluster', cluster, 'name',
                                   'Allowed characters: ' + allowed_chars,
                                   'NameNotAllowed')

    ss.clear()
    data_dir = os.path.dirname(os.path.abspath(__file__)) + '/data/'
    config_dir = os.path.dirname(os.path.abspath(__file__)) + '/config/'
    if template:
        try:
            with open(config_dir + 'templates/' + template + '.json') \
                    as template_file:
                ss.svars = json.load(template_file)
        except:
            raise ex.LoadError('template', template, 'NotExist')

    pathlib.Path(JUMBODIR + cluster).mkdir(parents=True)
github adaltas / jumbo / jumbo / core / nodes.py View on Github external
: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,
        'cpus': cpus,
        'components': [],
        'groups': []
github adaltas / jumbo / jumbo / core / services.py View on Github external
:type component: str
    :return: True if the service is in HA mode, false otherwise
    """

    ha = 'ha' if check_ha(service) else 'default'
    serv_comp_host = get_services_components_hosts()
    number_comp = 1
    if serv_comp_host[service].get(component):
        number_comp = len(serv_comp_host[service][component]) + 1
    for s in config['services']:
        if s['name'] == service:
            for c in s['components']:
                if c['name'] == component:
                    if number_comp > c['number'][ha] \
                            and c['number'][ha] != -1:
                        raise ex.CreationError('cluster',
                                               ss.svars['cluster'],
                                               'components',
                                               component,
                                               'MaxNumber')
                    elif number_comp == c['number']['ha']:
                        to_remove = {}
                        for comp in s['components']:
                            n = 0
                            max_n = comp['number']['ha']
                            if serv_comp_host[service].get(comp['name']):
                                n = len(serv_comp_host[service][comp['name']])
                            if n > max_n and max_n != -1:
                                to_remove[comp['name']] = n - max_n
                        if to_remove:
                            print_remove = []
                            for k, v in to_remove.items():
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:
                changed.append(["RAM", ss.svars['nodes'][i]['ram'], ram])
                ss.svars['nodes'][i]['ram'] = ram
            if cpus:
                changed.append(["CPUs", ss.svars['nodes'][i]['cpus'], cpus])
                ss.svars['nodes'][i]['cpus'] = cpus