Пример #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
Пример #2
0
 def delete(self, instance: Instance):
     self._database.remove(self._instances.name == instance.get_name())
Пример #3
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'}})
Пример #4
0
 def update(self, instance: Instance):
     self._database.update(instance.to_dict(), self._instances.name == instance.get_name())
Пример #5
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())