Exemplo n.º 1
0
#from himlarcli.cinder import Cinder
from himlarcli.gnocchi import Gnocchi
from himlarcli.cinder import Cinder
from himlarcli.parser import Parser
from himlarcli.printer import Printer
from himlarcli import utils as himutils
from datetime import date, timedelta
from collections import OrderedDict

parser = Parser()
options = parser.parse_args()
printer = Printer(options.format)

kc= Keystone(options.config, debug=options.debug)
kc.set_domain(options.domain)
kc.set_dry_run(options.dry_run)
logger = kc.get_logger()

# Billing will always use all regions
regions = kc.find_regions()

def action_whales():
    start = himutils.get_date(options.start, date.today() - timedelta(days=1))
    stop = himutils.get_date(options.end, date.today() + timedelta(days=1))
    if start > stop:
        himutils.sys_error('start %s must be fore stop %s' % (start, stop))
    logger.debug('=> start date = %s', start)
    logger.debug('=> stop date = %s', stop)

    for region in regions:
        nc = Nova(options.config, debug=options.debug, log=logger, region=region)
Exemplo n.º 2
0
tests.is_virtual_env()

from himlarcli.keystone import Keystone
from himlarcli.nova import Nova
from himlarcli.neutron import Neutron
from himlarcli.parser import Parser
from himlarcli.printer import Printer
from himlarcli import utils as himutils
import time

parser = Parser()
options = parser.parse_args()
printer = Printer(options.format)

kc = Keystone(options.config, debug=options.debug)
kc.set_dry_run(options.dry_run)
logger = kc.get_logger()
nc = Nova(options.config, debug=options.debug, log=logger)
nc.set_dry_run(options.dry_run)

# Region
if hasattr(options, 'region'):
    regions = kc.find_regions(region_name=options.region)
else:
    regions = kc.find_regions()


def action_list():
    for region in regions:
        nc = himutils.get_client(Neutron, options, logger, region)
        networks = nc.list_networks()
Exemplo n.º 3
0
    def prettyprint_project_instances(project, options, logger, regions):
        out_str = ''
        instances_total = 0
        instances = dict()

        # Get Instances
        for region in regions:
            # Initiate Nova object
            nc = utils.get_client(Nova, options, logger, region)

            # Get a list of instances in project
            instances[region] = nc.get_project_instances(project_id=project.id)
            for instance in instances[region]:
                instances_total += 1

        # Print Instances table
        if instances_total > 0:
            kc = Keystone(options.config, debug=options.debug)
            kc.set_dry_run(options.dry_run)
            kc.set_domain(options.domain)

            table_instances = PrettyTable()
            table_instances.field_names = [
                'id', 'name', 'status', 'owner', 'IPv4', 'IPv6', 'region',
                'flavor', 'image [status]'
            ]
            table_instances.align['id'] = 'l'
            table_instances.align['name'] = 'l'
            table_instances.align['status'] = 'l'
            table_instances.align['owner'] = 'l'
            table_instances.align['IPv4'] = 'l'
            table_instances.align['IPv6'] = 'l'
            table_instances.align['region'] = 'l'
            table_instances.align['flavor'] = 'l'
            table_instances.align['image [status]'] = 'l'
            for region in regions:
                # Initiate Glance object
                gc = utils.get_client(Glance, options, logger, region)
                for instance in instances[region]:
                    if len(instance.addresses.keys()) > 0:
                        network = instance.addresses.keys()[0]
                        ipv4_list = []
                        ipv6_list = []
                        for interface in instance.addresses[network]:
                            if interface['version'] == 4:
                                ipv4_list.append(interface['addr'])
                            if interface['version'] == 6:
                                ipv6_list.append(interface['addr'])
                        ipv4_addresses = ", ".join(ipv4_list)
                        ipv6_addresses = ", ".join(ipv6_list)
                    else:
                        ipv4_addresses = 'None'
                        ipv6_addresses = 'None'
                    if 'id' not in instance.image:
                        image_name = 'UNKNOWN'
                        image_status = 'N/A'
                    else:
                        filters = {'id': instance.image['id']}
                        image = gc.find_image(filters=filters, limit=1)
                        if len(image) == 1:
                            image_name = image[0]['name']
                            image_status = image[0]['status']
                        else:
                            image_name = 'UNKNOWN'
                            image_status = 'N/A'
                    user = kc.get_by_id('user', instance.user_id)
                    owner = user.name if user else '(deleted-user)'
                    row = []
                    row.append(instance.id)
                    row.append(instance.name)
                    row.append(instance.status)
                    row.append(owner)
                    row.append(ipv4_addresses)
                    row.append(ipv6_addresses)
                    row.append(region)
                    row.append(instance.flavor["original_name"])
                    row.append("%s [%s]" % (image_name, image_status))
                    table_instances.add_row(row)
            out_str += "\n  Instances (%d): \n" % instances_total
            out_str += table_instances.get_string() + "\n"

        return out_str.encode('utf-8')
Exemplo n.º 4
0
    def prettyprint_project_metadata(project,
                                     options,
                                     logger,
                                     regions,
                                     user=None):
        out_str = ''
        kc = Keystone(options.config, debug=options.debug)
        kc.set_dry_run(options.dry_run)
        kc.set_domain(options.domain)

        project_type = project.type if hasattr(project,
                                               'type') else '(unknown)'
        project_admin = project.admin if hasattr(project,
                                                 'admin') else '(unknown)'
        project_created = project.createdate if hasattr(
            project, 'createdate') else '(unknown)'
        project_enddate = project.enddate if hasattr(project,
                                                     'enddate') else 'None'
        project_contact = project.contact if hasattr(project,
                                                     'contact') else 'None'
        project_roles = kc.list_roles(project_name=project.name)

        # Make project create date readable
        project_created = re.sub(r'T\d\d:\d\d:\d\d.\d\d\d\d\d\d', '',
                                 project_created)

        # Disabled project?
        status = "*** DISABLED *** " if not project.enabled else ''

        # Print header for project
        out_str += "%sPROJECT: %s" % (status, project.name)
        if user is not None and not options.admin:
            prole = 'admin' if user == project.admin else 'member'
            out_str += " (%s)" % prole
        out_str += "\n" + '=' * 80 + "\n"

        # Print project metadata
        table_metadata = PrettyTable()
        table_metadata._max_width = {'value': 70}
        table_metadata.border = 0
        table_metadata.header = 0
        table_metadata.field_names = ['meta', 'value']
        table_metadata.align['meta'] = 'r'
        table_metadata.align['value'] = 'l'
        table_metadata.add_row(['ID:', project.id])
        table_metadata.add_row(['Admin:', project_admin])
        table_metadata.add_row(['Contact:', project_contact])
        table_metadata.add_row(['Type:', project_type])
        table_metadata.add_row(['Created:', project_created])
        table_metadata.add_row(['Enddate:', project_enddate])
        table_metadata.add_row(['Description:', project.description])
        if len(project_roles) > 0:
            users = dict()
            users['user'] = []
            users['object'] = []
            users['superuser'] = []
            for role in project_roles:
                user = role['group'].replace('-group', '')
                users[role['role']].append(user)
            table_metadata.add_row(['Users:', "\n".join(users['user'])])
            if len(users['superuser']) > 0:
                table_metadata.add_row(
                    ['Superusers:', "\n".join(users['superuser'])])
            if len(users['object']) > 0:
                table_metadata.add_row(
                    ['Object Users:', "\n".join(users['object'])])
        if not options.detail:
            zones = Printer._count_project_zones(project, options, logger)
            volumes = Printer._count_project_volumes(project, options, logger,
                                                     regions)
            images = Printer._count_project_images(project, options, logger,
                                                   regions)
            instances = Printer._count_project_instances(
                project, options, logger, regions)
            volume_list = []
            image_list = []
            instance_list = []
            for region in regions:
                volume_list.append("%d (%s)" % (volumes[region], region))
                image_list.append("%d (%s)" % (images[region], region))
                instance_list.append("%d (%s)" % (instances[region], region))
            table_metadata.add_row(['Zones:', zones])
            table_metadata.add_row(['Volumes:', ', '.join(volume_list)])
            table_metadata.add_row(['Images:', ', '.join(image_list)])
            table_metadata.add_row(['Instances:', ', '.join(instance_list)])

        out_str += table_metadata.get_string() + "\n"
        return out_str.encode('utf-8')
Exemplo n.º 5
0
from himlarcli.keystone import Keystone
from himlarcli.nova import Nova
from himlarcli.cinder import Cinder
from himlarcli.parser import Parser
from himlarcli.printer import Printer
from himlarcli import utils as himutils

himutils.is_virtual_env()

parser = Parser()
options = parser.parse_args()
printer = Printer(options.format)

ksclient = Keystone(options.config, debug=options.debug)
ksclient.set_dry_run(options.dry_run)
logger = ksclient.get_logger()

if hasattr(options, 'region'):
    regions = ksclient.find_regions(region_name=options.region)
else:
    regions = ksclient.find_regions()

if not regions:
    himutils.sys_error('no valid regions found!')

def action_volume():
    projects = ksclient.get_projects(domain=options.domain)
    for region in regions:
        cinderclient = Cinder(options.config, debug=options.debug, log=logger, region=region)
        # Quotas
Exemplo n.º 6
0
from himlarcli.cinder import Cinder
from himlarcli.neutron import Neutron
from himlarcli.parser import Parser
from himlarcli.printer import Printer
from himlarcli import utils as himutils
from datetime import datetime

himutils.is_virtual_env()

parser = Parser()
parser.set_autocomplete(True)
options = parser.parse_args()
printer = Printer(options.format)

ksclient = Keystone(options.config, debug=options.debug)
ksclient.set_dry_run(options.dry_run)
logger = ksclient.get_logger()
#novaclient = Nova(options.config, debug=options.debug, log=logger)
if hasattr(options, 'region'):
    regions = ksclient.find_regions(region_name=options.region)
else:
    regions = ksclient.find_regions()

if not regions:
    himutils.sys_error('no regions found!')


def action_create():
    quota = himutils.load_config('config/quotas/%s.yaml' % options.quota)
    if options.quota and not quota:
        himutils.sys_error('Could not find quota in config/quotas/%s.yaml' %