Пример #1
0
def do_sample_create(cc, args={}):
    """Create a sample."""
    arg_to_field_mapping = {
        "meter_name": "counter_name",
        "meter_unit": "counter_unit",
        "meter_type": "counter_type",
        "sample_volume": "counter_volume",
    }
    fields = {}
    for var in vars(args).items():
        k, v = var[0], var[1]
        if v is not None:
            if k == "resource_metadata":
                fields[k] = json.loads(v)
            else:
                fields[arg_to_field_mapping.get(k, k)] = v
    sample = cc.samples.create(**fields)
    fields = [
        "counter_name",
        "user_id",
        "resource_id",
        "timestamp",
        "message_id",
        "source",
        "counter_unit",
        "counter_volume",
        "project_id",
        "resource_metadata",
        "counter_type",
    ]
    data = dict([(f.replace("counter_", ""), getattr(sample[0], f, "")) for f in fields])
    utils.print_dict(data, wrap=72)
Пример #2
0
    def test_prettytable(self):
        class Struct:
            def __init__(self, **entries):
                self.__dict__.update(entries)

        # test that the prettytable output is wellformatted (left-aligned)
        saved_stdout = sys.stdout
        try:
            sys.stdout = output_dict = six.StringIO()
            utils.print_dict({"K": "k", "Key": "Value"})

        finally:
            sys.stdout = saved_stdout

        self.assertEqual(
            output_dict.getvalue(),
            """\
+----------+-------+
| Property | Value |
+----------+-------+
| K        | k     |
| Key      | Value |
+----------+-------+
""",
        )
Пример #3
0
def do_alarm_state_get(cc, args={}):
    """Get the state of an alarm."""
    try:
        state = cc.alarms.get_state(args.alarm_id)
    except exc.HTTPNotFound:
        raise exc.CommandError("Alarm not found: %s" % args.alarm_id)
    utils.print_dict({"state": state}, wrap=72)
Пример #4
0
def _display_alarm(alarm):
    fields = ['name', 'description', 'counter_name', 'period',
              'evaluation_periods', 'threshold', 'comparison_operator',
              'state', 'enabled', 'alarm_id', 'user_id', 'project_id',
              'alarm_actions', 'ok_actions', 'insufficient_data_actions']
    data = dict([(f, getattr(alarm, f, '')) for f in fields])
    utils.print_dict(data, wrap=72)
Пример #5
0
def do_alarm_state_get(cc, args={}):
    '''Get the state of an alarm.'''
    try:
        state = cc.alarms.get_state(args.alarm_id)
    except exc.HTTPNotFound:
        raise exc.CommandError('Alarm not found: %s' % args.alarm_id)
    utils.print_dict({'state': state}, wrap=72)
Пример #6
0
def _display_alarm(alarm):
    fields = ['name', 'description', 'type', 'rule',
              'state', 'enabled', 'alarm_id', 'user_id', 'project_id',
              'alarm_actions', 'ok_actions', 'insufficient_data_actions',
              'repeat_actions']
    data = dict([(f, getattr(alarm, f, '')) for f in fields])
    utils.print_dict(data, wrap=72)
Пример #7
0
def _display_alarm(alarm):
    fields = ['name', 'description', 'type',
              'state', 'enabled', 'alarm_id', 'user_id', 'project_id',
              'alarm_actions', 'ok_actions', 'insufficient_data_actions',
              'repeat_actions']
    data = dict([(f, getattr(alarm, f, '')) for f in fields])
    data.update(alarm.rule)
    if alarm.type == 'threshold':
        data['query'] = alarm_query_formater(alarm)
    utils.print_dict(data, wrap=72)
Пример #8
0
def do_resource_show(cc, args={}):
    """Show the resource."""
    try:
        resource = cc.resources.get(args.resource_id)
    except exc.HTTPNotFound:
        raise exc.CommandError("Resource not found: %s" % args.resource_id)
    else:
        fields = ["resource_id", "source", "user_id", "project_id", "metadata"]
        data = dict([(f, getattr(resource, f, "")) for f in fields])
        utils.print_dict(data, wrap=72)
Пример #9
0
    def test_prettytable(self):
        class Struct(object):
            def __init__(self, **entries):
                self.__dict__.update(entries)

        # test that the prettytable output is wellformatted (left-aligned)
        with mock.patch('sys.stdout', new=six.StringIO()) as stdout:
            utils.print_dict({'K': 'k', 'Key': 'Value'})
            self.assertEqual('''\
+----------+-------+
| Property | Value |
+----------+-------+
| K        | k     |
| Key      | Value |
+----------+-------+
''', stdout.getvalue())

        with mock.patch('sys.stdout', new=six.StringIO()) as stdout:
            utils.print_dict({'alarm_id': '262567fd-d79a-4bbb-a9d0-59d879b6',
                              'name': u'\u6d4b\u8bd5',
                              'description': u'\u6d4b\u8bd5',
                              'state': 'insufficient data',
                              'repeat_actions': 'False',
                              'type': 'threshold',
                              'threshold': '1.0',
                              'statistic': 'avg',
                              'time_constraints': '[{name: c1,'
                                                  '\\n  description: test,'
                                                  '\\n  start: 0 18 * * *,'
                                                  '\\n  duration: 1,'
                                                  '\\n  timezone: US}]'},
                             wrap=72)
            expected = u'''\
+------------------+----------------------------------+
| Property         | Value                            |
+------------------+----------------------------------+
| alarm_id         | 262567fd-d79a-4bbb-a9d0-59d879b6 |
| description      | \u6d4b\u8bd5                             |
| name             | \u6d4b\u8bd5                             |
| repeat_actions   | False                            |
| state            | insufficient data                |
| statistic        | avg                              |
| threshold        | 1.0                              |
| time_constraints | [{name: c1,                      |
|                  |   description: test,             |
|                  |   start: 0 18 * * *,             |
|                  |   duration: 1,                   |
|                  |   timezone: US}]                 |
| type             | threshold                        |
+------------------+----------------------------------+
'''
            # py2 prints str type, py3 prints unicode type
            if six.PY2:
                expected = expected.encode('utf-8')
            self.assertEqual(expected, stdout.getvalue())
    def test_prettytable(self):
        class Struct(object):
            def __init__(self, **entries):
                self.__dict__.update(entries)

        # test that the prettytable output is wellformatted (left-aligned)
        with mock.patch('sys.stdout', new=six.StringIO()) as stdout:
            utils.print_dict({'K': 'k', 'Key': 'Value'})
            self.assertEqual('''\
+----------+-------+
| Property | Value |
+----------+-------+
| K        | k     |
| Key      | Value |
+----------+-------+
''', stdout.getvalue())

        with mock.patch('sys.stdout', new=six.StringIO()) as stdout:
            utils.print_dict({'alarm_id': '262567fd-d79a-4bbb-a9d0-59d879b6',
                              'name': u'\u6d4b\u8bd5',
                              'description': u'\u6d4b\u8bd5',
                              'state': 'insufficient data',
                              'repeat_actions': 'False',
                              'type': 'threshold',
                              'threshold': '1.0',
                              'statistic': 'avg',
                              'time_constraints': '[{name: c1,'
                                                  '\\n  description: test,'
                                                  '\\n  start: 0 18 * * *,'
                                                  '\\n  duration: 1,'
                                                  '\\n  timezone: US}]'},
                             wrap=72)
            expected = u'''\
+------------------+----------------------------------+
| Property         | Value                            |
+------------------+----------------------------------+
| alarm_id         | 262567fd-d79a-4bbb-a9d0-59d879b6 |
| description      | \u6d4b\u8bd5                             |
| name             | \u6d4b\u8bd5                             |
| repeat_actions   | False                            |
| state            | insufficient data                |
| statistic        | avg                              |
| threshold        | 1.0                              |
| time_constraints | [{name: c1,                      |
|                  |   description: test,             |
|                  |   start: 0 18 * * *,             |
|                  |   duration: 1,                   |
|                  |   timezone: US}]                 |
| type             | threshold                        |
+------------------+----------------------------------+
'''
            # py2 prints str type, py3 prints unicode type
            if six.PY2:
                expected = expected.encode('utf-8')
            self.assertEqual(expected, stdout.getvalue())
Пример #11
0
def _display_alarm(alarm):
    fields = [
        'name', 'description', 'type', 'state', 'enabled', 'alarm_id',
        'user_id', 'project_id', 'alarm_actions', 'ok_actions',
        'insufficient_data_actions', 'repeat_actions'
    ]
    data = dict([(f, getattr(alarm, f, '')) for f in fields])
    data.update(alarm.rule)
    if alarm.type == 'threshold':
        data['query'] = alarm_query_formater(alarm)
    utils.print_dict(data, wrap=72)
Пример #12
0
def do_resource_show(cc, args={}):
    '''Show the resource.'''
    try:
        resource = cc.resources.get(args.resource_id)
    except exc.HTTPNotFound:
        raise exc.CommandError('Resource not found: %s' % args.resource_id)
    else:
        fields = ['resource_id', 'source', 'user_id',
                  'project_id', 'metadata']
        data = dict([(f, getattr(resource, f, '')) for f in fields])
        utils.print_dict(data, wrap=72)
Пример #13
0
def do_resource_show(cc, args={}):
    '''Show the resource.'''
    try:
        resource = cc.resources.get(args.resource_id)
    except exc.HTTPNotFound:
        raise exc.CommandError('Resource not found: %s' % args.resource_id)
    else:
        fields = ['resource_id', 'source', 'user_id',
                  'project_id', 'metadata']
        data = dict([(f, getattr(resource, f, '')) for f in fields])
        utils.print_dict(data, wrap=72)
    def test_prettytable(self):
        class Struct:
            def __init__(self, **entries):
                self.__dict__.update(entries)

        # test that the prettytable output is wellformatted (left-aligned)
        with mock.patch('sys.stdout', new=six.StringIO()) as stdout:
            utils.print_dict({'K': 'k', 'Key': 'Value'})
            self.assertEqual('''\
+----------+-------+
| Property | Value |
+----------+-------+
| K        | k     |
| Key      | Value |
+----------+-------+
''', stdout.getvalue())
Пример #15
0
    def test_prettytable(self):
        class Struct:
            def __init__(self, **entries):
                self.__dict__.update(entries)

        # test that the prettytable output is wellformatted (left-aligned)
        with mock.patch('sys.stdout', new=six.StringIO()) as stdout:
            utils.print_dict({'K': 'k', 'Key': 'Value'})
            self.assertEqual(
                '''\
+----------+-------+
| Property | Value |
+----------+-------+
| K        | k     |
| Key      | Value |
+----------+-------+
''', stdout.getvalue())
Пример #16
0
def do_sample_create(cc, args={}):
    '''Create a sample.'''
    arg_to_field_mapping = {'meter_name': 'counter_name',
                            'meter_unit': 'counter_unit',
                            'meter_type': 'counter_type',
                            'sample_volume': 'counter_volume'}
    fields = {}
    for var in vars(args).items():
        k, v = var[0], var[1]
        if v is not None:
            if k == 'resource_metadata':
                fields[k] = json.loads(v)
            else:
                fields[arg_to_field_mapping.get(k, k)] = v
    sample = cc.samples.create(**fields)
    fields = ['counter_name', 'user_id', 'resource_id',
              'timestamp', 'message_id', 'source', 'counter_unit',
              'counter_volume', 'project_id', 'resource_metadata',
              'counter_type']
    data = dict([(f.replace('counter_', ''), getattr(sample[0], f, ''))
                 for f in fields])
    utils.print_dict(data, wrap=72)
Пример #17
0
def do_sample_create(cc, args={}):
    '''Create a sample.'''
    arg_to_field_mapping = {'meter_name': 'counter_name',
                            'meter_unit': 'counter_unit',
                            'meter_type': 'counter_type',
                            'sample_volume': 'counter_volume'}
    fields = {}
    for var in vars(args).items():
        k, v = var[0], var[1]
        if v is not None:
            if k == 'resource_metadata':
                fields[k] = json.loads(v)
            else:
                fields[arg_to_field_mapping.get(k, k)] = v
    sample = cc.samples.create(**fields)
    fields = ['counter_name', 'user_id', 'resource_id',
              'timestamp', 'message_id', 'source', 'counter_unit',
              'counter_volume', 'project_id', 'resource_metadata',
              'counter_type']
    data = dict([(f.replace('counter_', ''), getattr(sample[0], f, ''))
                 for f in fields])
    utils.print_dict(data, wrap=72)
Пример #18
0
    def test_prettytable(self):
        class Struct:
            def __init__(self, **entries):
                self.__dict__.update(entries)

        # test that the prettytable output is wellformatted (left-aligned)
        saved_stdout = sys.stdout
        try:
            sys.stdout = output_dict = six.StringIO()
            utils.print_dict({'K': 'k', 'Key': 'Value'})

        finally:
            sys.stdout = saved_stdout

        self.assertEqual(output_dict.getvalue(), '''\
+----------+-------+
| Property | Value |
+----------+-------+
| K        | k     |
| Key      | Value |
+----------+-------+
''')
    def test_prettytable(self):
        class Struct:
            def __init__(self, **entries):
                self.__dict__.update(entries)

        # test that the prettytable output is wellformatted (left-aligned)
        saved_stdout = sys.stdout
        try:
            sys.stdout = output_dict = cStringIO.StringIO()
            utils.print_dict({'K': 'k', 'Key': 'Value'})

        finally:
            sys.stdout = saved_stdout

        self.assertEqual(output_dict.getvalue(), '''\
+----------+-------+
| Property | Value |
+----------+-------+
| K        | k     |
| Key      | Value |
+----------+-------+
''')
Пример #20
0
def _display_alarm(alarm):
    fields = [
        "name",
        "description",
        "type",
        "state",
        "severity",
        "enabled",
        "alarm_id",
        "user_id",
        "project_id",
        "alarm_actions",
        "ok_actions",
        "insufficient_data_actions",
        "repeat_actions",
    ]
    data = dict([(f, getattr(alarm, f, "")) for f in fields])
    data.update(alarm.rule)
    if alarm.type == "threshold":
        data["query"] = alarm_query_formater(alarm)
    if alarm.time_constraints:
        data["time_constraints"] = time_constraints_formatter_full(alarm)
    utils.print_dict(data, wrap=72)
Пример #21
0
def do_sample_show(cc, args):
    """Show an sample."""
    sample = cc.new_samples.get(args.sample_id)

    if sample is None:
        raise exc.CommandError("Sample not found: %s" % args.sample_id)

    fields = [
        "id",
        "meter",
        "volume",
        "type",
        "unit",
        "source",
        "resource_id",
        "user_id",
        "project_id",
        "timestamp",
        "recorded_at",
        "metadata",
    ]
    data = dict((f, getattr(sample, f, "")) for f in fields)
    utils.print_dict(data, wrap=72)
    def test_prettytable(self):
        class Struct(object):
            def __init__(self, **entries):
                self.__dict__.update(entries)

        # test that the prettytable output is wellformatted (left-aligned)
        with mock.patch('sys.stdout', new=six.StringIO()) as stdout:
            utils.print_dict({'K': 'k', 'Key': 'Value'})
            self.assertEqual('''\
+----------+-------+
| Property | Value |
+----------+-------+
| K        | k     |
| Key      | Value |
+----------+-------+
''', stdout.getvalue())

        with mock.patch('sys.stdout', new=six.StringIO()) as stdout:
            utils.print_dict({'alarm_id': '262567fd-d79a-4bbb-a9d0-59d879b6',
                              'name': u'\u6d4b\u8bd5',
                              'description': u'\u6d4b\u8bd5',
                              'state': 'insufficient data',
                              'repeat_actions': 'False',
                              'type': 'threshold',
                              'threshold': '1.0',
                              'statistic': 'avg',
                              'alarm_actions': [u'http://something/alarm1',
                                                u'http://something/alarm2'],
                              'ok_actions': [{"get_attr1":
                                              [u"web_server_scaleup_policy1",
                                               u"alarm_url1"]},
                                             {"get_attr2":
                                              [u"web_server_scaleup_policy2",
                                               u"alarm_url2"]}],
                              'time_constraints': '[{name: c1,'
                                                  '\\n  description: test,'
                                                  '\\n  start: 0 18 * * *,'
                                                  '\\n  duration: 1,'
                                                  '\\n  timezone: US}]'},
                             wrap=72)
            expected = u'''\
+------------------+-------------------------------------------------------\
--------+
| Property         | Value                                                 \
        |
+------------------+-------------------------------------------------------\
--------+
| alarm_actions    | ["http://something/alarm1", "http://something/alarm2"]\
        |
| alarm_id         | 262567fd-d79a-4bbb-a9d0-59d879b6                      \
        |
| description      | \u6d4b\u8bd5                                          \
                |
| name             | \u6d4b\u8bd5                                          \
                |
| ok_actions       | [{"get_attr1": ["web_server_scaleup_policy1", "alarm_u\
rl1"]}, |
|                  | {"get_attr2": ["web_server_scaleup_policy2", "alarm_ur\
l2"]}]  |
| repeat_actions   | False                                                 \
        |
| state            | insufficient data                                     \
        |
| statistic        | avg                                                   \
        |
| threshold        | 1.0                                                   \
        |
| time_constraints | [{name: c1,                                           \
        |
|                  |   description: test,                                  \
        |
|                  |   start: 0 18 * * *,                                  \
        |
|                  |   duration: 1,                                        \
        |
|                  |   timezone: US}]                                      \
        |
| type             | threshold                                             \
        |
+------------------+-------------------------------------------------------\
--------+
'''
            # py2 prints str type, py3 prints unicode type
            if six.PY2:
                expected = expected.encode('utf-8')
            self.assertEqual(expected, stdout.getvalue())
Пример #23
0
def do_event_show(cc, args={}):
    """Show a particular event."""
    event = cc.events.get(args.message_id)
    fields = ["event_type", "generated", "traits"]
    data = dict([(f, getattr(event, f, "")) for f in fields])
    utils.print_dict(data, wrap=72)
Пример #24
0
def do_event_show(cc, args={}):
    '''Show a particular event.'''
    event = cc.events.get(args.message_id)
    fields = ['event_type', 'generated', 'traits']
    data = dict([(f, getattr(event, f, '')) for f in fields])
    utils.print_dict(data, wrap=72)
    def test_prettytable(self):
        class Struct(object):
            def __init__(self, **entries):
                self.__dict__.update(entries)

        # test that the prettytable output is wellformatted (left-aligned)
        with mock.patch('sys.stdout', new=six.StringIO()) as stdout:
            utils.print_dict({'K': 'k', 'Key': 'Value'})
            self.assertEqual(
                '''\
+----------+-------+
| Property | Value |
+----------+-------+
| K        | k     |
| Key      | Value |
+----------+-------+
''', stdout.getvalue())

        with mock.patch('sys.stdout', new=six.StringIO()) as stdout:
            utils.print_dict(
                {
                    'alarm_id':
                    '262567fd-d79a-4bbb-a9d0-59d879b6',
                    'name':
                    u'\u6d4b\u8bd5',
                    'description':
                    u'\u6d4b\u8bd5',
                    'state':
                    'insufficient data',
                    'repeat_actions':
                    'False',
                    'type':
                    'threshold',
                    'threshold':
                    '1.0',
                    'statistic':
                    'avg',
                    'alarm_actions':
                    [u'http://something/alarm1', u'http://something/alarm2'],
                    'ok_actions': [{
                        "get_attr1":
                        [u"web_server_scaleup_policy1", u"alarm_url1"]
                    }, {
                        "get_attr2":
                        [u"web_server_scaleup_policy2", u"alarm_url2"]
                    }],
                    'time_constraints':
                    '[{name: c1,'
                    '\\n  description: test,'
                    '\\n  start: 0 18 * * *,'
                    '\\n  duration: 1,'
                    '\\n  timezone: US}]'
                },
                wrap=72)
            expected = u'''\
+------------------+-------------------------------------------------------\
--------+
| Property         | Value                                                 \
        |
+------------------+-------------------------------------------------------\
--------+
| alarm_actions    | ["http://something/alarm1", "http://something/alarm2"]\
        |
| alarm_id         | 262567fd-d79a-4bbb-a9d0-59d879b6                      \
        |
| description      | \u6d4b\u8bd5                                          \
                |
| name             | \u6d4b\u8bd5                                          \
                |
| ok_actions       | [{"get_attr1": ["web_server_scaleup_policy1", "alarm_u\
rl1"]}, |
|                  | {"get_attr2": ["web_server_scaleup_policy2", "alarm_ur\
l2"]}]  |
| repeat_actions   | False                                                 \
        |
| state            | insufficient data                                     \
        |
| statistic        | avg                                                   \
        |
| threshold        | 1.0                                                   \
        |
| time_constraints | [{name: c1,                                           \
        |
|                  |   description: test,                                  \
        |
|                  |   start: 0 18 * * *,                                  \
        |
|                  |   duration: 1,                                        \
        |
|                  |   timezone: US}]                                      \
        |
| type             | threshold                                             \
        |
+------------------+-------------------------------------------------------\
--------+
'''
            # py2 prints str type, py3 prints unicode type
            if six.PY2:
                expected = expected.encode('utf-8')
            self.assertEqual(expected, stdout.getvalue())
Пример #26
0
def do_event_show(cc, args={}):
    '''Show a particular event.'''
    event = cc.events.get(args.message_id)
    fields = ['event_type', 'generated', 'traits']
    data = dict([(f, getattr(event, f, '')) for f in fields])
    utils.print_dict(data, wrap=72)
def _show_pipeline(pipeline):
    fields = [
        'name', 'enabled', 'location', 'max_bytes', 'backup_count', 'compress'
    ]
    data = dict([(f, getattr(pipeline, f, '')) for f in fields])
    ceilometer_utils.print_dict(data, wrap=72)