class Capability(resource.Resource): """.. caution:: This API is a work in progress and is subject to change.""" resource_key = 'capability' resources_key = 'capabilities' base_path = '/capabilities' service = telemetry_service.TelemetryService() # Supported Operations allow_list = True # Properties enabled = resource.prop('enabled') @classmethod def list(cls, session, limit=None, marker=None, path_args=None, paginated=False, **params): resp = session.get(cls.base_path, endpoint_filter=cls.service, params=params) resp = resp.json() for key, value in six.iteritems(resp['api']): yield cls.existing(id=key, enabled=value)
class Meter(resource.Resource): """.. caution:: This API is a work in progress and is subject to change.""" id_attribute = 'meter_id' resource_key = 'meter' base_path = '/meters' service = telemetry_service.TelemetryService() # Supported Operations allow_list = True # Properties #: The unique identifier for the meter meter_id = resource.prop('meter_id') #: The unique name for the meter name = resource.prop('name') #: The ID of the project or tenant that owns the resource project_id = resource.prop('project_id') #: The ID of the resource for which the measurements are taken resource_id = resource.prop('resource_id') #: The ID of the source that identifies where the meter comes from source = resource.prop('source') #: The meter type type = resource.prop('type') #: The unit of measure unit = resource.prop('unit') #: The ID of the user who last triggered an update to the resource user_id = resource.prop('user_id')
class Meter(resource.Resource): resource_key = 'meter' base_path = '/v2/meters' service = telemetry_service.TelemetryService() # Supported Operations allow_list = True # Properties meter_id = resource.prop('meter_id') name = resource.prop('name') project_id = resource.prop('project_id') resource_id = resource.prop('resource_id') source = resource.prop('source') type = resource.prop('type') unit = resource.prop('unit') user_id = resource.prop('user_id') @property def id(self): try: val = self.meter_id except AttributeError: val = None return val
class AlarmChange(resource.Resource): id_attribute = 'event_id' resource_key = 'alarm_change' base_path = '/v2/alarms/%(alarm_id)s/history' service = telemetry_service.TelemetryService() # Supported Operations allow_list = True # Properties alarm_id = resource.prop('alarm_id') detail = resource.prop('detail') event_id = resource.prop('event_id') on_behalf_of = resource.prop('on_behalf_of') project_id = resource.prop('project_id') triggered_at = resource.prop('timestamp') type = resource.prop('type') user_id = resource.prop('user_id') @classmethod def list(cls, session, path_args=None, **params): url = cls.base_path % path_args resp = session.get(url, service=cls.service, params=params) changes = [] for item in resp.body: changes.append(cls.existing(**item)) return changes
class Resource(resource.Resource): """.. caution:: This API is a work in progress and is subject to change.""" id_attribute = 'resource_id' base_path = '/resources' service = telemetry_service.TelemetryService() # Supported Operations allow_retrieve = True allow_list = True # Properties #: UTC date & time not later than the first sample known for this resource first_sample_at = resource.prop('first_sample_timestamp') #: UTC date & time not earlier than the last sample known for this resource last_sample_at = resource.prop('last_sample_timestamp') #: A list containing a self link and associated meter links links = resource.prop('links') #: Arbitrary metadata associated with the resource metadata = resource.prop('metadata') #: The ID of the owning project or tenant project_id = resource.prop('project_id') #: The unique identifier for the resource resource_id = resource.prop('resource_id') #: The source where the resource comes from source = resource.prop('source') #: The ID of the user who created the resource or updated it last user_id = resource.prop('user_id')
def __init__(self, plugins=None): """User preference for each service. :param list plugins: List of entry point namespaces to load. Create a new :class:`~openstack.profile.Profile` object with no preferences defined, but knowledge of the services. Services are identified by their service type, e.g.: 'identity', 'compute', etc. """ self._preferences = {} self._services = {} self._add_service(cluster_service.ClusterService()) self._add_service(compute_service.ComputeService()) self._add_service(database_service.DatabaseService()) self._add_service(identity_service.IdentityService()) self._add_service(image_service.ImageService()) self._add_service(metric_service.MetricService()) self._add_service(network_service.NetworkService()) self._add_service(object_store_service.ObjectStoreService()) self._add_service(orchestration_service.OrchestrationService()) self._add_service(key_management_service.KeyManagementService()) self._add_service(telemetry_service.TelemetryService()) self._add_service(block_store_service.BlockStoreService()) self._add_service(message_service.MessageService()) if plugins: for plugin in plugins: self._load_plugin(plugin) self.service_names = sorted(self._services.keys())
class Sample(resource.Resource): """.. caution:: This API is a work in progress and is subject to change.""" id_attribute = 'sample_id' base_path = '/meters/%(counter_name)s' service = telemetry_service.TelemetryService() # Supported Operations allow_create = True allow_list = True # Properties #: Arbitrary metadata associated with the sample metadata = resource.prop('metadata', alias='resource_metadata') #: The meter name this sample is for counter_name = resource.prop('meter', alias='counter_name') #: The project this sample was taken for project_id = resource.prop('project_id') #: When the sample has been recorded recorded_at = resource.prop('recorded_at') #: The Resource this sample was taken for resource_id = resource.prop('resource_id') #: The unique identifier for the sample sample_id = resource.prop('id', alias='message_id') #: The source that identifies where the sample comes from source = resource.prop('source') #: When the sample has been generated generated_at = resource.prop('timestamp') #: The meter type type = resource.prop('type', alias='counter_type') #: The unit of measure unit = resource.prop('unit', alias='counter_unit') #: The user this sample was taken for user_id = resource.prop('user_id') #: The metered value volume = resource.prop('volume', alias='counter_volume') @classmethod def list(cls, session, limit=None, marker=None, path_args=None, paginated=False, **params): url = cls._get_url(path_args) resp = session.get(url, endpoint_filter=cls.service, params=params) for item in resp.json(): yield cls.existing(**item) def create(self, session): url = self._get_url(self) # telemetry expects a list of samples attrs = self._attrs.copy() attrs.pop('meter', None) resp = session.post(url, endpoint_filter=self.service, json=[attrs]) resp = resp.json() self.update_attrs(**resp.pop()) self._reset_dirty() return self
class Statistics(resource.Resource): """.. caution:: This API is a work in progress and is subject to change.""" id_attribute = 'meter_name' resource_key = 'statistics' base_path = '/meters/%(meter_name)s/statistics' service = telemetry_service.TelemetryService() # Supported Operations allow_list = True # Path Parameter meter_name = resource.prop('meter_name') # Properties #: The selectable aggregate value(s) aggregate = resource.prop('aggregate') #: The average of all of the volume values seen in the data avg = resource.prop('avg') #: The number of samples seen count = resource.prop('count') #: The difference, in seconds, between the oldest and newest timestamp duration = resource.prop('duration') #: UTC date and time of the oldest timestamp, or the query end time. #: *Type: datetime object parsed from ISO 8601 formatted string* duration_end_at = resource.prop('duration_end', type=format.ISO8601) #: UTC date and time of the earliest timestamp, or the query start time. #: *Type: datetime object parsed from ISO 8601 formatted string* duration_start_at = resource.prop('duration_start', type=format.ISO8601) #: Dictionary of field names for group, if groupby statistics are requested group_by = resource.prop('groupby') #: The maximum volume seen in the data max = resource.prop('max') #: The minimum volume seen in the data min = resource.prop('min') #: The difference, in seconds, between the period start and end period = resource.prop('period') #: UTC date and time of the period end. #: *Type: datetime object parsed from ISO 8601 formatted string* period_end_at = resource.prop('period_end', type=format.ISO8601) #: UTC date and time of the period start. #: *Type: datetime object parsed from ISO 8601 formatted string* period_start_at = resource.prop('period_start', type=format.ISO8601) #: The total of all of the volume values seen in the data sum = resource.prop('sum') #: The unit type of the data set unit = resource.prop('unit') @classmethod def list(cls, session, limit=None, marker=None, path_args=None, paginated=False, **params): url = cls._get_url(path_args) resp = session.get(url, endpoint_filter=cls.service, params=params) for stat in resp.json(): yield cls.existing(**stat)
def test_service(self): sot = telemetry_service.TelemetryService() self.assertEqual('metering', sot.service_type) self.assertEqual('public', sot.visibility) self.assertIsNone(sot.region) self.assertIsNone(sot.service_name) self.assertEqual(1, len(sot.valid_versions)) self.assertEqual('v2', sot.valid_versions[0].module) self.assertEqual('v2', sot.valid_versions[0].path)
def __init__(self): """Preferences for each service. Create a new :class:`~openstack.profile.Profile` object with no preferences defined, but knowledge of the services. Services are identified by their service type, e.g.: 'identity', 'compute', etc. """ self._preferences = {} self._services = {} """ NOTE(thowe): We should probably do something more clever here rather than brute force create all the services. Maybe use entry points or something, but I'd like to leave that work for another commit. """ serv = cluster_service.ClusterService() serv.set_visibility(None) self._services[serv.service_type] = serv serv = compute_service.ComputeService() serv.set_visibility(None) self._services[serv.service_type] = serv serv = database_service.DatabaseService() serv.set_visibility(None) self._services[serv.service_type] = serv serv = identity_service.IdentityService() serv.set_visibility(None) self._services[serv.service_type] = serv serv = image_service.ImageService() serv.set_visibility(None) self._services[serv.service_type] = serv serv = metric_service.MetricService() serv.set_visibility(None) self._services[serv.service_type] = serv serv = network_service.NetworkService() serv.set_visibility(None) self._services[serv.service_type] = serv serv = object_store_service.ObjectStoreService() serv.set_visibility(None) self._services[serv.service_type] = serv serv = orchestration_service.OrchestrationService() serv.set_visibility(None) self._services[serv.service_type] = serv serv = keystore_service.KeystoreService() serv.set_visibility(None) self._services[serv.service_type] = serv serv = telemetry_service.TelemetryService() serv.set_visibility(None) self._services[serv.service_type] = serv serv = block_store_service.BlockStoreService() serv.set_visibility(None) self._services[serv.service_type] = serv serv = message_service.MessageService() serv.set_visibility(None) self._services[serv.service_type] = serv self.service_names = sorted(self._services.keys())
class Sample(resource.Resource): id_attribute = 'sample_id' base_path = '/meters/%(meter)s' service = telemetry_service.TelemetryService() # Supported Operations allow_create = True allow_list = True # Properties #: Arbitrary metadata associated with the sample metadata = resource.prop('metadata', alias='resource_metadata') #: The meter name this sample is for meter = resource.prop('meter', alias='counter_name') #: The project this sample was taken for project_id = resource.prop('project_id') #: When the sample has been recorded recorded_at = resource.prop('recorded_at') #: The Resource this sample was taken for resource_id = resource.prop('resource_id') #: The unique identifier for the sample sample_id = resource.prop('id', alias='message_id') #: The source that identifies where the sample comes from source = resource.prop('source') #: When the sample has been generated generated_at = resource.prop('timestamp') #: The meter type type = resource.prop('type', alias='counter_type') #: The unit of measure unit = resource.prop('unit', alias='counter_unit') #: The user this sample was taken for user_id = resource.prop('user_id') #: The metered value volume = resource.prop('volume', alias='counter_volume') @classmethod def list(cls, session, path_args=None, **params): url = cls._get_url(path_args) resp = session.get(url, service=cls.service, params=params) changes = [] for item in resp.body: changes.append(cls.existing(**item)) return changes def create(self, session): url = self._get_url(self) # telemetry expects a list of samples resp = session.post(url, service=self.service, json=[self._attrs]) sample = self.existing(**resp.body.pop()) self._attrs['id'] = sample.id self._reset_dirty()
class Statistics(resource.Resource): id_attribute = 'meter_name' resource_key = 'statistics' base_path = '/meters/%(meter_name)s/statistics' service = telemetry_service.TelemetryService() # Supported Operations allow_list = True # Path Parameter meter_name = resource.prop('meter_name') # Properties #: The selectable aggregate value(s) aggregate = resource.prop('aggregate') #: The average of all of the volume values seen in the data avg = resource.prop('avg') #: The number of samples seen count = resource.prop('count') #: The difference, in seconds, between the oldest and newest timestamp duration = resource.prop('duration') #: UTC date and time of the oldest timestamp, or the query end time duration_end = resource.prop('duration_end') #: UTC date and time of the earliest timestamp, or the query start time duration_start = resource.prop('duration_start') #: Dictionary of field names for group, if groupby statistics are requested group_by = resource.prop('groupby') #: The maximum volume seen in the data max = resource.prop('max') #: The minimum volume seen in the data min = resource.prop('min') #: The difference, in seconds, between the period start and end period = resource.prop('period') #: UTC date and time of the period end period_end = resource.prop('period_end') #: UTC date and time of the period start period_start = resource.prop('period_start') #: The total of all of the volume values seen in the data sum = resource.prop('sum') #: The unit type of the data set unit = resource.prop('unit') @classmethod def list(cls, session, limit=None, marker=None, path_args=None, paginated=False, **params): url = cls._get_url(path_args) for stat in session.get(url, service=cls.service, params=params).body: yield cls.existing(**stat)
class Alarm(resource.Resource): id_attribute = 'alarm_id' base_path = '/v2/alarms' service = telemetry_service.TelemetryService() # Supported Operations allow_create = True allow_retrieve = True allow_update = True allow_delete = True allow_list = True # Properties alarm_actions = resource.prop('alarm_actions') alarm_id = resource.prop('alarm_id') combination_rule = resource.prop('combination_rule') description = resource.prop('description') enabled = resource.prop('enabled', type=bool) insufficient_data_actions = resource.prop('insufficient_data_actions') name = resource.prop('name') ok_actions = resource.prop('ok_actions') project_id = resource.prop('project_id') repeat_actions = resource.prop('repeat_actions', type=bool) state = resource.prop('state') state_changed_at = resource.prop('state_timestamp') threshold_rule = resource.prop('threshold_rule') time_constraints = resource.prop('time_constraints') type = resource.prop('type') updated_at = resource.prop('timestamp') user_id = resource.prop('user_id') def __repr__(self): return "alarm: %s" % self._attrs def change_state(self, session, next_state): """Set the state of an alarm. The next_state may be one of: 'ok' 'insufficient data' 'alarm' """ url = utils.urljoin(self.base_path, self.id, 'state') resp = session.put(url, service=self.service, json=next_state).body return resp def check_state(self, session): """Retrieve the current state of an alarm from the service. The properties of the alarm are not modified. """ url = utils.urljoin(self.base_path, self.id, 'state') resp = session.get(url, service=self.service).body current_state = resp.replace('\"', '') return current_state
def __init__(self, plugins=None): """User preference for each service. :param plugins: List of entry point namespaces to load. Create a new :class:`~openstack.profile.Profile` object with no preferences defined, but knowledge of the services. Services are identified by their service type, e.g.: 'identity', 'compute', etc. """ self._services = {} self._add_service(anti_ddos_service.AntiDDosService(version="v1")) self._add_service(alarm_service.AlarmService(version="v2")) self._add_service(bare_metal_service.BareMetalService(version="v1")) self._add_service(block_store_service.BlockStoreService(version="v2")) self._add_service(cluster_service.ClusterService(version="v1")) self._add_service(compute_service.ComputeService(version="v2")) self._add_service(cts_service.CTSService(version="v1")) self._add_service(database_service.DatabaseService(version="v1")) self._add_service(dms_service.DMSService(version="v1")) self._add_service(identity_service.IdentityService(version="v3")) self._add_service(image_service.ImageService(version="v2")) self._add_service(key_manager_service.KeyManagerService(version="v1")) self._add_service(kms_service.KMSService(version="v1")) self._add_service(lb_service.LoadBalancerService(version="v1")) self._add_service(maas_service.MaaSService(version="v1")) self._add_service(message_service.MessageService(version="v1")) self._add_service(network_service.NetworkService(version="v2")) self._add_service( object_store_service.ObjectStoreService(version="v1")) self._add_service( orchestration_service.OrchestrationService(version="v1")) self._add_service(rds_service.RDSService(version="v1")) self._add_service(rds_os_service.RDSService(version="v1")) self._add_service(smn_service.SMNService(version="v2")) self._add_service(telemetry_service.TelemetryService(version="v2")) self._add_service(workflow_service.WorkflowService(version="v2")) # QianBiao.NG HuaWei Services self._add_service(dns_service.DNSService(version="v2")) self._add_service(cloud_eye_service.CloudEyeService(version="v1")) ass = auto_scaling_service.AutoScalingService(version="v1") self._add_service(ass) vbs_v2 = volume_backup_service.VolumeBackupService(version="v2") self._add_service(vbs_v2) self._add_service(map_reduce_service.MapReduceService(version="v1")) if plugins: for plugin in plugins: self._load_plugin(plugin) self.service_keys = sorted(self._services.keys())
class Statistics(resource.Resource): """.. caution:: This API is a work in progress and is subject to change.""" resource_key = 'statistics' base_path = '/meters/%(meter_name)s/statistics' service = telemetry_service.TelemetryService() # Supported Operations allow_list = True # Properties #: The selectable aggregate value(s) aggregate = resource.Body('aggregate') #: The average of all of the volume values seen in the data avg = resource.Body('avg') #: The number of samples seen count = resource.Body('count') #: The difference, in seconds, between the oldest and newest timestamp duration = resource.Body('duration') #: UTC date and time of the oldest timestamp, or the query end time. duration_end_at = resource.Body('duration_end') #: UTC date and time of the earliest timestamp, or the query start time. duration_start_at = resource.Body('duration_start') #: Dictionary of field names for group, if groupby statistics are requested group_by = resource.Body('groupby') #: The maximum volume seen in the data max = resource.Body('max') #: The minimum volume seen in the data min = resource.Body('min') #: The difference, in seconds, between the period start and end period = resource.Body('period') #: UTC date and time of the period end. period_end_at = resource.Body('period_end') #: UTC date and time of the period start. period_start_at = resource.Body('period_start') #: The total of all of the volume values seen in the data sum = resource.Body('sum') #: The unit type of the data set #: TODO(Qiming): This is still incorrect unit = resource.Body('unit', alternate_id=True) @classmethod def list(cls, session, paginated=False, **params): url = cls.base_path % {'meter_name': params.pop('meter_name')} resp = session.get(url, endpoint_filter=cls.service, params=params) for stat in resp.json(): yield cls.existing(**stat)
class Resource(resource.Resource): id_attribute = 'resource_id' base_path = '/resources' service = telemetry_service.TelemetryService() # Supported Operations allow_retrieve = True allow_list = True # Properties first_sample_at = resource.prop('first_sample_timestamp') last_sample_at = resource.prop('last_sample_timestamp') links = resource.prop('links') metadata = resource.prop('metadata') project_id = resource.prop('project_id') resource_id = resource.prop('resource_id') source = resource.prop('source') user_id = resource.prop('user_id')
class Meter(resource.Resource): id_attribute = 'meter_id' resource_key = 'meter' base_path = '/meters' service = telemetry_service.TelemetryService() # Supported Operations allow_list = True # Properties meter_id = resource.prop('meter_id') name = resource.prop('name') project_id = resource.prop('project_id') resource_id = resource.prop('resource_id') source = resource.prop('source') type = resource.prop('type') unit = resource.prop('unit') user_id = resource.prop('user_id')
class Capability(resource.Resource): resource_key = 'capability' resources_key = 'capabilities' base_path = '/v2/capabilities' service = telemetry_service.TelemetryService() # Supported Operations allow_list = True # Properties enabled = resource.prop('enabled') @classmethod def list(cls, session, limit=None, marker=None, **params): resp = session.get(cls.base_path, service=cls.service, params=params) ray = [] for key, value in six.iteritems(resp.body['api']): ray.append(cls.existing(id=key, enabled=value)) return ray
class Sample(resource.Resource): id_attribute = 'sample_id' base_path = '/meters/%(meter)s' service = telemetry_service.TelemetryService() # Supported Operations allow_create = True allow_list = True # Properties metadata = resource.prop('metadata', alias='resource_metadata') meter = resource.prop('meter', alias='counter_name') project_id = resource.prop('project_id') recorded_at = resource.prop('recorded_at') resource_id = resource.prop('resource_id') sample_id = resource.prop('id', alias='message_id') source = resource.prop('source') generated_at = resource.prop('timestamp') type = resource.prop('type', alias='counter_type') unit = resource.prop('unit', alias='counter_unit') user_id = resource.prop('user_id') volume = resource.prop('volume', alias='counter_volume') @classmethod def list(cls, session, path_args=None, **params): url = cls.base_path % path_args resp = session.get(url, service=cls.service, params=params) changes = [] for item in resp.body: changes.append(cls.existing(**item)) return changes def create(self, session): url = self.base_path % {'meter': self.meter} # telemetry expects a list of samples resp = session.post(url, service=self.service, json=[self._attrs]) sample = self.existing(**resp.body.pop()) self._attrs['id'] = sample.id self._reset_dirty()
class AlarmChange(resource.Resource): """.. caution:: This API is a work in progress and is subject to change.""" id_attribute = 'event_id' resource_key = 'alarm_change' base_path = '/alarms/%(alarm_id)s/history' service = telemetry_service.TelemetryService() # Supported Operations allow_list = True # Properties #: The ID of the alarm alarm_id = resource.prop('alarm_id') #: Data describing the change detail = resource.prop('detail') #: The ID of the change event event_id = resource.prop('event_id') #: The project ID on behalf of which the change is being made on_behalf_of_id = resource.prop('on_behalf_of') #: The project ID of the initiating identity project_id = resource.prop('project_id') #: The time/date of the alarm change. #: *Type: datetime object parsed from ISO 8601 formatted string* triggered_at = resource.prop('timestamp', type=format.ISO8601) #: The type of change type = resource.prop('type') #: The user ID of the initiating identity user_id = resource.prop('user_id') @classmethod def list(cls, session, limit=None, marker=None, path_args=None, paginated=False, **params): url = cls._get_url(path_args) resp = session.get(url, endpoint_filter=cls.service, params=params) for item in resp.json(): yield cls.existing(**item)
class AlarmChange(resource.Resource): id_attribute = 'event_id' resource_key = 'alarm_change' base_path = '/alarms/%(alarm_id)s/history' service = telemetry_service.TelemetryService() # Supported Operations allow_list = True # Properties #: The UUID of the alarm alarm_id = resource.prop('alarm_id') #: Data describing the change detail = resource.prop('detail') #: The UUID of the change event event_id = resource.prop('event_id') #: The tenant on behalf of which the change is being made on_behalf_of = resource.prop('on_behalf_of') #: The project ID of the initiating identity project_id = resource.prop('project_id') #: The time/date of the alarm change triggered_at = resource.prop('timestamp') #: The type of change type = resource.prop('type') #: The user ID of the initiating identity user_id = resource.prop('user_id') @classmethod def list(cls, session, limit=None, marker=None, path_args=None, paginated=False, **params): url = cls._get_url(path_args) for item in session.get(url, service=cls.service, params=params).body: yield cls.existing(**item)
class Sample(resource.Resource): """.. caution:: This API is a work in progress and is subject to change.""" base_path = '/meters/%(counter_name)s' service = telemetry_service.TelemetryService() # Supported Operations allow_get = True allow_list = True # Properties #: When the sample has been generated. generated_at = resource.Body('timestamp') #: The message ID message_id = resource.Body('message_id', alternate_id=True) #: Arbitrary metadata associated with the sample metadata = resource.Body('metadata') #: The meter name this sample is for counter_name = resource.Body('counter_name') #: The meter name this sample is for counter_type = resource.Body('counter_type') #: The ID of the project this sample was taken for project_id = resource.Body('project_id') #: When the sample has been recorded. recorded_at = resource.Body('recorded_at') #: The ID of the resource this sample was taken for resource_id = resource.Body('resource_id') #: The name of the source that identifies where the sample comes from source = resource.Body('source') #: The meter type type = resource.Body('type') #: The unit of measure unit = resource.Body('unit') #: The ID of the user this sample was taken for user_id = resource.Body('user_id') #: The metered value volume = resource.Body('volume')
class Statistics(resource.Resource): id_attribute = 'meter_name' resource_key = 'statistics' base_path = '/meters/%(meter_name)s/statistics' service = telemetry_service.TelemetryService() # Supported Operations allow_list = True # Path Parameter meter_name = resource.prop('meter_name') # Properties aggregate = resource.prop('aggregate') avg = resource.prop('avg') count = resource.prop('count') duration = resource.prop('duration') duration_end = resource.prop('duration_end') duration_start = resource.prop('duration_start') group_by = resource.prop('groupby') max = resource.prop('max') min = resource.prop('min') period = resource.prop('period') period_end = resource.prop('period_end') period_start = resource.prop('period_start') sum = resource.prop('sum') unit = resource.prop('unit') @classmethod def list(cls, session, path_args=None, **params): url = cls.base_path % path_args resp = session.get(url, service=cls.service, params=params) stats = [] for stat in resp.body: stats.append(cls.existing(**stat)) return stats
class Alarm(resource.Resource): id_attribute = 'alarm_id' base_path = '/alarms' service = telemetry_service.TelemetryService() # Supported Operations allow_create = True allow_retrieve = True allow_update = True allow_delete = True allow_list = True # Properties #: The actions to do when alarm state changes to alarm alarm_actions = resource.prop('alarm_actions') #: The UUID of the alarm alarm_id = resource.prop('alarm_id') # TODO(briancurtin): undocumented combination_rule = resource.prop('combination_rule') #: The description of the alarm description = resource.prop('description') #: ``True`` if this alarm is enabled enabled = resource.prop('enabled', type=bool) #: The actions to do when alarm state changes to insufficient data insufficient_data_actions = resource.prop('insufficient_data_actions') #: The name for the alarm name = resource.prop('name') #: The actions to do when alarm state change to ok ok_actions = resource.prop('ok_actions') #: The ID of the project or tenant that owns the alarm project_id = resource.prop('project_id') #: The actions should be re-triggered on each evaluation cycle repeat_actions = resource.prop('repeat_actions', type=bool) #: The severity of the alarm severity = resource.prop('severity') #: The state off the alarm state = resource.prop('state') #: The timestamp of the last alarm state change state_changed_at = resource.prop('state_timestamp') # TODO(briancurtin): undocumented threshold_rule = resource.prop('threshold_rule', type=dict) #: Describe time constraints for the alarm time_constraints = resource.prop('time_constraints') #: Explicit type specifier to select which rule to follow type = resource.prop('type') #: The timestamp of the last alarm definition update updated_at = resource.prop('timestamp') #: The ID of the user who created the alarm user_id = resource.prop('user_id') def change_state(self, session, next_state): """Set the state of an alarm. The next_state may be one of: 'ok' 'insufficient data' 'alarm' """ url = utils.urljoin(self.base_path, self.id, 'state') resp = session.put(url, service=self.service, json=next_state).body return resp def check_state(self, session): """Retrieve the current state of an alarm from the service. The properties of the alarm are not modified. """ url = utils.urljoin(self.base_path, self.id, 'state') resp = session.get(url, service=self.service).body current_state = resp.replace('\"', '') return current_state