def get_resources(cls): my_plurals = [] for plural in RESOURCE_ATTRIBUTE_MAP: singular = plural[:-1] my_plurals.append((plural, singular)) attr.PLURALS.update(dict(my_plurals)) resources = [] plugin = manager.CrdManager.get_service_plugins()[ constants.LOADBALANCER] for collection_name in RESOURCE_ATTRIBUTE_MAP: resource_name = collection_name[:-1] params = RESOURCE_ATTRIBUTE_MAP[collection_name] member_actions = {} if resource_name == 'pool': member_actions = {'stats': 'GET'} controller = base.create_resource( collection_name, resource_name, plugin, params, member_actions=member_actions, allow_pagination=cfg.CONF.allow_pagination, allow_sorting=cfg.CONF.allow_sorting) resource = extensions.ResourceExtension( collection_name, controller, path_prefix=constants.COMMON_PREFIXES[constants.LOADBALANCER], member_actions=member_actions, attr_map=params) resources.append(resource) ###For multi level URL's for collection_name in SUB_RESOURCE_ATTRIBUTE_MAP: # Special handling needed for sub-resources with 'y' ending # (e.g. proxies -> proxy) resource_name = collection_name[:-1] parent = SUB_RESOURCE_ATTRIBUTE_MAP[collection_name].get('parent') params = SUB_RESOURCE_ATTRIBUTE_MAP[collection_name].get( 'parameters') controller = base.create_resource(collection_name, resource_name, plugin, params, allow_bulk=True, parent=parent) resource = extensions.ResourceExtension( collection_name, controller, parent, path_prefix=constants.COMMON_PREFIXES[constants.LOADBALANCER], attr_map=params) resources.append(resource) return resources
def get_resources(cls): resources = [] plugin = manager.CrdManager.get_plugin() for collection_name in RESOURCE_ATTRIBUTE_MAP: resource_name = DUMMY_PLURALS[collection_name] parents = None path_prefix="" parent = None if RESOURCE_ATTRIBUTE_MAP[collection_name].has_key('parameters'): params = RESOURCE_ATTRIBUTE_MAP[collection_name].get('parameters') parent = RESOURCE_ATTRIBUTE_MAP[collection_name].get('parent') parents = [] path_prefix=[] def generate_parent(parent_attr): parents.append(parent_attr) if parent_attr != parent: path_prefix.insert(0,"/%s/{%s_id}" % (parent_attr['collection_name'],parent_attr['member_name'])) if RESOURCE_ATTRIBUTE_MAP[parent_attr['collection_name']].has_key('parent'): generate_parent(RESOURCE_ATTRIBUTE_MAP[parent_attr['collection_name']].get('parent')) generate_parent(parent) path_prefix= ''.join(path_prefix) else : params = RESOURCE_ATTRIBUTE_MAP[collection_name] member_actions = {} controller = base.create_resource(collection_name, resource_name, plugin, params, member_actions=member_actions, parent=parents) resource = extensions.ResourceExtension( collection_name, controller, parent=parent, path_prefix=path_prefix, member_actions=member_actions, attr_map=params) resources.append(resource) return resources #def get_resources(cls): # """Returns Extended Resource for dummy management.""" # dummy_inst = manager.CrdManager.get_plugin() # controller = base.create_resource( # COLLECTION_NAME, RESOURCE_NAME, dummy_inst, # RESOURCE_ATTRIBUTE_MAP[COLLECTION_NAME]) # return [extensions.ResourceExtension(COLLECTION_NAME, # controller)]
def get_resources(cls): """Returns Ext Resources.""" my_plurals = [(key, key[:-1]) for key in RESOURCE_ATTRIBUTE_MAP.keys()] attr.PLURALS.update(dict(my_plurals)) plugin = manager.CrdManager.get_plugin() params = RESOURCE_ATTRIBUTE_MAP.get(RESOURCE_NAME + 's') controller = base.create_resource(RESOURCE_NAME + 's', RESOURCE_NAME, plugin, params ) ex = extensions.ResourceExtension(RESOURCE_NAME + 's', controller) return [ex]
def get_resources(cls): resources = [] plugin = manager.CrdManager.get_service_plugins()[NOVASERVICE] for collection_name in RESOURCE_ATTRIBUTE_MAP: resource_name = OVS_PLURALS[collection_name] parents = None path_prefix = "" parent = None if RESOURCE_ATTRIBUTE_MAP[collection_name].has_key("parameters"): params = RESOURCE_ATTRIBUTE_MAP[collection_name].get("parameters") parent = RESOURCE_ATTRIBUTE_MAP[collection_name].get("parent") parents = [] path_prefix = [] def generate_parent(parent_attr): parents.append(parent_attr) if parent_attr != parent: path_prefix.insert( 0, "/%s/{%s_id}" % (parent_attr["collection_name"], parent_attr["member_name"]) ) if RESOURCE_ATTRIBUTE_MAP[parent_attr["collection_name"]].has_key("parent"): generate_parent(RESOURCE_ATTRIBUTE_MAP[parent_attr["collection_name"]].get("parent")) generate_parent(parent) path_prefix = "".join(path_prefix) else: params = RESOURCE_ATTRIBUTE_MAP[collection_name] member_actions = {} controller = base.create_resource( collection_name, resource_name, plugin, params, member_actions=member_actions, parent=parents ) resource = extensions.ResourceExtension( collection_name, controller, parent=parent, path_prefix=path_prefix, member_actions=member_actions, attr_map=params, ) resources.append(resource) return resources
def _map_resource(collection, resource, params, parent=None): allow_bulk = cfg.CONF.allow_bulk allow_pagination = cfg.CONF.allow_pagination allow_sorting = cfg.CONF.allow_sorting controller = base.create_resource( collection, resource, plugin, params, allow_bulk=allow_bulk, parent=parent, allow_pagination=allow_pagination, allow_sorting=allow_sorting) path_prefix = None if parent: path_prefix = "/%s/{%s_id}/%s" % (parent['collection_name'], parent['member_name'], collection) mapper_kwargs = dict(controller=controller, requirements=REQUIREMENTS, path_prefix=path_prefix, **col_kwargs) return mapper.collection(collection, resource, **mapper_kwargs)
def get_resources(cls): my_plurals = [] for plural in RESOURCE_ATTRIBUTE_MAP: if plural == 'firewall_policies': singular = 'firewall_policy' else: singular = plural[:-1] my_plurals.append((plural, singular)) attr.PLURALS.update(dict(my_plurals)) resources = [] plugin = manager.CrdManager.get_service_plugins()[ constants.FIREWALL] for collection_name in RESOURCE_ATTRIBUTE_MAP: # Special handling needed for resources with 'y' ending if collection_name == 'firewall_policies': resource_name = 'firewall_policy' else: resource_name = collection_name[:-1] params = RESOURCE_ATTRIBUTE_MAP[collection_name] member_actions = {} if resource_name == 'firewall_policy': member_actions = {'insert_rule': 'PUT', 'remove_rule': 'PUT'} controller = base.create_resource( collection_name, resource_name, plugin, params, member_actions=member_actions, allow_pagination=cfg.CONF.allow_pagination, allow_sorting=cfg.CONF.allow_sorting) resource = extensions.ResourceExtension( collection_name, controller, path_prefix=constants.COMMON_PREFIXES[constants.FIREWALL], member_actions=member_actions, attr_map=params) resources.append(resource) return resources
def get_resources(cls): attr.PLURALS.update(SFC_PLURALS) resources = [] plugin = manager.CrdManager.get_service_plugins()[constants.SFC] for collection_name in RESOURCE_ATTRIBUTE_MAP: #resource_name = collection_name[:-1] resource_name = SFC_PLURALS[collection_name] parents = None path_prefix = None parent = None if 'parameters' in RESOURCE_ATTRIBUTE_MAP[collection_name]: params = RESOURCE_ATTRIBUTE_MAP[collection_name].get( 'parameters') parent = RESOURCE_ATTRIBUTE_MAP[collection_name].get('parent') parents = [] path_prefix = [] def generate_parent(parent_attr): parents.append(parent_attr) if parent_attr != parent: path_prefix.insert(0, "/%s/{%s_id}" % (parent_attr['collection_name'], parent_attr['member_name'])) if RESOURCE_ATTRIBUTE_MAP[parent_attr['collection_name']].has_key('parent'): generate_parent(RESOURCE_ATTRIBUTE_MAP[parent_attr['collection_name']].get('parent')) generate_parent(parent) path_prefix = constants.COMMON_PREFIXES[constants.SFC] + \ ''.join(path_prefix) else: params = RESOURCE_ATTRIBUTE_MAP[collection_name] path_prefix = constants.COMMON_PREFIXES[constants.SFC] member_actions = {} controller = base.create_resource(collection_name, resource_name, plugin, params, member_actions=member_actions, parent=parents) resource = extensions.ResourceExtension( collection_name, controller, parent=parent, path_prefix=path_prefix, member_actions=member_actions, attr_map=params) resources.append(resource) TMP_RESOURCE_ATTRIBUTE_MAP = RESOURCE_ATTRIBUTE_MAP.copy() TMP_RESOURCE_ATTRIBUTE_MAP.update(SUB_RESOURCE_ATTRIBUTE_MAP) for collection_name in SUB_RESOURCE_ATTRIBUTE_MAP: resource_name = SFC_SUB_PLURALS[collection_name] parents = None path_prefix = None parent = None if 'parameters' in TMP_RESOURCE_ATTRIBUTE_MAP[collection_name]: params = TMP_RESOURCE_ATTRIBUTE_MAP[collection_name].get( 'parameters') parent = TMP_RESOURCE_ATTRIBUTE_MAP[collection_name].get( 'parent') parents = [] path_prefix = [] def generate_parent(parent_attr): parents.append(parent_attr) if parent_attr != parent: path_prefix.insert(0, "/%s/{%s_id}" % ( parent_attr['collection_name'], parent_attr['member_name'])) if 'parent' in TMP_RESOURCE_ATTRIBUTE_MAP[parent_attr[ 'collection_name']]: generate_parent(TMP_RESOURCE_ATTRIBUTE_MAP[parent_attr[ 'collection_name']].get('parent')) generate_parent(parent) path_prefix = constants.COMMON_PREFIXES[constants.SFC] + \ ''.join(path_prefix) else: params = TMP_RESOURCE_ATTRIBUTE_MAP[collection_name] path_prefix = constants.COMMON_PREFIXES[constants.SFC] member_actions = {} controller = base.create_resource(collection_name, resource_name, plugin, params, member_actions=member_actions, parent=parents) resource = extensions.ResourceExtension( collection_name, controller, parent=parent, path_prefix=path_prefix, member_actions=member_actions, attr_map=params) resources.append(resource) return resources