Set active portal according to the name passed in 'portal_name'.

            Returns dictionary of device 'serial_number: rid'
484776
def get_portal_by_name(self, portal_name):
        
        portals = self.get_portals_list()

        for p in portals:
            # print("Checking {!r}".format(p))
            if portal_name == p[1]:
                # print("Found Portal!")
                self.set_portal_name( p[1] )
                self.set_portal_id( p[0] )
                self.set_portal_cik( p[2][1]['info']['key'] )
                # print("Active Portal Details:\nName: {0}\nId: {1}\nCIK: {2}".format(
                #                               self.portal_name(),
                #                               self.portal_id(),
                #                               self.portal_cik()))
                return p
        return None
30535
def set_ghost_status(self, ghost_status):
        

        yield from self._hypervisor.send('vm set_ghost_status "{name}" {ghost_status}'.format(name=self._name,
                                                                                              ghost_status=ghost_status))

        log.info('Router "{name}" [{id}]: ghost status set to {ghost_status}'.format(name=self._name,
                                                                                     id=self._id,
                                                                                     ghost_status=ghost_status))
        self._ghost_status = ghost_status
353062
def update_device(self, device_obj):
        
        rid = device_obj['rid']
        device_obj['info']['description']['meta'] = \
                json.dumps(device_obj['info']['description']['meta'])
        headers = {
                'User-Agent': self.user_agent(),
        }
        headers.update(self.headers())

        r = requests.put(   self.portals_url()+'/devices/'+rid, 
                            data=json.dumps(device_obj),
                            headers=headers,
                            auth=self.auth())
        if HTTP_STATUS.OK == r.status_code:
            # fix the 'meta' to be dictionary instead of string
            updated_dev_obj = r.json()
            updated_dev_obj['info']['description']['meta'] =\
                            json.loads(device_obj['info']['description']['meta'])
            return updated_dev_obj
        else:
            print("update_device: Something went wrong: <{0}>: {1}".format(
                        r.status_code, r.reason))
            r.raise_for_status()
602145
def make_storage_key(portal_type, prefix=None):
    
    key = portal_type.lower()
    if prefix:
        key = "{}-{}".format(key, prefix)
    return key
351537
def setActiveWindow(self, win):
        
        self._setProperty('_NET_ACTIVE_WINDOW', [1, X.CurrentTime, win.id],
                          win)
953130
def set_operation_mode(self, mode):
        
        if mode == "off":
            desired_state = {"powered": False}
        else:
            desired_state = {"powered": True, "mode": mode}

        response = self.api_interface.set_device_state(self, {
            "desired_state": desired_state
        })

        self._update_state_from_response(response)
215973
async def deactivate(cls, access_key: str) -> dict:
        '''
        
        '''
        q = 'mutation($access_key: String!, $input: ModifyKeyPairInput!) {' + \
            '  modify_keypair(access_key: $access_key, props: $input) {' \
            '    ok msg' \
            '  }' \
            '}'
        variables = {
            'access_key': access_key,
            'input': {
                'is_active': False,
                'is_admin': None,
                'resource_policy': None,
                'rate_limit': None,
            },
        }
        rqst = Request(cls.session, 'POST', '/admin/graphql')
        rqst.set_json({
            'query': q,
            'variables': variables,
        })
        async with rqst.fetch() as resp:
            data = await resp.json()
            return data['modify_keypair']
459295
def pick_unused_port():
  
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  s.bind(('localhost', 0))
  addr, port = s.getsockname()
  s.close()
  return port
989187
def map_aliases_to_device_objects(self):
        
        all_devices = self.get_all_devices_in_portal()
        for dev_o in all_devices:
            dev_o['portals_aliases'] = self.get_portal_by_name(
                                                        self.portal_name()
                                                )[2][1]['info']['aliases'][ dev_o['rid'] ]
        return all_devices
326604
def pick_free_port(hostname=REDIRECT_HOST, port=0):
    
    import socket
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        s.bind((hostname, port))  # port=0 finds an open port
    except OSError as e:
        log.warning("Could not bind to %s:%s %s", hostname, port, e)
        if port == 0:
            print('Unable to find an open port for authentication.')
            raise AuthenticationException(e)
        else:
            return pick_free_port(hostname, 0)
    addr, port = s.getsockname()
    s.close()
    return port
162867
def reset(self, method=None):
        
        self.logger.info('Reset serial device %s' % self.name)
        self.__send_break()
1322552
def refresh(self, url=CONST.PANEL_URL):
        """"""
        response_object = AbodeDevice.refresh(self, url)
        # pylint: disable=W0212
        self._abode._panel.update(response_object[0])

        return response_object
1310376
def get_by_name(self, name): # pylint: disable=invalid-name,redefined-builtin
        
        rs, _ = self.list(filter=field('name').eq(name), limit=1)
        if len(rs) is 0:
            raise CDRouterError('no such device')
        return rs[0]
1146725
def print_device_list(self, device_list=None):
        
        dev_list = device_list if device_list is not None else self.get_all_devices_in_portal()

        for dev in dev_list:
            print('{0}\t\t{1}\t\t{2}'.format(
                    dev['info']['description']['name'],
                    dev['sn'],
                    dev['portals_aliases']\
                        if len(dev['portals_aliases']) != 1
                        else dev['portals_aliases'][0]
                )
            )
122747
def _set_serial_console(self):
        

        pipe_name = self._get_pipe_name()
        serial_port = {"serial0.present": "TRUE",
                       "serial0.filetype": "pipe",
                       "serial0.filename": pipe_name,
                       "serial0.pipe.endpoint": "server",
                       "serial0.startconnected": "TRUE"}
        self._vmx_pairs.update(serial_port)
786392
def request_set_sensor_inactive(self, req, sensor_name):
        """"""
        sensor = self.get_sensor(sensor_name)
        ts, status, value = sensor.read()
        sensor.set_value(value, sensor.INACTIVE, ts)
        return('ok',)
917097
def active():
    '''
    
    '''
    ret = {}
    # TODO: This command should be extended to collect more information, such as UUID.
    devices = __salt__['cmd.run_stdout']('dmsetup ls --target crypt')
    out_regex = re.compile(r'(?P<devname>\w+)\W+\((?P<major>\d+), (?P<minor>\d+)\)')

    log.debug(devices)
    for line in devices.split('\n'):
        match = out_regex.match(line)
        if match:
            dev_info = match.groupdict()
            ret[dev_info['devname']] = dev_info
        else:
            log.warning('dmsetup output does not match expected format')

    return ret