示例#1
0
    def handle_update(self, json_snippet, tmpl_diff, prop_diff):
        try:
            health_obj = self.vnc_lib().service_health_check_read(
                id=self.resource_id)
        except vnc_api.NoIdError:
            LOG.warn(_("Service health check %s not found.") % self.name)
            raise
        except Exception as e:
            LOG.warn(_("Unknown error %s.") % str(e))
            raise

        health_props = vnc_api.ServiceHealthCheckType()
        if self.ENABLED in prop_diff:
            health_props.set_enabled(prop_diff.get(self.ENABLED))
        if self.MONITOR_TYPE in prop_diff:
            health_props.set_monitor_type(prop_diff.get(self.MONITOR_TYPE))
        if self.DELAY in prop_diff:
            health_props.set_delay(prop_diff.get(self.DELAY))
        if self.TIMEOUT in prop_diff:
            health_props.set_timeout(prop_diff.get(self.TIMEOUT))
        if self.MAX_RETRIES in prop_diff:
            health_props.set_max_retries(prop_diff.get(self.MAX_RETRIES))
        if self.HTTP_METHOD in prop_diff:
            health_props.set_http_method(prop_diff.get(self.HTTP_METHOD))
        if self.URL_PATH in prop_diff:
            health_props.set_url_path(prop_diff.get(self.URL_PATH))
        if self.EXPECTED_CODES in prop_diff:
            health_props.set_expected_codes(prop_diff.get(self.EXPECTED_CODES))

        health_obj.set_service_health_check_properties(health_props)
        self.vnc_lib().service_health_check_update(health_obj)
示例#2
0
    def handle_create(self):
        tenant_id = self.stack.context.tenant_id
        project_obj = self.vnc_lib().project_read(id=str(uuid.UUID(tenant_id)))
        try:
            si_obj = self.vnc_lib().service_instance_read(
                id=self.properties[self.SERVICE_INSTANCE])
        except vnc_api.NoIdError:
            si_name = project_obj.fq_name + \
                [self.properties[self.SERVICE_INSTANCE]]
            si_obj = self.vnc_lib().service_instance_read(fq_name=si_name)

        health_props = vnc_api.ServiceHealthCheckType(
            enabled=self.properties[self.ENABLED],
            monitor_type=self.properties[self.MONITOR_TYPE],
            delay=self.properties[self.DELAY],
            timeout=self.properties[self.TIMEOUT],
            max_retries=self.properties[self.MAX_RETRIES],
            http_method=self.properties[self.HTTP_METHOD],
            url_path=self.properties[self.URL_PATH],
            expected_codes=self.properties[self.EXPECTED_CODES])
        health_obj = vnc_api.ServiceHealthCheck(
            name=self.properties[self.NAME],
            parent_obj=project_obj,
            service_health_check_properties=health_props)
        health_obj.set_service_instance(
            si_obj,
            vnc_api.ServiceInterfaceTag(
                self.properties[self.SERVICE_PORT_TAG]))
        health_uuid = self.vnc_lib().service_health_check_create(health_obj)
        self.resource_id_set(health_uuid)
示例#3
0
    def handle_update(self, json_snippet, tmpl_diff, prop_diff):
        try:
            obj_0 = self.vnc_lib().service_health_check_read(
                id=self.resource_id)
        except:
            raise Exception(
                _('service-health-check %s not found.') % self.name)

        if prop_diff.get(self.SERVICE_HEALTH_CHECK_PROPERTIES) is not None:
            obj_1 = vnc_api.ServiceHealthCheckType()
            if prop_diff.get(self.SERVICE_HEALTH_CHECK_PROPERTIES, {}).get(
                    self.SERVICE_HEALTH_CHECK_PROPERTIES_ENABLED) is not None:
                obj_1.set_enabled(
                    prop_diff.get(
                        self.SERVICE_HEALTH_CHECK_PROPERTIES,
                        {}).get(self.SERVICE_HEALTH_CHECK_PROPERTIES_ENABLED))
            if prop_diff.get(self.SERVICE_HEALTH_CHECK_PROPERTIES, {}).get(
                    self.SERVICE_HEALTH_CHECK_PROPERTIES_HEALTH_CHECK_TYPE
            ) is not None:
                obj_1.set_health_check_type(
                    prop_diff.get(
                        self.SERVICE_HEALTH_CHECK_PROPERTIES, {}).get(
                            self.
                            SERVICE_HEALTH_CHECK_PROPERTIES_HEALTH_CHECK_TYPE))
            if prop_diff.get(self.SERVICE_HEALTH_CHECK_PROPERTIES, {}).get(
                    self.SERVICE_HEALTH_CHECK_PROPERTIES_MONITOR_TYPE
            ) is not None:
                obj_1.set_monitor_type(
                    prop_diff.get(
                        self.SERVICE_HEALTH_CHECK_PROPERTIES, {}).get(
                            self.SERVICE_HEALTH_CHECK_PROPERTIES_MONITOR_TYPE))
            if prop_diff.get(self.SERVICE_HEALTH_CHECK_PROPERTIES, {}).get(
                    self.SERVICE_HEALTH_CHECK_PROPERTIES_DELAY) is not None:
                obj_1.set_delay(
                    prop_diff.get(
                        self.SERVICE_HEALTH_CHECK_PROPERTIES,
                        {}).get(self.SERVICE_HEALTH_CHECK_PROPERTIES_DELAY))
            if prop_diff.get(self.SERVICE_HEALTH_CHECK_PROPERTIES, {}).get(
                    self.SERVICE_HEALTH_CHECK_PROPERTIES_TIMEOUT) is not None:
                obj_1.set_timeout(
                    prop_diff.get(
                        self.SERVICE_HEALTH_CHECK_PROPERTIES,
                        {}).get(self.SERVICE_HEALTH_CHECK_PROPERTIES_TIMEOUT))
            if prop_diff.get(self.SERVICE_HEALTH_CHECK_PROPERTIES, {}).get(
                    self.SERVICE_HEALTH_CHECK_PROPERTIES_MAX_RETRIES
            ) is not None:
                obj_1.set_max_retries(
                    prop_diff.get(
                        self.SERVICE_HEALTH_CHECK_PROPERTIES, {}).get(
                            self.SERVICE_HEALTH_CHECK_PROPERTIES_MAX_RETRIES))
            if prop_diff.get(self.SERVICE_HEALTH_CHECK_PROPERTIES, {}).get(
                    self.SERVICE_HEALTH_CHECK_PROPERTIES_HTTP_METHOD
            ) is not None:
                obj_1.set_http_method(
                    prop_diff.get(
                        self.SERVICE_HEALTH_CHECK_PROPERTIES, {}).get(
                            self.SERVICE_HEALTH_CHECK_PROPERTIES_HTTP_METHOD))
            if prop_diff.get(self.SERVICE_HEALTH_CHECK_PROPERTIES, {}).get(
                    self.SERVICE_HEALTH_CHECK_PROPERTIES_URL_PATH) is not None:
                obj_1.set_url_path(
                    prop_diff.get(
                        self.SERVICE_HEALTH_CHECK_PROPERTIES,
                        {}).get(self.SERVICE_HEALTH_CHECK_PROPERTIES_URL_PATH))
            if prop_diff.get(self.SERVICE_HEALTH_CHECK_PROPERTIES, {}).get(
                    self.SERVICE_HEALTH_CHECK_PROPERTIES_EXPECTED_CODES
            ) is not None:
                obj_1.set_expected_codes(
                    prop_diff.get(self.SERVICE_HEALTH_CHECK_PROPERTIES, {}).
                    get(self.SERVICE_HEALTH_CHECK_PROPERTIES_EXPECTED_CODES))
            obj_0.set_service_health_check_properties(obj_1)
        if prop_diff.get(self.DISPLAY_NAME) is not None:
            obj_0.set_display_name(prop_diff.get(self.DISPLAY_NAME))

        # reference to service_instance
        ref_obj_list = []
        ref_data_list = []
        if prop_diff.get(self.SERVICE_INSTANCE_REFS_DATA) is not None:
            for index_0 in range(
                    len(prop_diff.get(self.SERVICE_INSTANCE_REFS_DATA))):
                obj_1 = vnc_api.ServiceInterfaceTag()
                if prop_diff.get(
                        self.SERVICE_INSTANCE_REFS_DATA, {})[index_0].get(
                            self.SERVICE_INSTANCE_REFS_DATA_INTERFACE_TYPE
                        ) is not None:
                    obj_1.set_interface_type(
                        prop_diff.get(self.SERVICE_INSTANCE_REFS_DATA, {})
                        [index_0].get(
                            self.SERVICE_INSTANCE_REFS_DATA_INTERFACE_TYPE))
                ref_data_list.append(obj_1)
        if self.SERVICE_INSTANCE_REFS in prop_diff:
            for index_0 in range(
                    len(prop_diff.get(self.SERVICE_INSTANCE_REFS_DATA) or [])):
                try:
                    ref_obj = self.vnc_lib().service_instance_read(
                        id=prop_diff.get(self.SERVICE_INSTANCE_REFS)[index_0])
                except:
                    ref_obj = self.vnc_lib().service_instance_read(
                        fq_name_str=prop_diff.get(
                            self.SERVICE_INSTANCE_REFS)[index_0])
                ref_obj_list.append(ref_obj.fq_name)

            obj_0.set_service_instance_list(ref_obj_list, ref_data_list)
            # End: reference to service_instance_refs

        try:
            self.vnc_lib().service_health_check_update(obj_0)
        except:
            raise Exception(
                _('service-health-check %s could not be updated.') % self.name)
示例#4
0
    def handle_create(self):
        parent_obj = None
        if parent_obj is None and self.properties.get(self.PROJECT):
            try:
                parent_obj = self.vnc_lib().project_read(
                    id=self.properties.get(self.PROJECT))
            except vnc_api.NoIdError:
                parent_obj = self.vnc_lib().project_read(
                    fq_name_str=self.properties.get(self.PROJECT))
            except:
                parent_obj = None

        if parent_obj is None:
            tenant_id = self.stack.context.tenant_id
            parent_obj = self.vnc_lib().project_read(
                id=str(uuid.UUID(tenant_id)))

        if parent_obj is None:
            raise Exception('Error: parent is not specified in template!')

        obj_0 = vnc_api.ServiceHealthCheck(name=self.properties[self.NAME],
                                           parent_obj=parent_obj)

        if self.properties.get(
                self.SERVICE_HEALTH_CHECK_PROPERTIES) is not None:
            obj_1 = vnc_api.ServiceHealthCheckType()
            if self.properties.get(
                    self.SERVICE_HEALTH_CHECK_PROPERTIES,
                {}).get(
                    self.SERVICE_HEALTH_CHECK_PROPERTIES_ENABLED) is not None:
                obj_1.set_enabled(
                    self.properties.get(
                        self.SERVICE_HEALTH_CHECK_PROPERTIES,
                        {}).get(self.SERVICE_HEALTH_CHECK_PROPERTIES_ENABLED))
            if self.properties.get(
                    self.SERVICE_HEALTH_CHECK_PROPERTIES,
                {}).get(self.SERVICE_HEALTH_CHECK_PROPERTIES_HEALTH_CHECK_TYPE
                        ) is not None:
                obj_1.set_health_check_type(
                    self.properties.get(
                        self.SERVICE_HEALTH_CHECK_PROPERTIES, {}).get(
                            self.
                            SERVICE_HEALTH_CHECK_PROPERTIES_HEALTH_CHECK_TYPE))
            if self.properties.get(
                    self.SERVICE_HEALTH_CHECK_PROPERTIES,
                {}).get(self.SERVICE_HEALTH_CHECK_PROPERTIES_MONITOR_TYPE
                        ) is not None:
                obj_1.set_monitor_type(
                    self.properties.get(
                        self.SERVICE_HEALTH_CHECK_PROPERTIES, {}).get(
                            self.SERVICE_HEALTH_CHECK_PROPERTIES_MONITOR_TYPE))
            if self.properties.get(
                    self.SERVICE_HEALTH_CHECK_PROPERTIES,
                {}).get(
                    self.SERVICE_HEALTH_CHECK_PROPERTIES_DELAY) is not None:
                obj_1.set_delay(
                    self.properties.get(
                        self.SERVICE_HEALTH_CHECK_PROPERTIES,
                        {}).get(self.SERVICE_HEALTH_CHECK_PROPERTIES_DELAY))
            if self.properties.get(
                    self.SERVICE_HEALTH_CHECK_PROPERTIES,
                {}).get(
                    self.SERVICE_HEALTH_CHECK_PROPERTIES_TIMEOUT) is not None:
                obj_1.set_timeout(
                    self.properties.get(
                        self.SERVICE_HEALTH_CHECK_PROPERTIES,
                        {}).get(self.SERVICE_HEALTH_CHECK_PROPERTIES_TIMEOUT))
            if self.properties.get(
                    self.SERVICE_HEALTH_CHECK_PROPERTIES,
                {}).get(self.SERVICE_HEALTH_CHECK_PROPERTIES_MAX_RETRIES
                        ) is not None:
                obj_1.set_max_retries(
                    self.properties.get(
                        self.SERVICE_HEALTH_CHECK_PROPERTIES, {}).get(
                            self.SERVICE_HEALTH_CHECK_PROPERTIES_MAX_RETRIES))
            if self.properties.get(
                    self.SERVICE_HEALTH_CHECK_PROPERTIES,
                {}).get(self.SERVICE_HEALTH_CHECK_PROPERTIES_HTTP_METHOD
                        ) is not None:
                obj_1.set_http_method(
                    self.properties.get(
                        self.SERVICE_HEALTH_CHECK_PROPERTIES, {}).get(
                            self.SERVICE_HEALTH_CHECK_PROPERTIES_HTTP_METHOD))
            if self.properties.get(
                    self.SERVICE_HEALTH_CHECK_PROPERTIES,
                {}).get(
                    self.SERVICE_HEALTH_CHECK_PROPERTIES_URL_PATH) is not None:
                obj_1.set_url_path(
                    self.properties.get(
                        self.SERVICE_HEALTH_CHECK_PROPERTIES,
                        {}).get(self.SERVICE_HEALTH_CHECK_PROPERTIES_URL_PATH))
            if self.properties.get(
                    self.SERVICE_HEALTH_CHECK_PROPERTIES,
                {}).get(self.SERVICE_HEALTH_CHECK_PROPERTIES_EXPECTED_CODES
                        ) is not None:
                obj_1.set_expected_codes(
                    self.properties.get(self.SERVICE_HEALTH_CHECK_PROPERTIES,
                                        {}).
                    get(self.SERVICE_HEALTH_CHECK_PROPERTIES_EXPECTED_CODES))
            obj_0.set_service_health_check_properties(obj_1)
        if self.properties.get(self.DISPLAY_NAME) is not None:
            obj_0.set_display_name(self.properties.get(self.DISPLAY_NAME))

        # reference to service_instance_refs
        obj_1 = None
        if self.properties.get(self.SERVICE_INSTANCE_REFS_DATA) is not None:
            for index_0 in range(
                    len(self.properties.get(self.SERVICE_INSTANCE_REFS_DATA))):
                obj_1 = vnc_api.ServiceInterfaceTag()
                if self.properties.get(
                        self.SERVICE_INSTANCE_REFS_DATA, {})[index_0].get(
                            self.SERVICE_INSTANCE_REFS_DATA_INTERFACE_TYPE
                        ) is not None:
                    obj_1.set_interface_type(
                        self.properties.get(self.SERVICE_INSTANCE_REFS_DATA,
                                            {})
                        [index_0].get(
                            self.SERVICE_INSTANCE_REFS_DATA_INTERFACE_TYPE))

                if self.properties.get(self.SERVICE_INSTANCE_REFS):
                    try:
                        ref_obj = self.vnc_lib().service_instance_read(
                            id=self.properties.get(
                                self.SERVICE_INSTANCE_REFS)[index_0])
                    except vnc_api.NoIdError:
                        ref_obj = self.vnc_lib().service_instance_read(
                            fq_name_str=self.properties.get(
                                self.SERVICE_INSTANCE_REFS)[index_0])
                    obj_0.add_service_instance(ref_obj, obj_1)

        try:
            obj_uuid = super(ContrailServiceHealthCheck,
                             self).resource_create(obj_0)
        except:
            raise Exception(
                _('service-health-check %s could not be updated.') % self.name)

        self.resource_id_set(obj_uuid)