Esempio n. 1
0
    def dispatch(self, instance: Instance):
        if instance.get_enabled():
            instance_running = self._command.is_running(instance)
            just_enabled = self._property_changed('enabled', instance)

            if just_enabled or not instance_running:
                self._foreman.run(instance)

            if not just_enabled and not instance_running:
                raise StartedBecauseShouldBeRunning(
                    "Instance {0} started because not running on {1}".format(instance.get_name(),
                                                                             instance.get_host()))
        else:
            self._foreman.stop(instance)

        return instance
Esempio n. 2
0
 def is_running(self, instance: Instance):
     host = self._hosts.find_one_by_name(instance.get_host())
     return self._container_exist(host, instance.get_name(), {'filters': {'status': 'running'}})
Esempio n. 3
0
 def exist(self, instance: Instance):
     instance_name = instance.get_name()
     if not instance_name:
         return False
     host = self._hosts.find_one_by_name(instance.get_host())
     return self._container_exist(host, instance.get_name())