def assign_hosting_device_to_cfg_agent(self, context, cfg_agent_id,<EOL>hosting_device_id):
hd_db = self._get_hosting_device(context, hosting_device_id)<EOL>if hd_db.cfg_agent_id:<EOL><INDENT>if hd_db.cfg_agent_id == cfg_agent_id:<EOL><INDENT>return<EOL><DEDENT>LOG.debug('<STR_LIT>'<EOL>'<STR_LIT>',<EOL>{'<STR_LIT>': hosting_device_id, '<STR_LIT>': cfg_agent_id})<EOL>raise ciscocfgagentscheduler.HostingDeviceAssignedToCfgAgent(<EOL>hosting_device_id=hosting_device_id, agent_id=cfg_agent_id)<EOL><DEDENT>cfg_agent_db = get_agent_db_obj(self._get_agent(context, cfg_agent_id))<EOL>if (cfg_agent_db.agent_type != c_constants.AGENT_TYPE_CFG or<EOL>cfg_agent_db.admin_state_up is not True):<EOL><INDENT>raise ciscocfgagentscheduler.InvalidCfgAgent(agent_id=cfg_agent_id)<EOL><DEDENT>self._bind_hosting_device_to_cfg_agent(context, hd_db, cfg_agent_db)<EOL>cfg_notifier = self.agent_notifiers.get(c_constants.AGENT_TYPE_CFG)<EOL>if cfg_notifier:<EOL><INDENT>cfg_notifier.hosting_devices_assigned_to_cfg_agent(<EOL>context, [hosting_device_id], cfg_agent_db.host)<EOL><DEDENT>
Make config agent handle an (unassigned) hosting device.