Пример #1
0
def do_create(args, client, sl_storage, configuration):

    if args['-v']:
        DebugLevel.set_level('verbose')
    else:
        DebugLevel.set_level('progress')

    containername = args['<clustername>']
    if args['<clustername>'] in clusters(sl_storage):
        error('cluster {} already exists'.format(args['<clustername>']))

    scoretext = open(args['<score.yaml>'], 'r').read()
    score = yaml.load(scoretext)

    score['clustername'] = args['<clustername>']
    dirname = os.path.dirname(args['<score.yaml>'])
    if dirname == "":
        dirname = "."
    score['path'] = dirname + "/"

    # setup environment for scripts in score to run properly. Change to
    #  the score directory and add . to the path
    os.chdir(score['path'])
    os.environ['PATH'] = ':'.join([os.environ['PATH'], './'])

    if 'parameters' in score:
        parmvalues = score['parameters']
    else:
        parmvalues = {}

    parameters = args['<key=value>']
    for param in parameters:
        splits = param.split('=', 1)
        if len(splits) != 2:
            raise Exception("{} is not a key=value pair".format(param))
        parmvalues[splits[0]] = splits[1]
    score['parameters'] = parmvalues
    scoretext = yaml.dump(score, indent=4)

    msg = validate_provision_parms_passed(scoretext, parmvalues)
    debug(msg)
    if msg:
        error(msg)

    state_container_create(sl_storage, containername)
    try:
        # save score for later operations
        save_state(sl_storage, containername, 'score', scoretext)
        provision(args['<clustername>'], containername, score, configuration,
                  client, sl_storage)
    except Exception, e:
        debug(traceback.format_exc())
        resources = get_resources(sl_storage, containername)
        del resources['score']
        if deletable(resources):
            state_container_clean(sl_storage, containername)
        error(e.message)
Пример #2
0
def do_create(args, client, sl_storage, configuration):

    if args['-v']:
        DebugLevel.set_level('verbose')
    else:
        DebugLevel.set_level('progress')

    containername = args['<clustername>']
    if args['<clustername>'] in clusters(sl_storage):
        error('cluster {} already exists'.format(args['<clustername>']))

    scoretext = open(args['<score.yaml>'], 'r').read()
    score = yaml.load(scoretext)

    score['clustername'] = args['<clustername>']
    dirname = os.path.dirname(args['<score.yaml>'])
    if dirname == "":
        dirname = "."
    score['path'] = dirname+"/"

    # setup environment for scripts in score to run properly. Change to
    #  the score directory and add . to the path
    os.chdir(score['path'])
    os.environ['PATH'] = ':'.join([os.environ['PATH'], './'])

    if 'parameters' in score:
        parmvalues = score['parameters']
    else:
        parmvalues = {}

    parameters = args['<key=value>']
    for param in parameters:
        splits = param.split('=', 1)
        if len(splits) != 2:
            raise Exception("{} is not a key=value pair".format(param))
        parmvalues[splits[0]] = splits[1]
    score['parameters'] = parmvalues
    scoretext = yaml.dump(score, indent=4)

    msg = validate_provision_parms_passed(scoretext, parmvalues)
    debug(msg)
    if msg:
        error(msg)

    state_container_create(sl_storage, containername)
    try:
        # save score for later operations
        save_state(sl_storage, containername, 'score', scoretext)
        provision(args['<clustername>'], containername, score,
                  configuration, client, sl_storage)
    except Exception, e:
        debug(traceback.format_exc())
        resources = get_resources(sl_storage, containername)
        del resources['score']
        if deletable(resources):
            state_container_clean(sl_storage, containername)
        error(e.message)
Пример #3
0
def do_status(args, client, sl_storage, configuration):
    containername = args['<clustername>']
    if containername in clusters(sl_storage):

        vs_manager = SoftLayer.VSManager(client)
        resources = get_resources(sl_storage, containername)
        if 'score' in resources:
            del resources['score']

        if args['<resourcename>']:
            resourcename = args['<resourcename>']
            filteredresources = {}
            status_serverinstances(resources, resourcename, filteredresources,
                                   vs_manager, client)
            resources = filteredresources
        print json.dumps(resources, indent=4, sort_keys=True)
    else:
        error('cluster does not exist')
Пример #4
0
def do_status(args, client, sl_storage, configuration):
    containername = args['<clustername>']
    if containername in clusters(sl_storage):

        vs_manager = SoftLayer.VSManager(client)
        resources = get_resources(sl_storage, containername)
        if 'score' in resources:
            del resources['score']

        if args['<resourcename>']:
            resourcename = args['<resourcename>']
            filteredresources = {}
            status_serverinstances(resources, resourcename,
                                   filteredresources, vs_manager, client)
            resources = filteredresources
        print json.dumps(resources, indent=4, sort_keys=True)
    else:
        error('cluster does not exist')
Пример #5
0
def do_delete(args, client, sl_storage, configuration):
    if args['-v']:
        DebugLevel.set_level('verbose')
    containername = args['<clustername>']
    if containername in clusters(sl_storage):
        resources = get_resources(sl_storage, containername)

        if 'serverinstances' in resources:
            vs_manager = SoftLayer.VSManager(client)

            for grpname, group in resources['serverinstances'].iteritems():
                print 'working on ' + grpname
                if 'vms' in group:
                    for hostname, vm in group['vms'].iteritems():
                        try:
                            print "deleting vm {}({}): {}".format(
                                hostname, vm['id'],
                                vs_manager.cancel_instance(vm['id']))
                        except Exception, e:
                            print "error deleting " + str(e)

                elif 'autoscale' in group:
                    try:
                        autoscalegrp = client['Scale_Group'].getObject(
                            id=group['autoscale']['id'])
                        if not autoscalegrp['suspendedFlag']:
                            client['Scale_Group'].suspend(
                                id=autoscalegrp['id'])
                        print "deleting autoscale group {}: {}".format(
                            autoscalegrp,
                            client['Scale_Group'].forceDeleteObject(
                                id=autoscalegrp['id']))
                    except Exception, e:
                        print "error deleting autoscale group "
                        print grpname
                        print str(e)
Пример #6
0
def do_delete(args, client, sl_storage, configuration):
    if args['-v']:
        DebugLevel.set_level('verbose')
    containername = args['<clustername>']
    if containername in clusters(sl_storage):
        resources = get_resources(sl_storage, containername)

        if 'serverinstances' in resources:
            vs_manager = SoftLayer.VSManager(client)

            for grpname, group in resources['serverinstances'].iteritems():
                print 'working on '+grpname
                if 'vms' in group:
                    for hostname, vm in group['vms'].iteritems():
                        try:
                            print "deleting vm {}({}): {}".format(
                                hostname, vm['id'],
                                vs_manager.cancel_instance(vm['id']))
                        except Exception, e:
                            print "error deleting "+str(e)

                elif 'autoscale' in group:
                    try:
                        autoscalegrp = client['Scale_Group'].getObject(
                                      id=group['autoscale']['id'])
                        if not autoscalegrp['suspendedFlag']:
                            client['Scale_Group'].suspend(
                                                id=autoscalegrp['id'])
                        print "deleting autoscale group {}: {}".format(
                                  autoscalegrp,
                                  client['Scale_Group'].forceDeleteObject(
                                      id=autoscalegrp['id']))
                    except Exception, e:
                        print "error deleting autoscale group "
                        print grpname
                        print str(e)