コード例 #1
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)
コード例 #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)

        route_table = vnc_api.RouteTableType()
        for route in self.properties[self.ROUTES]:
            route_table.add_route(vnc_api.RouteType(prefix=route))
        rt_obj = vnc_api.InterfaceRouteTable(
            name=self.properties[self.NAME],
            parent_obj=project_obj,
            interface_route_table_routes=route_table)
        rt_obj.set_service_instance(
            si_obj,
            vnc_api.ServiceInterfaceTag(
                self.properties[self.SERVICE_PORT_TAG]))
        rt_uuid = self.vnc_lib().interface_route_table_create(rt_obj)
        self.resource_id_set(rt_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)
コード例 #5
0
    def handle_update(self, json_snippet, tmpl_diff, prop_diff):
        try:
            obj_0 = self.vnc_lib().interface_route_table_read(
                id=self.resource_id)
        except:
            raise Exception(
                _('interface-route-table %s not found.') % self.name)

        if prop_diff.get(self.DISPLAY_NAME) is not None:
            obj_0.set_display_name(prop_diff.get(self.DISPLAY_NAME))
        if prop_diff.get(self.INTERFACE_ROUTE_TABLE_ROUTES) is not None:
            obj_1 = vnc_api.RouteTableType()
            if prop_diff.get(self.INTERFACE_ROUTE_TABLE_ROUTES, {}).get(
                    self.INTERFACE_ROUTE_TABLE_ROUTES_ROUTE) is not None:
                for index_1 in range(
                        len(
                            prop_diff.get(
                                self.INTERFACE_ROUTE_TABLE_ROUTES, {}).get(
                                    self.INTERFACE_ROUTE_TABLE_ROUTES_ROUTE))):
                    obj_2 = vnc_api.RouteType()
                    if prop_diff.get(
                            self.INTERFACE_ROUTE_TABLE_ROUTES,
                        {}).get(
                            self.INTERFACE_ROUTE_TABLE_ROUTES_ROUTE,
                            {})[index_1].get(
                                self.INTERFACE_ROUTE_TABLE_ROUTES_ROUTE_PREFIX
                            ) is not None:
                        obj_2.set_prefix(
                            prop_diff.get(self.INTERFACE_ROUTE_TABLE_ROUTES,
                                          {}).
                            get(self.INTERFACE_ROUTE_TABLE_ROUTES_ROUTE,
                                {})[index_1].get(
                                    self.
                                    INTERFACE_ROUTE_TABLE_ROUTES_ROUTE_PREFIX))
                    if prop_diff.get(
                            self.INTERFACE_ROUTE_TABLE_ROUTES, {}
                    ).get(self.INTERFACE_ROUTE_TABLE_ROUTES_ROUTE,
                          {})[index_1].get(
                              self.INTERFACE_ROUTE_TABLE_ROUTES_ROUTE_NEXT_HOP
                          ) is not None:
                        obj_2.set_next_hop(
                            prop_diff.get(
                                self.INTERFACE_ROUTE_TABLE_ROUTES, {}).get(
                                    self.INTERFACE_ROUTE_TABLE_ROUTES_ROUTE,
                                    {})
                            [index_1].get(
                                self.
                                INTERFACE_ROUTE_TABLE_ROUTES_ROUTE_NEXT_HOP))
                    if prop_diff.get(
                            self.INTERFACE_ROUTE_TABLE_ROUTES, {}
                    ).get(self.INTERFACE_ROUTE_TABLE_ROUTES_ROUTE,
                          {})[index_1].get(
                              self.
                              INTERFACE_ROUTE_TABLE_ROUTES_ROUTE_NEXT_HOP_TYPE
                          ) is not None:
                        obj_2.set_next_hop_type(
                            prop_diff.get(
                                self.INTERFACE_ROUTE_TABLE_ROUTES, {}).get(
                                    self.INTERFACE_ROUTE_TABLE_ROUTES_ROUTE,
                                    {})
                            [index_1].get(
                                self.
                                INTERFACE_ROUTE_TABLE_ROUTES_ROUTE_NEXT_HOP_TYPE
                            ))
                    if prop_diff.get(
                            self.INTERFACE_ROUTE_TABLE_ROUTES,
                        {}).get(
                            self.INTERFACE_ROUTE_TABLE_ROUTES_ROUTE, {}
                        )[index_1].get(
                            self.
                            INTERFACE_ROUTE_TABLE_ROUTES_ROUTE_COMMUNITY_ATTRIBUTES
                        ) is not None:
                        obj_3 = vnc_api.CommunityAttributes()
                        if prop_diff.get(
                                self.INTERFACE_ROUTE_TABLE_ROUTES, {}
                        ).get(
                                self.INTERFACE_ROUTE_TABLE_ROUTES_ROUTE, {}
                        )[index_1].get(
                                self.
                                INTERFACE_ROUTE_TABLE_ROUTES_ROUTE_COMMUNITY_ATTRIBUTES,
                            {}
                        ).get(self.
                              INTERFACE_ROUTE_TABLE_ROUTES_ROUTE_COMMUNITY_ATTRIBUTES_COMMUNITY_ATTRIBUTE
                              ) is not None:
                            for index_3 in range(
                                    len(
                                        prop_diff.get(
                                            self.INTERFACE_ROUTE_TABLE_ROUTES,
                                            {}
                                        ).get(
                                            self.
                                            INTERFACE_ROUTE_TABLE_ROUTES_ROUTE,
                                            {})
                                        [index_1].get(
                                            self.
                                            INTERFACE_ROUTE_TABLE_ROUTES_ROUTE_COMMUNITY_ATTRIBUTES,
                                            {}).
                                        get(self.
                                            INTERFACE_ROUTE_TABLE_ROUTES_ROUTE_COMMUNITY_ATTRIBUTES_COMMUNITY_ATTRIBUTE
                                            ))):
                                obj_3.add_community_attribute(
                                    prop_diff.get(
                                        self.INTERFACE_ROUTE_TABLE_ROUTES,
                                        {}).get(
                                            self.
                                            INTERFACE_ROUTE_TABLE_ROUTES_ROUTE,
                                            {})
                                    [index_1].get(
                                        self.
                                        INTERFACE_ROUTE_TABLE_ROUTES_ROUTE_COMMUNITY_ATTRIBUTES,
                                        {}).
                                    get(self.
                                        INTERFACE_ROUTE_TABLE_ROUTES_ROUTE_COMMUNITY_ATTRIBUTES_COMMUNITY_ATTRIBUTE
                                        )[index_3])
                        obj_2.set_community_attributes(obj_3)
                    obj_1.add_route(obj_2)
            obj_0.set_interface_route_table_routes(obj_1)

        # 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().interface_route_table_update(obj_0)
        except:
            raise Exception(
                _('interface-route-table %s could not be updated.') %
                self.name)
コード例 #6
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.InterfaceRouteTable(name=self.properties[self.NAME],
                                            parent_obj=parent_obj)

        if self.properties.get(self.DISPLAY_NAME) is not None:
            obj_0.set_display_name(self.properties.get(self.DISPLAY_NAME))
        if self.properties.get(self.INTERFACE_ROUTE_TABLE_ROUTES) is not None:
            obj_1 = vnc_api.RouteTableType()
            if self.properties.get(self.INTERFACE_ROUTE_TABLE_ROUTES, {}).get(
                    self.INTERFACE_ROUTE_TABLE_ROUTES_ROUTE) is not None:
                for index_1 in range(
                        len(
                            self.properties.get(
                                self.INTERFACE_ROUTE_TABLE_ROUTES, {}).get(
                                    self.INTERFACE_ROUTE_TABLE_ROUTES_ROUTE))):
                    obj_2 = vnc_api.RouteType()
                    if self.properties.get(
                            self.INTERFACE_ROUTE_TABLE_ROUTES,
                        {}).get(
                            self.INTERFACE_ROUTE_TABLE_ROUTES_ROUTE,
                            {})[index_1].get(
                                self.INTERFACE_ROUTE_TABLE_ROUTES_ROUTE_PREFIX
                            ) is not None:
                        obj_2.set_prefix(
                            self.properties.get(
                                self.INTERFACE_ROUTE_TABLE_ROUTES, {}).get(
                                    self.INTERFACE_ROUTE_TABLE_ROUTES_ROUTE,
                                    {})
                            [index_1].get(
                                self.INTERFACE_ROUTE_TABLE_ROUTES_ROUTE_PREFIX)
                        )
                    if self.properties.get(
                            self.INTERFACE_ROUTE_TABLE_ROUTES, {}
                    ).get(self.INTERFACE_ROUTE_TABLE_ROUTES_ROUTE,
                          {})[index_1].get(
                              self.INTERFACE_ROUTE_TABLE_ROUTES_ROUTE_NEXT_HOP
                          ) is not None:
                        obj_2.set_next_hop(
                            self.properties.get(
                                self.INTERFACE_ROUTE_TABLE_ROUTES, {}).get(
                                    self.INTERFACE_ROUTE_TABLE_ROUTES_ROUTE,
                                    {})
                            [index_1].get(
                                self.
                                INTERFACE_ROUTE_TABLE_ROUTES_ROUTE_NEXT_HOP))
                    if self.properties.get(
                            self.INTERFACE_ROUTE_TABLE_ROUTES, {}
                    ).get(self.INTERFACE_ROUTE_TABLE_ROUTES_ROUTE,
                          {})[index_1].get(
                              self.
                              INTERFACE_ROUTE_TABLE_ROUTES_ROUTE_NEXT_HOP_TYPE
                          ) is not None:
                        obj_2.set_next_hop_type(
                            self.properties.get(
                                self.INTERFACE_ROUTE_TABLE_ROUTES, {}).get(
                                    self.INTERFACE_ROUTE_TABLE_ROUTES_ROUTE,
                                    {})
                            [index_1].get(
                                self.
                                INTERFACE_ROUTE_TABLE_ROUTES_ROUTE_NEXT_HOP_TYPE
                            ))
                    if self.properties.get(
                            self.INTERFACE_ROUTE_TABLE_ROUTES,
                        {}).get(
                            self.INTERFACE_ROUTE_TABLE_ROUTES_ROUTE, {}
                        )[index_1].get(
                            self.
                            INTERFACE_ROUTE_TABLE_ROUTES_ROUTE_COMMUNITY_ATTRIBUTES
                        ) is not None:
                        obj_3 = vnc_api.CommunityAttributes()
                        if self.properties.get(
                                self.INTERFACE_ROUTE_TABLE_ROUTES, {}
                        ).get(
                                self.INTERFACE_ROUTE_TABLE_ROUTES_ROUTE, {}
                        )[index_1].get(
                                self.
                                INTERFACE_ROUTE_TABLE_ROUTES_ROUTE_COMMUNITY_ATTRIBUTES,
                            {}
                        ).get(self.
                              INTERFACE_ROUTE_TABLE_ROUTES_ROUTE_COMMUNITY_ATTRIBUTES_COMMUNITY_ATTRIBUTE
                              ) is not None:
                            for index_3 in range(
                                    len(
                                        self.properties.get(
                                            self.INTERFACE_ROUTE_TABLE_ROUTES,
                                            {}
                                        ).get(
                                            self.
                                            INTERFACE_ROUTE_TABLE_ROUTES_ROUTE,
                                            {})
                                        [index_1].get(
                                            self.
                                            INTERFACE_ROUTE_TABLE_ROUTES_ROUTE_COMMUNITY_ATTRIBUTES,
                                            {}).
                                        get(self.
                                            INTERFACE_ROUTE_TABLE_ROUTES_ROUTE_COMMUNITY_ATTRIBUTES_COMMUNITY_ATTRIBUTE
                                            ))):
                                obj_3.add_community_attribute(
                                    self.properties.get(
                                        self.INTERFACE_ROUTE_TABLE_ROUTES,
                                        {}).get(
                                            self.
                                            INTERFACE_ROUTE_TABLE_ROUTES_ROUTE,
                                            {})
                                    [index_1].get(
                                        self.
                                        INTERFACE_ROUTE_TABLE_ROUTES_ROUTE_COMMUNITY_ATTRIBUTES,
                                        {}).
                                    get(self.
                                        INTERFACE_ROUTE_TABLE_ROUTES_ROUTE_COMMUNITY_ATTRIBUTES_COMMUNITY_ATTRIBUTE
                                        )[index_3])
                        obj_2.set_community_attributes(obj_3)
                    obj_1.add_route(obj_2)
            obj_0.set_interface_route_table_routes(obj_1)

        # 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(ContrailInterfaceRouteTable,
                             self).resource_create(obj_0)
        except:
            raise Exception(
                _('interface-route-table %s could not be updated.') %
                self.name)

        self.resource_id_set(obj_uuid)
コード例 #7
0
    def handle_update(self, json_snippet, tmpl_diff, prop_diff):
        try:
            obj_0 = self.vnc_lib().route_aggregate_read(id=self.resource_id)
        except:
            raise Exception(_('route-aggregate %s not found.') % self.name)

        if prop_diff.get(self.AGGREGATE_ROUTE_ENTRIES) is not None:
            obj_1 = vnc_api.RouteListType()
            if prop_diff.get(self.AGGREGATE_ROUTE_ENTRIES, {}).get(
                    self.AGGREGATE_ROUTE_ENTRIES_ROUTE) is not None:
                for index_1 in range(
                        len(
                            prop_diff.get(
                                self.AGGREGATE_ROUTE_ENTRIES,
                                {}).get(self.AGGREGATE_ROUTE_ENTRIES_ROUTE))):
                    obj_1.add_route(
                        prop_diff.get(self.AGGREGATE_ROUTE_ENTRIES, {}).get(
                            self.AGGREGATE_ROUTE_ENTRIES_ROUTE)[index_1])
            obj_0.set_aggregate_route_entries(obj_1)
        if prop_diff.get(self.DISPLAY_NAME) is not None:
            obj_0.set_display_name(prop_diff.get(self.DISPLAY_NAME))
        if prop_diff.get(self.AGGREGATE_ROUTE_NEXTHOP) is not None:
            obj_0.set_aggregate_route_nexthop(
                prop_diff.get(self.AGGREGATE_ROUTE_NEXTHOP))

        # 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

        # reference to routing_instance_refs
        ref_obj_list = []
        ref_data_list = []
        if self.ROUTING_INSTANCE_REFS in prop_diff:
            for index_0 in range(
                    len(prop_diff.get(self.ROUTING_INSTANCE_REFS) or [])):
                try:
                    ref_obj = self.vnc_lib().routing_instance_read(
                        id=prop_diff.get(self.ROUTING_INSTANCE_REFS)[index_0])
                except:
                    ref_obj = self.vnc_lib().routing_instance_read(
                        fq_name_str=prop_diff.get(
                            self.ROUTING_INSTANCE_REFS)[index_0])
                ref_obj_list.append(ref_obj.fq_name)

            obj_0.set_routing_instance_list(ref_obj_list)
            # End: reference to routing_instance_refs

        try:
            self.vnc_lib().route_aggregate_update(obj_0)
        except:
            raise Exception(
                _('route-aggregate %s could not be updated.') % self.name)
コード例 #8
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.RouteAggregate(name=self.properties[self.NAME],
                                       parent_obj=parent_obj)

        if self.properties.get(self.AGGREGATE_ROUTE_ENTRIES) is not None:
            obj_1 = vnc_api.RouteListType()
            if self.properties.get(self.AGGREGATE_ROUTE_ENTRIES, {}).get(
                    self.AGGREGATE_ROUTE_ENTRIES_ROUTE) is not None:
                for index_1 in range(
                        len(
                            self.properties.get(
                                self.AGGREGATE_ROUTE_ENTRIES,
                                {}).get(self.AGGREGATE_ROUTE_ENTRIES_ROUTE))):
                    obj_1.add_route(
                        self.properties.get(
                            self.AGGREGATE_ROUTE_ENTRIES, {}).get(
                                self.AGGREGATE_ROUTE_ENTRIES_ROUTE)[index_1])
            obj_0.set_aggregate_route_entries(obj_1)
        if self.properties.get(self.DISPLAY_NAME) is not None:
            obj_0.set_display_name(self.properties.get(self.DISPLAY_NAME))
        if self.properties.get(self.AGGREGATE_ROUTE_NEXTHOP) is not None:
            obj_0.set_aggregate_route_nexthop(
                self.properties.get(self.AGGREGATE_ROUTE_NEXTHOP))

        # 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)

        # reference to routing_instance_refs
        if self.properties.get(self.ROUTING_INSTANCE_REFS):
            for index_0 in range(
                    len(self.properties.get(self.ROUTING_INSTANCE_REFS))):
                try:
                    ref_obj = self.vnc_lib().routing_instance_read(
                        id=self.properties.get(
                            self.ROUTING_INSTANCE_REFS)[index_0])
                except vnc_api.NoIdError:
                    ref_obj = self.vnc_lib().routing_instance_read(
                        fq_name_str=self.properties.get(
                            self.ROUTING_INSTANCE_REFS)[index_0])
                obj_0.add_routing_instance(ref_obj)

        try:
            obj_uuid = super(ContrailRouteAggregate,
                             self).resource_create(obj_0)
        except:
            raise Exception(
                _('route-aggregate %s could not be updated.') % self.name)

        self.resource_id_set(obj_uuid)