Beispiel #1
0
def jumbo(ctx, cluster):
    """
    Execute a Jumbo command.
    If no command is passed, start the Jumbo shell interactive mode.
    """

    # Create the shell
    sh = Shell(prompt=click.style('jumbo > ', fg='green') if OS != 'Windows'
               else 'jumbo > ',
               intro=printlogo.jumbo_ascii() +
               '\nJumbo Shell. Enter "help" for list of supported commands.' +
               ' Type "quit" to leave the Jumbo Shell.' +
               click.style('\nJumbo v0.4.4',
                           fg='cyan'))
    # Save the shell in the click context (to modify its prompt later on)
    ctx.meta['jumbo_shell'] = sh.shell
    # Register commands that can be used in the shell
    sh.add_command(create)
    sh.add_command(exit)
    sh.add_command(delete)
    sh.add_command(use)
    sh.add_command(addnode)
    sh.add_command(rmnode)
    sh.add_command(editnode)
    sh.add_command(listclusters)
    sh.add_command(listnodes)
    sh.add_command(repair)
    sh.add_command(addservice)
    sh.add_command(addcomponent)
    sh.add_command(listcomponents)
    sh.add_command(rmservice)
    sh.add_command(rmcomponent)
    sh.add_command(checkservice)
    sh.add_command(listservices)
    sh.add_command(start)
    sh.add_command(stop)
    sh.add_command(status)
    sh.add_command(provision)
    sh.add_command(restart)

    # If cluster exists, call manage command (saves the shell in session
    #  variable svars and adapts the shell prompt)
    if cluster:
        if not checks.check_cluster(cluster):
            click.echo('This cluster does not exist.'
                       ' Use "create NAME" to create it.', err=True)
        else:
            ctx.invoke(use, name=cluster)

    # Run the command, or the shell if no command is passed
    sh.invoke(ctx)
Beispiel #2
0
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)
        except:
            raise ex.LoadError('template', template, 'NotExist')

    pathlib.Path(JUMBODIR + cluster).mkdir(parents=True)

    dir_util.copy_tree(data_dir, JUMBODIR + cluster)
    dir_util._path_created = {}
    ss.svars['cluster'] = cluster
    ss.svars['domain'] = domain if domain else '%s.local' % cluster

    services_components_hosts = None
    if template:
        services_components_hosts = services.get_services_components_hosts()

    ss.dump_config(services_components_hosts)
    return True
Beispiel #3
0
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
Beispiel #4
0
 def test_delete_cluster(self):
     print('Test "delete_cluster"')
     clusters.delete_cluster(cluster=self.c_name)
     self.assertFalse(checks.check_cluster(self.c_name))
Beispiel #5
0
 def tearDown(self):
     if checks.check_cluster(self.c_name):
         clusters.delete_cluster(cluster=self.c_name)
         print('Cluster deleted\n')