Example #1
0
def cli(ctx, config_file):
    """Get nova cores quotas."""
    setattr(cli, '__doc__', DOC)

    output = {
        'measurement_name': COMMAND_NAME,
        'meta': {
            'quotas': 'cores'
        },
        'variables': {}
    }
    nova_config = utils.read_config(config_file=config_file)['nova']
    interface = nova_config.pop('interface', 'internal')
    _ost = ost.OpenStack(os_auth_args=nova_config)
    try:
        variables = output['variables']
        for project in _ost.get_projects():
            limits = _ost.get_compute_limits(project_id=project.id,
                                             interface=interface)
            variables[project.name] = int(limits['quota_set']['cores'])
    except Exception as exp:
        output['exit_code'] = 1
        output['message'] = '{} failed -- {}'.format(
            COMMAND_NAME, utils.log_exception(exp=exp))
    else:
        output['exit_code'] = 0
        output['message'] = '{} is ok'.format(COMMAND_NAME)
    finally:
        return output
Example #2
0
def cli(ctx, config_file):
    """Get nova instance quotas."""
    setattr(cli, '__doc__', DOC)

    # Lower level import because we only want to load this module
    # when this plugin is called.
    from monitorstack.utils import os_utils as ost

    output = {
        'measurement_name': COMMAND_NAME,
        'meta': {
            'quotas': 'instances'
        },
        'variables': {}
    }
    nova_config = utils.read_config(config_file=config_file)['nova']
    interface = nova_config.pop('interface', 'internal')
    _ost = ost.OpenStack(os_auth_args=nova_config)
    try:
        variables = output['variables']
        for project in _ost.get_projects():
            limits = _ost.get_compute_limits(project_id=project.id,
                                             interface=interface)
            variables[project.name] = int(limits['quota_set']['instances'])
    except Exception as exp:
        output['exit_code'] = 1
        output['message'] = '{} failed -- {}'.format(
            COMMAND_NAME, utils.log_exception(exp=exp))
    else:
        output['exit_code'] = 0
        output['message'] = '{} is ok'.format(COMMAND_NAME)
    finally:
        return output
Example #3
0
 def test_secure(self):
     """Test False insecure value."""
     with mock.patch.dict(self.config, {'insecure': 'False'}):
         self.osu = os_utils.OpenStack(
             os_auth_args=self.config
         )
         self.assertTrue(self.osu.verify)
Example #4
0
 def test_conn(self):
     """Test the OpenStack connection interface."""
     # load the base class for these tests.
     self.osu = os_utils.OpenStack(
         os_auth_args=tests.read_config()['keystone']
     )
     self.assertTrue(
         isinstance(
             self.osu.conn,
             os_utils.os_conn.Connection
         )
     )
Example #5
0
def cli(ctx, config_file):
    """Get nova cores quotas."""
    setattr(cli, '__doc__', DOC)

    # Lower level import because we only want to load this module
    # when this plugin is called.
    from monitorstack.utils import os_utils as ost

    output = {
        'measurement_name': COMMAND_NAME,
        'meta': {
            'block_pools': 'usage'
        },
        'variables': {}
    }
    config = utils.read_config(config_file=config_file)['cinder']
    interface = config.pop('interface', 'internal')
    _ost = ost.OpenStack(os_auth_args=config)
    try:
        variables = output['variables']
        for item in _ost.get_volume_pool_stats(interface=interface):
            cap = item['capabilities']
            total_capacity_gb = float(cap.get('total_capacity_gb', 0))
            free_capacity_gb = float(cap.get('free_capacity_gb', 0))
            percent_used = 100 * (free_capacity_gb / total_capacity_gb)
            pool_name = cap.get('pool_name')

            output['meta'][pool_name] = True

            free_metric = '{}_free_capacity_gb'.format(pool_name)
            variables[free_metric] = free_capacity_gb

            total_metric = '{}_total_capacity_gb'.format(pool_name)
            variables[total_metric] = total_capacity_gb

            percent_metric = '{}_percent_used'.format(pool_name)
            variables[percent_metric] = percent_used
    except Exception as exp:
        output['exit_code'] = 1
        output['message'] = '{} failed -- {}'.format(
            COMMAND_NAME, utils.log_exception(exp=exp))
    else:
        output['exit_code'] = 0
        output['message'] = '{} is ok'.format(COMMAND_NAME)
    finally:
        return output
def cli(ctx, config_file):
    """Get nova cores quotas."""
    setattr(cli, '__doc__', DOC)

    output = {
        'measurement_name': COMMAND_NAME,
        'meta': {
            'block_pools': 'totals'
        },
        'variables': {}
    }
    config = utils.read_config(config_file=config_file)['cinder']
    interface = config.pop('interface', 'internal')
    _ost = ost.OpenStack(os_auth_args=config)
    try:
        variables = output['variables']
        total_capacity_gb = 0
        free_capacity_gb = 0
        for item in _ost.get_volume_pool_stats(interface=interface):
            cap = item['capabilities']
            output['meta'][cap.get('pool_name')] = True
            free_capacity_gb += float(cap.get('free_capacity_gb', 0))
            total_capacity_gb += float(cap.get('total_capacity_gb', 0))
        else:
            used_capacity = total_capacity_gb - free_capacity_gb
            total_percent = 100 * (free_capacity_gb / total_capacity_gb)
            variables['cinder_total_percent_used'] = total_percent
            variables['cinder_total_free_capacity'] = free_capacity_gb
            variables['cinder_total_used_capacity'] = used_capacity
            variables['cinder_total_capacity'] = total_capacity_gb
    except Exception as exp:
        output['exit_code'] = 1
        output['message'] = '{} failed -- {}'.format(
            COMMAND_NAME,
            utils.log_exception(exp=exp)
        )
    else:
        output['exit_code'] = 0
        output['message'] = '{} is ok'.format(COMMAND_NAME)
    finally:
        return output
Example #7
0
def cli(ctx, config_file):
    """Get nova used ram."""
    setattr(cli, '__doc__', DOC)

    # Lower level import because we only want to load this module
    # when this plugin is called.
    from monitorstack.utils import os_utils as ost

    output = {
        'measurement_name': COMMAND_NAME,
        'meta': {
            'used': 'ram'
        },
        'variables': {}
    }

    used_collection = collections.Counter()
    nova_config = utils.read_config(config_file=config_file)['nova']
    _ost = ost.OpenStack(os_auth_args=nova_config)
    try:
        flavors = _ost.get_flavors()
        variables = output['variables']
        for used in _ost.get_consumer_usage():
            flavor = flavors[used['flavor']['id']]
            project_name = _ost.get_project_name(project_id=used['project_id'])
            used_collection[project_name] += int(flavor['ram'])
            flavor_id = used['flavor']['id']
            output['meta'][flavor_id] = True
            flavor_name = _ost.get_flavor_name(flavor_id=flavor_id)
            output['meta'][flavor_name] = True
        variables.update(used_collection)
    except Exception as exp:
        output['exit_code'] = 1
        output['message'] = '{} failed -- {}'.format(
            COMMAND_NAME, utils.log_exception(exp=exp))
    else:
        output['exit_code'] = 0
        output['message'] = '{} is ok'.format(COMMAND_NAME)
    finally:
        return output
Example #8
0
def cli(ctx, config_file):
    """Get nova used disk."""
    setattr(cli, '__doc__', DOC)

    output = {
        'measurement_name': COMMAND_NAME,
        'meta': {
            'used': 'disk'
        },
        'variables': {}
    }

    used_collection = collections.Counter()
    nova_config = utils.read_config(config_file=config_file)['nova']
    _ost = ost.OpenStack(os_auth_args=nova_config)
    try:
        flavors = _ost.get_flavors()
        variables = output['variables']
        for used in _ost.get_consumer_usage():
            flavor = flavors[used['flavor']['id']]
            project_name = _ost.get_project_name(project_id=used['project_id'])
            used_collection[project_name] += int(flavor['disk'])
            flavor_id = used['flavor']['id']
            output['meta'][flavor_id] = True
            flavor_name = _ost.get_flavor_name(flavor_id=flavor_id)
            output['meta'][flavor_name] = True
        variables.update(used_collection)
    except Exception as exp:
        output['exit_code'] = 1
        output['message'] = '{} failed -- {}'.format(
            COMMAND_NAME, utils.log_exception(exp=exp))
    else:
        output['exit_code'] = 0
        output['message'] = '{} is ok'.format(COMMAND_NAME)
    finally:
        return output
Example #9
0
 def setUp(self):
     """Setup the test."""
     # load the base class for these tests.
     self.osu = os_utils.OpenStack(
         os_auth_args=tests.unit.read_config()['keystone'])
Example #10
0
 def test_insecure(self):
     """Test True insecure value."""
     self.osu = os_utils.OpenStack(
         os_auth_args=self.config
     )
     self.assertFalse(self.osu.verify)