Get all the resource scenarios in a network, across all scenarios
        returns a dictionary of dict objects, keyed on scenario_id
773318
def _get_all_resourcescenarios(network_id, user_id):
    

    rs_qry = db.DBSession.query(
                Dataset.type,
                Dataset.unit_id,
                Dataset.name,
                Dataset.hash,
                Dataset.cr_date,
                Dataset.created_by,
                Dataset.hidden,
                Dataset.value,
                ResourceScenario.dataset_id,
                ResourceScenario.scenario_id,
                ResourceScenario.resource_attr_id,
                ResourceScenario.source,
                ResourceAttr.attr_id,
    ).outerjoin(DatasetOwner, and_(DatasetOwner.dataset_id==Dataset.id, DatasetOwner.user_id==user_id)).filter(
                or_(Dataset.hidden=='N', Dataset.created_by==user_id, DatasetOwner.user_id != None),
                ResourceAttr.id == ResourceScenario.resource_attr_id,
                Scenario.id==ResourceScenario.scenario_id,
                Scenario.network_id==network_id,
                Dataset.id==ResourceScenario.dataset_id)

    x = time.time()
    logging.info("Getting all resource scenarios")
    all_rs = db.DBSession.execute(rs_qry.statement).fetchall()
    log.info("%s resource scenarios retrieved in %s", len(all_rs), time.time()-x)


    logging.info("resource scenarios retrieved. Processing results...")
    x = time.time()
    rs_dict = dict()
    for rs in all_rs:
        rs_obj = JSONObject(rs)
        rs_attr = JSONObject({'attr_id':rs.attr_id})

        value = rs.value

        rs_dataset = JSONDataset({
            'id':rs.dataset_id,
            'type' : rs.type,
            'unit_id' : rs.unit_id,
            'name' : rs.name,
            'hash' : rs.hash,
            'cr_date':rs.cr_date,
            'created_by':rs.created_by,
            'hidden':rs.hidden,
            'value':value,
            'metadata':{},
        })
        rs_obj.resourceattr = rs_attr
        rs_obj.value = rs_dataset
        rs_obj.dataset = rs_dataset

        scenario_rs = rs_dict.get(rs.scenario_id, [])
        scenario_rs.append(rs_obj)
        rs_dict[rs.scenario_id] = scenario_rs

    logging.info("resource scenarios processed in %s", time.time()-x)

    return rs_dict
1276111
def interfaces(self):
        
        if not self._interfaces_cache:
            response = yield from self.get("/network/interfaces")
            self._interfaces_cache = response.json
        return self._interfaces_cache
800863
def _get_links(network_id, template_id=None):
    
    extras = {'types':[], 'attributes':[]}
    link_qry = db.DBSession.query(Link).filter(
                                        Link.network_id==network_id,
                                        Link.status=='A').options(
                                            noload('network')
                                        )
    if template_id is not None:
        link_qry = link_qry.filter(ResourceType.link_id==Link.id,
                                   TemplateType.id==ResourceType.type_id,
                                   TemplateType.template_id==template_id)

    link_res = db.DBSession.execute(link_qry.statement).fetchall()

    links = []
    for l in link_res:
        links.append(JSONObject(l, extras=extras))

    return links
1294575
def retrieve_net(wrnt_path):
    '''
    '''
    # Exception Handling of  wrong format.
    if wrnt_path[-4:] != __WRNT_FORMAT: raise Exception(__WRNG_FORMAT_MSG)
    
    file = open(wrnt_path,'rb')
    # retrieving a network  from .wrnt file.
    network = pickle.load(file)
    file.close()
    # Generating Word() instance dictionary from retrieved network.
    word_net = {}
    for n in network:
        word_net[n[0]] = Word(n[0],None,set([network[i][0] for i in n[1:]]))
    # deleting useless resources, for efficient memory usage.
    del network
    return word_net
676307
def get_matching_resource_types(resource_type, resource_id,**kwargs):
    
    resource_i = None
    if resource_type == 'NETWORK':
        resource_i = db.DBSession.query(Network).filter(Network.id==resource_id).one()
    elif resource_type == 'NODE':
        resource_i = db.DBSession.query(Node).filter(Node.id==resource_id).one()
    elif resource_type == 'LINK':
        resource_i = db.DBSession.query(Link).filter(Link.id==resource_id).one()
    elif resource_type == 'GROUP':
        resource_i = db.DBSession.query(ResourceGroup).filter(ResourceGroup.id==resource_id).one()

    matching_types = get_types_by_attr(resource_i)
    return matching_types
1004638
def get_scenario(scenario_id,**kwargs):
    

    user_id = kwargs.get('user_id')

    scen_i = _get_scenario(scenario_id, user_id)

    scen_j = JSONObject(scen_i)
    rscen_rs = db.DBSession.query(ResourceScenario).filter(ResourceScenario.scenario_id==scenario_id).options(joinedload_all('dataset.metadata')).all()

    #lazy load resource attributes and attributes
    for rs in rscen_rs:
        rs.resourceattr
        rs.resourceattr.attr

    rgi_rs = db.DBSession.query(ResourceGroupItem).filter(ResourceGroupItem.scenario_id==scenario_id).all()

    scen_j.resourcescenarios = []
    for rs in rscen_rs:
        rs_j = JSONObject(rs, extras={'resourceattr':JSONObject(rs.resourceattr)})
        if rs.dataset.check_read_permission(user_id, do_raise=False) is False:
            rs_j.dataset['value'] = None
            rs_j.dataset.metadata = JSONObject({})
        scen_j.resourcescenarios.append(rs_j)

    scen_j.resourcegroupitems =[JSONObject(r) for r in rgi_rs]

    return scen_j
890900
def _to_enos_networks(networks):
    
    nets = []
    for roles, network in networks:
        nets.append(network.to_enos(roles))
    logger.debug(nets)
    return nets
1255341
def list_networks(self, org, part):
        
        if org and part:
            list_url = self._del_part + '/networks'
            list_url = list_url % (org, part)
            res = self._send_request('GET', list_url, '', 'networks')
            if res and res.status_code in self._resp_ok:
                return res.json()
463160
def get_networks(self, contents):
        
        schema = NetworksSchema()
        resp = self.service.post(self.base,
                                 params={'process': 'networks'}, json={'contents': contents})
        return self.service.decode(schema, resp)
1358345
def list_networks(self, retrieve_all=True, **_params):
        """"""
        # Pass filters in "params" argument to do_request
        return self.list('networks', self.networks_path, retrieve_all,
                         **_params)
26725
def get_resources(cls):
        """"""
        exts = []
        parent = dict(member_name=ciscohostingdevicemanager.DEVICE,
                      collection_name=ciscohostingdevicemanager.DEVICES)
        controller = resource.Resource(
            RouterHostingDeviceSchedulerController(), cb_faults.FAULT_MAP)
        exts.append(extensions.ResourceExtension(
            DEVICE_L3_ROUTERS, controller, parent, path_prefix="/dev_mgr"))
        parent = dict(member_name="router",
                      collection_name=l3_const.ROUTERS)
        controller = resource.Resource(
            HostingDevicesHostingRouterController(), cb_faults.FAULT_MAP)
        exts.append(extensions.ResourceExtension(L3_ROUTER_DEVICES, controller,
                                                 parent))
        return exts
1292886
def get_scenario_data(scenario_id,**kwargs):
    
    user_id = kwargs.get('user_id')

    scenario_data = db.DBSession.query(Dataset).filter(Dataset.id==ResourceScenario.dataset_id, ResourceScenario.scenario_id==scenario_id).options(joinedload_all('metadata')).distinct().all()

    for sd in scenario_data:
       if sd.hidden == 'Y':
           try:
                sd.check_read_permission(user_id)
           except:
               sd.value      = None
               sd.metadata = []

    db.DBSession.expunge_all()

    log.info("Retrieved %s datasets", len(scenario_data))
    return scenario_data
75684
def bulk_update_resourcedata(scenario_ids, resource_scenarios,**kwargs):
    
    user_id = kwargs.get('user_id')
    res = None

    res = {}

    net_ids = db.DBSession.query(Scenario.network_id).filter(Scenario.id.in_(scenario_ids)).all()

    if len(set(net_ids)) != 1:
        raise HydraError("Scenario IDS are not in the same network")

    for scenario_id in scenario_ids:
        _check_can_edit_scenario(scenario_id, kwargs['user_id'])

        scen_i = _get_scenario(scenario_id, user_id)
        res[scenario_id] = []

        for rs in resource_scenarios:
            if rs.dataset is not None:
                updated_rs = _update_resourcescenario(scen_i, rs, user_id=user_id, source=kwargs.get('app_name'))
                res[scenario_id].append(updated_rs)
            else:
                _delete_resourcescenario(scenario_id, rs.resource_attr_id)

        db.DBSession.flush()

    return res
663918
def get_network(self):
        
        props = self.get_chain_properties()
        chain_id = props["chain_id"]
        for k, v in known_chains.items():
            if v["chain_id"] == chain_id:
                return v
        raise Exception("Connecting to unknown network!")
888318
def get_all_incomings(self, params=None):
        
        if not params:
            params = {}
        return self._iterate_through_pages(self.get_incomings_per_page, resource=INCOMINGS, **{'params': params})
67645
def getall(self):
        
        users = self.users_re.findall(self.config, re.M)
        resources = dict()
        for user in users:
            resources.update(self._parse_username(user))
        return resources
714005
def networks(self, role="all", full="all"):
        """"""
        if full not in ["all", True, False]:
            raise ValueError(
                "full must be boolean or all, it cannot be {}".format(full)
            )

        if full == "all":
            if role == "all":
                return Network.query.all()
            else:
                return Network.query.filter_by(role=role).all()
        else:
            if role == "all":
                return Network.query.filter_by(full=full).all()
            else:
                return Network.query.filter(
                    and_(Network.role == role, Network.full == full)
                ).all()