Esempio n. 1
0
class MonitoringChannelSerializer(serializers.ModelSerializer,
                                  PlusSerializerMixin):
    id = ReadOnlyField()
    service_specific_attribute = ReadOnlyField()
    ceilometer_url = ReadOnlyField()
    tenant_list_str = ReadOnlyField()
    creator = ReadOnlyField()
    instance = ReadOnlyField()
    provider_service = serializers.PrimaryKeyRelatedField(
        queryset=CeilometerService.get_service_objects().all(),
        default=get_default_ceilometer_service)

    humanReadableName = serializers.SerializerMethodField(
        "getHumanReadableName")

    computeNodeName = serializers.SerializerMethodField("getComputeNodeName")

    class Meta:
        model = MonitoringChannel
        fields = ('humanReadableName', 'id', 'provider_service',
                  'service_specific_attribute', 'ceilometer_url',
                  'tenant_list_str', 'creator', 'instance', 'computeNodeName')

    def getHumanReadableName(self, obj):
        return obj.__unicode__()

    def getComputeNodeName(self, obj):
        instance = obj.instance
        if not instance:
            return None
        return instance.node.name
Esempio n. 2
0
    def get_extra_attributes(self, o):
        # This is a place to include extra attributes. In the case of Monitoring Channel, we need to know
        #   1) Allowed tenant ids
        #   2) Ceilometer API service endpoint URL if running externally
        #   3) Credentials to access Ceilometer API service

        ceilometer_services = CeilometerService.get_service_objects().filter(
            id=o.provider_service.id)
        if not ceilometer_services:
            raise "No associated Ceilometer service"
        ceilometer_service = ceilometer_services[0]
        ceilometer_pub_sub_url = ceilometer_service.ceilometer_pub_sub_url
        if not ceilometer_pub_sub_url:
            ceilometer_pub_sub_url = ''
        instance = self.get_instance(o)

        try:
            full_setup = Config().observer_full_setup
        except:
            full_setup = True

        fields = {
            "unique_id": o.id,
            "allowed_tenant_ids": o.tenant_list,
            "auth_url": instance.controller.auth_url,
            "admin_user": instance.controller.admin_user,
            "admin_password": instance.controller.admin_password,
            "admin_tenant": instance.controller.admin_tenant,
            "ceilometer_pub_sub_url": ceilometer_pub_sub_url,
            "full_setup": full_setup
        }

        return fields
    def get_extra_attributes(self, o):
        # This is a place to include extra attributes. In the case of Monitoring Channel, we need to know
        #   1) Allowed tenant ids
        #   2) Ceilometer API service endpoint URL if running externally
        #   3) Credentials to access Ceilometer API service

        ceilometer_services = CeilometerService.get_service_objects().filter(id=o.provider_service.id)
        if not ceilometer_services:
            raise "No associated Ceilometer service"
        ceilometer_service = ceilometer_services[0]
        ceilometer_pub_sub_url = ceilometer_service.ceilometer_pub_sub_url
        if not ceilometer_pub_sub_url:
            ceilometer_pub_sub_url = ''
        instance = self.get_instance(o)

        try:
            full_setup = Config().observer_full_setup
        except:
            full_setup = True

        fields = {"unique_id": o.id,
                  "allowed_tenant_ids": o.tenant_list,
                  "auth_url":instance.controller.auth_url,
                  "admin_user":instance.controller.admin_user,
                  "admin_password":instance.controller.admin_password,
                  "admin_tenant":instance.controller.admin_tenant,
                  "ceilometer_pub_sub_url": ceilometer_pub_sub_url,
                  "full_setup": full_setup}

        return fields
Esempio n. 4
0
class MonitoringChannelSerializer(PlusModelSerializer):
    id = ReadOnlyField()
    service_specific_attribute = ReadOnlyField()
    ceilometer_url = ReadOnlyField()
    tenant_list_str = ReadOnlyField()
    #creator = ReadOnlyField()
    #instance = ReadOnlyField()
    provider_service = serializers.PrimaryKeyRelatedField(
        queryset=CeilometerService.get_service_objects().all(),
        default=get_default_ceilometer_service)

    humanReadableName = serializers.SerializerMethodField(
        "getHumanReadableName")
    related = serializers.DictField(required=False)

    #computeNodeName = serializers.SerializerMethodField("getComputeNodeName")

    class Meta:
        model = MonitoringChannelForAPI
        fields = ('humanReadableName', 'id', 'provider_service',
                  'service_specific_attribute', 'ceilometer_url',
                  'tenant_list_str', 'related')

    def getHumanReadableName(self, obj):
        return obj.__unicode__()
Esempio n. 5
0
def get_default_ceilometer_service():
    ceilometer_services = CeilometerService.get_service_objects().all()
    if ceilometer_services:
        return ceilometer_services[0].id
    return None
Esempio n. 6
0
def get_default_ceilometer_service():
    ceilometer_services = CeilometerService.get_service_objects().all()
    if ceilometer_services:
        return ceilometer_services[0].id
    return None