def _prepare(self): self.logger.info('Target device %s waiting for ip', self) self._state_transition(_STATE.WAITING, _STATE.INIT) self.record_result('sanity', state=MODE.DONE) self.record_result('acquire', state=MODE.EXEC) static_ip = self._get_static_ip() if static_ip: self.logger.info('Target device %s using static ip', self) self.device.dhcp_mode = DhcpMode.STATIC_IP time.sleep(self._STARTUP_MIN_TIME_SEC) self.runner.ip_notify( MODE.NOPE, { 'type': 'STATIC', 'mac': self.target_mac, 'ip': static_ip, 'delta': -1 }, self.gateway) else: if not self.device.dhcp_mode: dhcp_mode = self._get_dhcp_mode() self.device.dhcp_mode = dhcp_mode # enables dhcp response for this device wait_time = self.runner.config.get("long_dhcp_response_sec") \ if self.device.dhcp_mode == DhcpMode.LONG_RESPONSE else 0 self.logger.info('Target device %s using %s DHCP mode, wait %s', self, DhcpMode.Name(self.device.dhcp_mode), wait_time) if self.device.dhcp_mode != DhcpMode.EXTERNAL: self.gateway.change_dhcp_response_time(self.target_mac, wait_time) _ = [listener(self.device) for listener in self._dhcp_listeners]
def _get_env_vars(self, params): def opt_param(key): return params.get(key) or '' # Substitute empty string for None dhcp_mode = DhcpMode.Name( self.device.dhcp_mode) if self.device.dhcp_mode else '' env_vars = [("TARGET_NAME", self.host_name), ("TARGET_IP", params['target_ip']), ("TARGET_MAC", params['target_mac']), ("TARGET_PORT", opt_param('target_port')), ("GATEWAY_IP", params['gateway_ip']), ("GATEWAY_MAC", params['gateway_mac']), ("LOCAL_IP", opt_param('local_ip')), ("DHCP_MODE", dhcp_mode)] return env_vars