~virtual-maasers/modev/trunk

« back to all changes in this revision

Viewing changes to modev/commands/cmd_modev.py

  • Committer: pierre-andre.morey at canonical
  • Date: 2014-07-23 23:52:40 UTC
  • Revision ID: pierre-andre.morey@canonical.com-20140723235240-etc99a6z3ujo6ind
bug fixes, keypairs start, and node-add also. Still not functionnal.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
# import logging
10
10
 
11
11
from neutronclient.v2_0 import client as neutronc # need python-neutronclient
12
 
from novaclient.v3 import client as novac# need python-novaclient
 
12
from novaclient import client as novac# need python-novaclient
13
13
 
14
14
from modev import openstack
15
15
from modev import util
82
82
            (('--base-cidr', '-cidr',),
83
83
             {'help': 'subnet definition \
84
84
                (default {})'.format(DEFAULT_CLUSTER_SUBNET),
85
 
              'action': 'store', 'default': DEFAULT_CLUSTER_SUBNET}),
 
85
              'action': 'store'}),
86
86
 
87
87
            #            (('--cluster-controller-create'),
88
88
            #             {'help': 'create the maas cluster controller instance
156
156
 
157
157
            (('--cluster-name'),
158
158
             {'help': 'name of the cluster to attach to',
159
 
              'action': 'store', 'default': 'cluster_admin'}),
 
159
              'action': 'store',}),
160
160
 
161
161
            (('--profile'),
162
162
             {'help': 'name of the profile to use', 'action': 'store',
385
385
 
386
386
 
387
387
def print_it(data=None, name=None):
388
 
    print('\n' + str(name) + ': "{}"\n'.format(data))
 
388
    print('*********************************************************' +
 
389
          '***********************')
 
390
    print(str(name) + ': "{}"'.format(data))
 
391
    print('*********************************************************' +
 
392
          '***********************')
389
393
 
390
394
 
391
395
def which(program):
965
969
               'admin_state_up': True}
966
970
    network = neutron.create_network({'network': network})
967
971
    network_id = network[u'network'][u'id']
968
 
    region_cfg.update({'networks': [{'name': 'net-admin-id',
 
972
    region_cfg.update({'networks': [{'name': full_region + 'admin',
969
973
                                    'network-id': network_id}, ]})
970
974
 
971
975
#
995
999
            sys.exit(2)
996
1000
 
997
1001
    if cidr.version == 4:
998
 
        subnet = {'name': full_region + 'adm-snet',
 
1002
        subnet = {'name': full_region + 'admin_snet',
999
1003
                  'network_id': network_id, 'ip_version': cidr.version,
1000
1004
                  'cidr': str(cidr)}
1001
1005
        try:
1005
1009
            neutron_purge(prefix=full_region, rc=openrc_cfg)
1006
1010
            sys.exit(2)
1007
1011
        subnet_id = subnet[u'subnet'][u'id']
1008
 
        region_cfg.update({'subnets': [{'name': 'subnet-adm-id',
 
1012
        region_cfg.update({'subnets': [{'name': full_region + 'admin_snet',
1009
1013
                                        'subnet-id': subnet_id,
1010
1014
                                        'subnet-cidr': str(cidr)}, ]})
1011
1015
 
1050
1054
#   updating ports names:
1051
1055
    neutron_update_ports(name=region_name)
1052
1056
 
 
1057
#
 
1058
#                     CONFIG SERIALIZATION
 
1059
#
 
1060
 
 
1061
    region_dir = DEFAULT_CONF_DIR + '/' + region_name + '/'
 
1062
    cmd_line = 'ssh-keygen -f ' + region_dir + region_name + '-key -P ""'
 
1063
 
 
1064
    output = subprocess.check_output(cmd_line, shell=True)
 
1065
    pub_key = region_dir + region_name + '-key.pub'
 
1066
 
 
1067
    pub_key_file = open(pub_key, 'r')
 
1068
    pub_key = pub_key_file.read()
 
1069
    pub_key_file.close()
 
1070
 
 
1071
    print_it(pub_key)
 
1072
 
 
1073
    nova = nova_connect(openrc_cfg)
 
1074
    nova.keypairs.create(full_region + 'key', public_key=pub_key)
 
1075
 
1053
1076
    print('switching to region: "{}"'.format(region_name))
1054
1077
    set_modev_region(region_name)
1055
1078
 
1172
1195
 
1173
1196
#   Check if it already exists
1174
1197
    c_name = FIXED_PREFIX + region_name + '_cluster_' +\
1175
 
        cluster_name + '_snet'
 
1198
        cluster_name
1176
1199
 
1177
1200
    for cluster_net in region_cfg['config']['networks']:
1178
1201
        if cluster_net['name'] == c_name:
1279
1302
def main_node_list(args):
1280
1303
    raise NotImplementedError()
1281
1304
 
 
1305
 
1282
1306
def nova_connect(openrc_cfg=None):
1283
1307
    if openrc_cfg is None:
1284
1308
        raise NameError('neutron_connect() called with wrong parameter')
1285
1309
#client = Client(USERNAME, PASSWORD, PROJECT_ID, AUTH_URL)
1286
 
    nova = novac.Client(username=openrc_cfg['os_username'],
1287
 
                            password=openrc_cfg['os_password'],
1288
 
                            project_id='',
1289
 
                            auth_url=openrc_cfg['os_auth_url'])
 
1310
    nova = novac.Client("2",
 
1311
                        openrc_cfg['os_username'],
 
1312
                        openrc_cfg['os_password'],
 
1313
                        openrc_cfg['os_tenant_name'],
 
1314
                        openrc_cfg['os_auth_url'],
 
1315
                        region_name=openrc_cfg['os_region_name'])
 
1316
    nova.client.authenticate()
1290
1317
    nova.format = 'json'
1291
1318
    return nova
1292
1319
 
1301
1328
 
1302
1329
    return(name,nova)
1303
1330
 
 
1331
 
 
1332
def nova_get_modev_objects(nova=None,objects=None):
 
1333
    obj_list = []
 
1334
    request = 'nova.' + str(objects) + '.list()'
 
1335
    for object in eval(request):
 
1336
        if 'modev_' in str(object):
 
1337
            obj_list.append(object)
 
1338
    return(obj_list)
 
1339
 
 
1340
 
1304
1341
def main_node_add(args):
1305
1342
    name, nova = node_init_nova()
1306
1343
 
 
1344
    #Temporaire tests pour creation de serveurs:
 
1345
    servers = nova_get_modev_objects(nova,'servers')
 
1346
    flavors = nova_get_modev_objects(nova,'flavors')
 
1347
    networks = nova_get_modev_objects(nova,'networks')
 
1348
    keypairs = nova_get_modev_objects(nova,'keypairs')
 
1349
 
 
1350
    if args.cluster_name is None:
 
1351
        for net in networks:
 
1352
            if '_admin' in str(net):
 
1353
                cur_clust = net
 
1354
                break
 
1355
 
 
1356
    print_it(servers,'servers')
 
1357
    print_it(flavors,'flavors')
 
1358
    print_it(keypairs,'keypairs')
 
1359
 
1307
1360
 
1308
1361
def main_node_delete(args):
1309
1362
    name, nova = node_init_nova()