def get_link(ctx, link_id, scenario_id): """ Get a link using the link_id. optionally, scenario_id can be included if data is to be included Args: link_id (int): The link to retrieve scenario_id (int) (optional): Include this if you want to include data with the scenario Returns: hydra_complexmodels.Link: A link complex model, with attributes and data if requested) Raises: ResourceNotFoundError: If the link or scenario is not found """ link = network.get_link(link_id, **ctx.in_header.__dict__) if scenario_id is not None: ret_link = Link(link) res_scens = scenario.get_resource_data('LINK', link_id, scenario_id, None) rs_dict = {} for rs in res_scens: rs_dict[rs.resource_attr_id] = rs for ra in ret_link.attributes: if rs_dict.get(ra.id): ra.resourcescenario = ResourceScenario(rs_dict[ra.id]) return ret_link else: ret_link = Link(link) return ret_link
def get_resourcegroup(ctx, group_id, scenario_id): """ Get a resourcegroup using the group_id. optionally, scenario_id can be included if data is to be included Args: group_id (int): The resource group to retrieve scenario_id (int) (optional): Include this if you want to include data with the scenario Returns: hydra_complexmodels.ResourceGroup: A resource group complex model, with attributes and data if requested) Raises: ResourceNotFoundError: If the group or scenario is not found """ group = network.get_resourcegroup(group_id, **ctx.in_header.__dict__) if scenario_id is not None: ret_group = ResourceGroup(group) res_scens = scenario.get_resource_data('GROUP', group_id, scenario_id, None) rs_dict = {} for rs in res_scens: rs_dict[rs.resource_attr_id] = rs for ra in ret_group.attributes: if rs_dict.get(ra.id): ra.resourcescenario = ResourceScenario(rs_dict[ra.id]) return ret_group else: ret_group = ResourceGroup(group) return ret_group
def get_resourcegroup_data(ctx, resourcegroup_id, scenario_id, type_id): """ Get all the resource scenarios for a given resourcegroup in a given scenario. If type_id is specified, only return the resource scenarios for the attributes within the type. """ group_data = scenario.get_resource_data('GROUP', resourcegroup_id, scenario_id, type_id, **ctx.in_header.__dict__) ret_data = [ResourceScenario(rs) for rs in group_data] return ret_data
def get_network_data(ctx, network_id, scenario_id, type_id): """ Get all the resource scenarios for a given network in a given scenario. If type_id is specified, only return the resource scenarios for the attributes within the type. """ network_data = scenario.get_resource_data('NETWORK', network_id, scenario_id, type_id, **ctx.in_header.__dict__) ret_data = [ResourceScenario(rs) for rs in network_data] return ret_data
def get_resourcegroup_data(ctx, resourcegroup_id, scenario_id, type_id): """ Get all the resource scenarios for a given resourcegroup in a given scenario. If type_id is specified, only return the resource scenarios for the attributes within the type. """ group_data = scenario.get_resource_data('GROUP', resourcegroup_id, scenario_id, type_id, **ctx.in_header.__dict__) ret_data = [ResourceScenario(rs) for rs in group_data] return ret_data
def get_network_data(ctx, network_id, scenario_id, type_id): """ Get all the resource scenarios for a given network in a given scenario. If type_id is specified, only return the resource scenarios for the attributes within the type. """ network_data = scenario.get_resource_data('NETWORK', network_id, scenario_id, type_id, **ctx.in_header.__dict__) ret_data = [ResourceScenario(rs) for rs in network_data] return ret_data
def get_nodes(ctx, node_ids, scenario_id): """ Get nodes using the node_ids. optionally, scenario_id can be included if data is to be included Args: node_id (int): The node to retrieve scenario_id (int) (optional): Include this if you want to include data with the scenario Returns: hydra_complexmodels.Node: A node complex model, with attributes and data if requested) Raises: ResourceNotFoundError: If the node or scenario is not found """ nodes = network.get_nodes(node_ids, **ctx.in_header.__dict__) ret_nodes = [] if scenario_id is not None: for node in nodes: ret_node = Node(node) res_scens = scenario.get_resource_data('NODE', node.node_id, scenario_id, None) rs_dict = {} for rs in res_scens: rs_dict[rs.resource_attr_id] = rs for ra in ret_node.attributes: if rs_dict.get(ra.id): ra.resourcescenario = ResourceScenario(rs_dict[ra.id]) ret_nodes.append(ret_node) else: ret_nodes = [Node(node) for node in nodes] return ret_nodes