Пример #1
0
def action_list():
    for region in regions:
        nc = Nova(options.config, debug=options.debug, log=logger, region=region)
        flavors = nc.get_flavors(filters=options.flavor)
        outputs = ['name', 'vcpus', 'ram', 'disk']
        header = 'flavors in %s (%s)' % (region, ', '.join(outputs))
        printer.output_dict({'header': header})
        for flavor in flavors:
            output = OrderedDict()
            for out in outputs:
                output[out] = getattr(flavor, out)
            printer.output_dict(objects=output, one_line=True, sort=False)
Пример #2
0
def action_test():
    novaclient = Nova(options.config, debug=options.debug, log=logger, region=options.region)
    neutronclient = Neutron(options.config, debug=options.debug, log=logger, region=options.region)
    filters = {'status': 'active', 'visibility': options.visibility, 'tag': tags}
    logger.debug('=> filter: %s' % filters)
    images = glclient.get_images(filters=filters)
    flavors = novaclient.get_flavors('m1')
    networks = neutronclient.list_networks()
    secgroup_name = 'image_test-' + str(int(time.time()))
    secgroup = neutronclient.create_security_port_group(secgroup_name, 22)
    tests = dict({'passed': 0, 'failed': 0, 'dropped': 0})
    for image in images:
        if options.name and options.name not in image.tags:
            logger.debug('=> dropped: image name %s not in tags %s', options.name,
                         ', '.join(image.tags))
            continue
        for network in networks:
            if network['name'] == 'imagebuilder':
                continue
            try:
                starttime = int(time.time())
                print '* Create instance from %s with network %s' % (image.name, network['name'])
                flavor = glclient.find_optimal_flavor(image, flavors)
                if not flavor:
                    print '* Could not optimal find flavor for %s' % image.name
                    print '-------------------------------------------------------------'
                    continue
                logger.debug('=> use %s flavor' % flavor.name)
                nics = list()
                nics.append({'net-id': network['id']})
                server = novaclient.create_server(name='image_test'+ str(int(time.time())),
                                                  flavor=flavor,
                                                  image_id=image.id,
                                                  security_groups=[secgroup['id']],
                                                  nics=nics)
                timeout = 300 # 5 min timeout
                if not server:
                    print '-------------------------------------------------------------'
                    continue
                server = novaclient.get_instance(server.id)
                while timeout > 0 and server.status == 'BUILD':
                    time.sleep(2)
                    timeout -= 2
                    server = novaclient.get_instance(server.id)
                if timeout <= 0:
                    print ('* Could not start instance from image %s in %s seconds' %
                           (image.name, timeout))
                if server.status == 'ERROR':
                    print '* Instance started with error'
                    print server.fault
                else:
                    used_time = int(time.time()) - starttime
                    print '* Instance started after %s sec' % used_time
                if server.addresses:
                    for net in server.addresses[network['name']]:
                        starttime = int(time.time())
                        ip = IP(net['addr'])
                        print ('* Instance started with IPv%s %s (%s)' %
                               (net['version'], ip, ip.iptype()))
                        if ip.iptype() == 'ALLOCATED RIPE NCC':
                            print '* Drop connection check for IPv6 for now'
                            tests['dropped'] += 1
                            continue
                        elif ip.iptype() == 'PRIVATE':
                            print '* Drop connection check for rfc1918 address for now'
                            tests['dropped'] += 1
                            continue
                        timeout = 90
                        port = False
                        while timeout > 0 and not port:
                            start = int(time.time())
                            port = himutils.check_port(address=str(ip), port=22, timeout=2, log=logger)
                            time.sleep(3)
                            timeout -= (int(time.time()) - start)
                        used_time = int(time.time()) - starttime
                        if port:
                            print '* Port 22 open on %s (%s)' % (ip, ip.iptype())
                            tests['passed'] += 1
                        else:
                            print ('* Unable to reach port 22 on %s after %s sec (%s)'
                                   % (ip, used_time, ip.iptype()))
                            tests['failed'] += 1
                else:
                    print '* No IP found for instances %s' % server.name
                try:
                    server.delete()
                    time.sleep(3)
                    print '* Instance deleted'
                except:
                    himutils.sys_error('error!!!')
                print '-------------------------------------------------------------'
            except KeyboardInterrupt:
                if server:
                    server.delete()
                    time.sleep(5)
                    print '* Instance deleted'
    print '* Delete security group'
    neutronclient.delete_security_group(secgroup['id'])
    printer.output_dict({'header': 'Result'})
    printer.output_dict(tests)
Пример #3
0
def action_test():
    novaclient = Nova(options.config,
                      debug=options.debug,
                      log=logger,
                      region=options.region)
    neutronclient = Neutron(options.config,
                            debug=options.debug,
                            log=logger,
                            region=options.region)
    filters = {
        'status': 'active',
        'visibility': options.visibility,
        'tag': tags
    }
    logger.debug('=> filter: %s' % filters)
    images = glclient.get_images(filters=filters)
    flavors = novaclient.get_flavors('m1')
    networks = neutronclient.list_networks()
    secgroup_name = 'image_test-' + str(int(time.time()))
    secgroup = neutronclient.create_security_port_group(secgroup_name, 22)
    for image in images:
        if options.name and options.name not in image.tags:
            logger.debug('=> dropped: image name %s not in tags %s',
                         options.name, ', '.join(image.tags))
            continue
        for network in networks:
            if network['name'] == 'imagebuilder':
                continue
            try:
                starttime = int(time.time())
                print '* Create instance from %s with network %s' % (
                    image.name, network['name'])
                flavor = glclient.find_optimal_flavor(image, flavors)
                if not flavor:
                    print '* Could not optimal find flavor for %s' % image.name
                    print '-------------------------------------------------------------'
                    continue
                logger.debug('=> use %s flavor' % flavor.name)
                nics = list()
                nics.append({'net-id': network['id']})
                server = novaclient.create_server(
                    name='image_test' + str(int(time.time())),
                    flavor=flavor,
                    image_id=image.id,
                    security_groups=[secgroup['id']],
                    nics=nics)
                timeout = 300  # 5 min timeout
                if not server:
                    print '-------------------------------------------------------------'
                    continue
                server = novaclient.get_instance(server.id)
                while timeout > 0 and server.status == 'BUILD':
                    time.sleep(2)
                    timeout -= 2
                    server = novaclient.get_instance(server.id)
                if timeout <= 0:
                    print(
                        '* Could not start instance from image %s in %s seconds'
                        % (image.name, timeout))
                if server.status == 'ERROR':
                    print '* Instance started with error'
                    print server.fault
                else:
                    used_time = int(time.time()) - starttime
                    print '* Instance started after %s sec' % used_time
                if server.addresses:
                    for net in server.addresses[network['name']]:
                        starttime = int(time.time())
                        ip = IP(net['addr'])
                        print('* Instance started with IPv%s %s (%s)' %
                              (net['version'], ip, ip.iptype()))
                        if ip.iptype() == 'ALLOCATED RIPE NCC':
                            print '* Drop connection check for IPv6 for now'
                            continue
                        elif ip.iptype() == 'PRIVATE':
                            print '* Drop connection check for rfc1918 address for now'
                            continue
                        timeout = 90
                        port = False
                        while timeout > 0 and not port:
                            start = int(time.time())
                            port = himutils.check_port(address=str(ip),
                                                       port=22,
                                                       timeout=2,
                                                       log=logger)
                            time.sleep(3)
                            timeout -= (int(time.time()) - start)
                        used_time = int(time.time()) - starttime
                        if port:
                            print '* Port 22 open on %s (%s)' % (ip,
                                                                 ip.iptype())
                        else:
                            print(
                                '* Unable to reach port 22 on %s after %s sec (%s)'
                                % (ip, used_time, ip.iptype()))
                else:
                    print '* No IP found for instances %s' % server.name
                try:
                    server.delete()
                    time.sleep(3)
                    print '* Instance deleted'
                except:
                    himutils.sys_error('error!!!')
                print '-------------------------------------------------------------'
            except KeyboardInterrupt:
                if server:
                    server.delete()
                    time.sleep(5)
                    print '* Instance deleted'
    print '* Delete security group'
    neutronclient.delete_security_group(secgroup['id'])
Пример #4
0
        'help': 'project to grant or revoke access'
    }
}

options = utils.get_action_options(desc,
                                   actions,
                                   dry_run=True,
                                   opt_args=opt_args)
ksclient = Keystone(options.config, debug=options.debug)
logger = ksclient.get_logger()
novaclient = Nova(options.config, debug=options.debug, log=logger)
domain = 'Dataporten'

if options.action[0] == 'list':
    pp = pprint.PrettyPrinter(indent=1)
    flavors = novaclient.get_flavors(filters=options.name)
    for flavor in flavors:
        #print flavor.__dict__.keys()
        if not getattr(flavor, 'OS-FLV-DISABLED:disabled'):
            public = 'public' if getattr(
                flavor, 'os-flavor-access:is_public') else 'not public'
            print '------------------------'
            print '%s (%s):' % (flavor.name, public)
            print 'ram:   %s' % flavor.ram
            print 'vcpus: %s' % flavor.vcpus
            print 'disk:  %s' % flavor.disk
        else:
            print '------------------------'
            print '%s is disabled!' % flavor.name
        #pp.pprint(flavor.to_dict())
elif options.action[0] == 'update':