Esempio n. 1
0
def list_policies(groupid):
    '''List out current scaling policies.'''
    resp = utils.get(endpoint % (auth_data['id'], 'groups/%s/policies' % groupid), token=auth_data['token'])
    data = []
    for i in resp.json['policies']:
        if 'changePercent' in i:
            chng = '%s%%' % i['changePercent']
        else:
            chng = '%s server(s)' % i['change']
        utils.printvtable([('ID', i['id']), ('Name', i['name']),
                ('Change', chng), ('Cooldown', i['cooldown']),
                ('Type', i['type']),
                ('Link', utils.string_a_list([l['href'] for l in i['links']]))])
Esempio n. 2
0
def get_groups():
    '''List out current scaling groups.'''
    resp = utils.get(endpoint % (auth_data['id'], 'groups'),
            auth_data['token']).json
    groups = resp['groups']
    for group in groups:
        utils.printvtable([('Group ID', group['id']),
            ('Desired Capacity', group['desiredCapacity']),
            ('Pending Capacity', group['pendingCapacity']),
            ('Active Capacity', group['activeCapacity']),
            ('Active Nodes',
            utils.string_a_list(
                                [findservers(i) for i in
                                 [i['id'] for i in group['active']]]))])
Esempio n. 3
0
def massbuild(*args, **kwargs):
    '''Provide a basename and an amount. This function will build the amount
    specified starting at 1. Default naming convention is "web1, web2, web3".
    If wait is False, returned build data is provided immediatly. It is likely
    that the network info will be unavailable until the build completes.'''
    if kwargs['disk'] is False:
        disk = 'AUTO'
    else:
        disk = 'MANUAL'
    if kwargs['password']:
        password = kwargs['password']
    if kwargs['region'] is None:
        region = kwargs['region']
    else:
        region = kwargs['region'].upper()
    cs = auth(region)
    basename = kwargs['basename']
    size = kwargs['size']
    for flvr in cs.flavors.list():
        if size == int(flvr.ram):
            flavor = flvr.id
    if kwargs['imageid'] is None:
        for image in cs.images.list():
            if 'Squeeze' in image.name:
                imageid = image.id
    else:
        imageid = kwargs['imageid']
        try:
            cs.images.get(imageid)
        except ncexc.NotFound:
            print 'Image not found. It may not be local to %s.' % cs.client.region_name
            exit(1)
    start = kwargs['start']
    amount = kwargs['amount']
    utils.printvtable([('Name: ', basename), ('Size: ', size),
            ('Amount: ', amount), ('Start at: ', start)])
    build = raw_input('Is this information correct? (y|n) ')
    if build.lower() == 'y':
        for count in range(start, start + amount):
            server = cs.servers.create(basename + str(count), imageid,
            flavor, disk_config=disk)
            if not kwargs['nowait']:
                print 'Building %s...' % server.name
                pyrax.utils.wait_until(server, 'status', ['ACTIVE', 'ERROR'],
                        callback=servercallback, attempts=0)
                if not password:
                    adminpasses[server.id] = server.adminPass
                else:
                    adminpasses[server.id] = password
            else:
                utils.printvtable([('Name', server.name),
                        ('Pass', server.adminPass), ('Status', server.status),
                        ('IP', server.networks)])
        while len(server_return) != amount:
            pyrax.utils.time.sleep(5)
        if password:
            print 'Changing passwords to %s...' % password
            for s in server_return:
                cs.servers.change_password(s[0], password)
                print 'Password changed for %s' % s[1]
        fields = ['ID', 'Name', 'Password', 'Status', 'IP']
        utils.printhtable(fields, server_return, sort=1)
    else:
        exit(0)