Ejemplo n.º 1
0
 def device_send(self, job_template, job_input, is_delete, retry):
     config_str = json.dumps(job_input, sort_keys=True)
     self.push_config_state = PushConfigState.PUSH_STATE_IN_PROGRESS
     start_time = None
     config_size = 0
     forced_cfg_push = self.physical_router.forced_cfg_push
     try:
         config_size = len(config_str)
         current_config_hash = md5(config_str).hexdigest()
         if self.last_config_hash is None or (
                 current_config_hash != self.last_config_hash
                 or forced_cfg_push):
             self._logger.info(
                 "Config push for %s(%s) using job template %s, "
                 "forced_push %s" %
                 (self.physical_router.name, self.physical_router.uuid,
                  str(job_template), forced_cfg_push))
             self._logger.debug(
                 "Abstract config: %s" %
                 json.dumps(job_input, indent=4, sort_keys=True))
             device_manager = DeviceManager.get_instance()
             job_handler = JobHandler(
                 job_template, job_input, [self.physical_router.uuid],
                 device_manager.get_api_server_config(), self._logger,
                 device_manager._amqp_client,
                 self.physical_router.transaction_id,
                 self.physical_router.transaction_descr,
                 device_manager._args)
             self.commit_stats['total_commits_sent_since_up'] += 1
             start_time = time.time()
             job_handler.push(**device_manager.get_job_status_config())
             end_time = time.time()
             self.commit_stats['commit_status_message'] = 'success'
             self.commit_stats['last_commit_time'] = \
                 datetime.datetime.fromtimestamp(
                 end_time).strftime('%Y-%m-%d %H:%M:%S')
             self.commit_stats['last_commit_duration'] = str(end_time -
                                                             start_time)
             self.last_config_hash = current_config_hash
         else:
             self._logger.debug("not pushing since no config change"
                                " detected")
         self.push_config_state = PushConfigState.PUSH_STATE_SUCCESS
     except Exception as e:
         self._logger.error("Router %s: %s" %
                            (self.physical_router.management_ip, repr(e)))
         self._logger.error("Abstract config: %s" %
                            json.dumps(job_input, indent=4, sort_keys=True))
         self.commit_stats[
             'commit_status_message'] = 'failed to apply config,\
                                             router response: ' + e.message
         if start_time is not None:
             self.commit_stats['last_commit_time'] = \
                 datetime.datetime.fromtimestamp(
                 start_time).strftime('%Y-%m-%d %H:%M:%S')
             self.commit_stats['last_commit_duration'] = str(time.time() -
                                                             start_time)
         self.push_config_state = PushConfigState.PUSH_STATE_RETRY if retry\
             else PushConfigState.PUSH_STATE_FAILED
     return config_size
Ejemplo n.º 2
0
 def device_send(self, job_template, job_input, is_delete, retry):
     config_str = json.dumps(job_input, sort_keys=True)
     self.push_config_state = PushConfigState.PUSH_STATE_IN_PROGRESS
     start_time = None
     config_size = 0
     try:
         config_size = len(config_str)
         current_config_hash = md5(config_str).hexdigest()
         if self.last_config_hash is None or\
                 current_config_hash != self.last_config_hash:
             self._logger.info("Config push for %s(%s) using job template %s" %
                       (self.physical_router.name, self.physical_router.uuid,
                        str(job_template)))
             self._logger.debug("Abstract config: %s" %
                                json.dumps(job_input, indent=4,
                                           sort_keys=True))
             device_manager = DeviceManager.get_instance()
             job_handler = JobHandler(job_template, job_input,
                                      None if is_delete else
                                      [self.physical_router.uuid],
                                      device_manager.get_api_server_config(),
                                      self._logger,
                                      device_manager._amqp_client,
                                      device_manager._args)
             self.commit_stats['total_commits_sent_since_up'] += 1
             start_time = time.time()
             job_handler.push(**device_manager.get_job_status_config())
             end_time = time.time()
             self.commit_stats['commit_status_message'] = 'success'
             self.commit_stats['last_commit_time'] = \
                     datetime.datetime.fromtimestamp(
                     end_time).strftime('%Y-%m-%d %H:%M:%S')
             self.commit_stats['last_commit_duration'] = str(
                     end_time - start_time)
             self.last_config_hash = current_config_hash
         else:
             self._logger.debug("not pushing since no config change"
                                " detected")
         self.push_config_state = PushConfigState.PUSH_STATE_SUCCESS
     except Exception as e:
         self._logger.error("Router %s: %s" %
                            (self.physical_router.management_ip, repr(e)))
         self._logger.error("Abstract config: %s" %
                            json.dumps(job_input, indent=4,
                                       sort_keys=True))
         self.commit_stats[
                 'commit_status_message'] = 'failed to apply config,\
                                             router response: ' + e.message
         if start_time is not None:
             self.commit_stats['last_commit_time'] = \
                     datetime.datetime.fromtimestamp(
                         start_time).strftime('%Y-%m-%d %H:%M:%S')
             self.commit_stats['last_commit_duration'] = str(
                     time.time() - start_time)
         self.push_config_state = PushConfigState.PUSH_STATE_RETRY if retry\
             else PushConfigState.PUSH_STATE_FAILED
     return config_size
Ejemplo n.º 3
0
 def device_send(self, job_template, job_input, is_delete, retry):
     config_str = json.dumps(job_input, sort_keys=True)
     self.push_config_state = PushConfigState.PUSH_STATE_IN_PROGRESS
     start_time = None
     config_size = 0
     try:
         config_size = len(config_str)
         current_config_hash = md5(config_str).hexdigest()
         if self.last_config_hash is None or\
                 current_config_hash != self.last_config_hash:
             self._logger.info("config push for %s(%s) using job template %s" %
                       (self.physical_router.name, self.physical_router.uuid,
                        str(job_template)))
             self._logger.debug("playbook send message: %s" %
                                json.dumps(job_input, indent=4,
                                           sort_keys=True))
             device_manager = DeviceManager.get_instance()
             job_handler = JobHandler(job_template, job_input,
                                      None if is_delete else
                                      [self.physical_router.uuid],
                                      device_manager.get_analytics_config(),
                                      device_manager.get_vnc(), self._logger)
             self.commit_stats['total_commits_sent_since_up'] += 1
             start_time = time.time()
             job_handler.push()
             end_time = time.time()
             self.commit_stats['commit_status_message'] = 'success'
             self.commit_stats['last_commit_time'] = \
                     datetime.datetime.fromtimestamp(
                     end_time).strftime('%Y-%m-%d %H:%M:%S')
             self.commit_stats['last_commit_duration'] = str(
                     end_time - start_time)
             self.last_config_hash = current_config_hash
         else:
             self._logger.debug("not pushing since no config change"
                                " detected")
         self.push_config_state = PushConfigState.PUSH_STATE_SUCCESS
     except Exception as e:
         self._logger.error("Router %s: %s" %
                            (self.physical_router.management_ip, e.message))
         self.commit_stats[
                 'commit_status_message'] = 'failed to apply config,\
                                             router response: ' + e.message
         if start_time is not None:
             self.commit_stats['last_commit_time'] = \
                     datetime.datetime.fromtimestamp(
                         start_time).strftime('%Y-%m-%d %H:%M:%S')
             self.commit_stats['last_commit_duration'] = str(
                     time.time() - start_time)
         self.push_config_state = PushConfigState.PUSH_STATE_RETRY if retry\
             else PushConfigState.PUSH_STATE_FAILED
     return config_size
 def device_send(self, job_template, job_input, retry):
     config_str = json.dumps(job_input)
     self.push_config_state = PushConfigState.PUSH_STATE_INIT
     start_time = None
     config_size = 0
     try:
         self._logger.debug("playbook send message: %s" % config_str)
         config_size = len(config_str)
         device_manager = DeviceManager.get_instance()
         job_handler = JobHandler(job_template, job_input,
                                  [self.physical_router.uuid],
                                  device_manager.get_analytics_config(),
                                  device_manager.get_vnc(), self._logger)
         self.commit_stats['total_commits_sent_since_up'] += 1
         start_time = time.time()
         job_handler.push()
         end_time = time.time()
         self.commit_stats['commit_status_message'] = 'success'
         self.commit_stats['last_commit_time'] = \
                 datetime.datetime.fromtimestamp(
                 end_time).strftime('%Y-%m-%d %H:%M:%S')
         self.commit_stats['last_commit_duration'] = str(
                 end_time - start_time)
         self.push_config_state = PushConfigState.PUSH_STATE_SUCCESS
     except Exception as e:
         self._logger.error("Router %s: %s" %
                            (self.physical_router.management_ip, e.message))
         self.commit_stats[
                 'commit_status_message'] = 'failed to apply config,\
                                             router response: ' + e.message
         if start_time is not None:
             self.commit_stats['last_commit_time'] = \
                     datetime.datetime.fromtimestamp(
                         start_time).strftime('%Y-%m-%d %H:%M:%S')
             self.commit_stats['last_commit_duration'] = str(
                     time.time() - start_time)
         self.push_config_state = PushConfigState.PUSH_STATE_RETRY if retry\
             else PushConfigState.PUSH_STATE_FAILED
     return config_size
Ejemplo n.º 5
0
def sighup_handler():
    if DeviceManager.get_instance() is not None:
        DeviceManager.get_instance().sighup_handler()
Ejemplo n.º 6
0
def sighup_handler():
    if DeviceManager.get_instance() is not None:
        DeviceManager.get_instance().sighup_handler()