Esempio n. 1
0
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
    is_enabled = resource.prop('enabled', type=bool)

    @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)
Esempio n. 2
0
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 ID of the meter
    meter_id = resource.prop('meter_id')
    #: The unique name for the meter
    name = resource.prop('name')
    #: The ID of the project 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 name of the source 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')
Esempio n. 3
0
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.
    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)
        resp = session.get(url, endpoint_filter=cls.service, params=params)
        for item in resp.json():
            yield cls.existing(**item)
Esempio n. 4
0
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
    project_id = resource.prop('project_id')
    #: The ID for the resource
    resource_id = resource.prop('resource_id')
    #: The name of 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')
Esempio n. 5
0
 def test_service(self):
     sot = telemetry_service.TelemetryService()
     self.assertEqual('metering', sot.service_type)
     self.assertEqual('public', sot.interface)
     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)
Esempio n. 6
0
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
    #: The meter name this sample is for
    counter_name = resource.prop('meter', alias='counter_name')
    #: When the sample has been generated.
    generated_at = resource.prop('timestamp')
    #: Arbitrary metadata associated with the sample
    metadata = resource.prop('metadata', alias='resource_metadata')
    #: The ID of 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 ID of the resource this sample was taken for
    resource_id = resource.prop('resource_id')
    #: The name of the source that identifies where the sample comes from
    source = resource.prop('source')
    #: The meter type
    type = resource.prop('type', alias='counter_type')
    #: The unit of measure
    unit = resource.prop('unit', alias='counter_unit')
    #: The ID of 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
Esempio n. 7
0
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.
    duration_end_at = resource.prop('duration_end')
    #: UTC date and time of the earliest timestamp, or the query start time.
    duration_start_at = 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_at = resource.prop('period_end')
    #: UTC date and time of the period start.
    period_start_at = 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)
        resp = session.get(url, endpoint_filter=cls.service, params=params)
        for stat in resp.json():
            yield cls.existing(**stat)
Esempio n. 8
0
    def __init__(self, plugins=None):
        """User preference for each service.

        :param list plugins: List of entry point namespaces to load.

        Create a new :class:`~ecl.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(compute_service.ComputeService(version="v2"))
        self._add_service(
            connectivity_service.ConnectivityService(version="v1"))
        self._add_service(identity_service.IdentityService(version="v3"))
        self._add_service(image_service.ImageService(version="v2"))
        self._add_service(network_service.NetworkService(version="v2"))
        self._add_service(sss_service.SssService(version="v1"))
        self._add_service(
            orchestration_service.OrchestrationService(version="v1"))
        self._add_service(
            provider_connectivity_service.ProviderConnectivityService(
                version="v2"))
        self._add_service(telemetry_service.TelemetryService(version="v2"))
        self._add_service(block_store_service.BlockStoreService(version="v2"))
        self._add_service(storage_service.StorageService(version="v1"))
        self._add_service(
            security_order_service.SecurityOrderService(version="v2"))
        self._add_service(
            security_portal_service.SecurityPortalService(version="v2"))
        ## This section will be deleted if MSS v1 API is not available
        self._add_service(
            security_order_service_v1.SecurityOrderService(version="v1"))
        self._add_service(
            security_portal_service_v1.SecurityPortalService(version="v1"))
        ## end of the section
        self._add_service(rca_service.RcaService(version="v1"))
        self._add_service(baremetal_service.BaremetalService(version="v2"))
        self._add_service(
            dedicated_hypervisor_service.DedicatedHypervisorService(
                version="v1"))
        self._add_service(dns_service.DnsService(version="v2"))
        self._add_service(
            virtual_network_appliance_service.VirtualNetworkApplianceService(
                version="v1"))
        self._add_service(mvna_service.MVNAService(version="v1"))

        # NOTE: The Metric service is not added here as it currently
        # only retrieves the /capabilities API.

        if plugins:
            for plugin in plugins:
                self._load_plugin(plugin)
        self.service_keys = sorted(self._services.keys())
Esempio n. 9
0
class Alarm(resource.Resource):
    """.. caution:: This API is a work in progress and is subject to change."""
    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 ID 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. *Type: bool*
    is_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 actions should be re-triggered on each evaluation cycle.
    #: *Type: bool*
    is_repeat_actions = resource.prop('repeat_actions', type=bool)
    #: 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 that owns the alarm
    project_id = resource.prop('project_id')
    #: 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, endpoint_filter=self.service, json=next_state)
        return resp.json()

    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, endpoint_filter=self.service)
        resp = resp.json()
        current_state = resp.replace('\"', '')
        return current_state