Skip to content

Commit

Permalink
[CE-220] Fix host reset operation
Browse files Browse the repository at this point in the history
Can reset host in admin dashboard
Add is_active function in DockerHost class

Change-Id: Ief4c6ab28be5305ecf42f2d7b69cdb6a4fe84b30
Signed-off-by: Haitao Yue <hightall@me.com>
  • Loading branch information
hightall committed Jan 10, 2018
1 parent b14ec7f commit 3e2e0a2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/agent/docker/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def __init__(self, host_type):
self.col = db["host"]
self.host_type = host_type

def is_active(self, *args):
return check_daemon(args[1])

def create(self, worker_api):
""" Create a new docker host node
Expand Down
10 changes: 5 additions & 5 deletions src/modules/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,11 @@ def reset(self, id):
"""
logger.debug("clean host with id = {}".format(id))
host = self.get_by_id(id)
if not host or ClusterModel.objects(host=host).count() > 0:
if not host or ClusterModel.objects(host=host).count() < 0:
logger.warning("No find resettable host with id ={}".format(id))
return False
return self.host_agents[host.type].reset(
host_type=host.type, worker_api=host.worker_api)
host_type = host.type
return self.host_agents[host_type].reset(host_type, host.worker_api)

def refresh_status(self, id):
"""
Expand All @@ -410,10 +410,10 @@ def refresh_status(self, id):
if not self.host_agents[host.type]\
.refresh_status(host.worker_api):
logger.warning("Host {} is inactive".format(id))
self.db_set_by_id(id, status="inactive")
self.db_set_by_id(id, **{"status": "inactive"})
return False
else:
self.db_set_by_id(id, status="active")
self.db_set_by_id(id, **{"status": "active"})
return True

def is_active(self, host_id):
Expand Down
9 changes: 9 additions & 0 deletions src/resources/host_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
request_debug

from modules import host_handler
from modules.models import Cluster as ClusterModel
from modules.models import Host as HostModel
from agent import detect_daemon_type

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -246,6 +248,13 @@ def host_actions():
elif action == "reset":
if host_handler.reset(host_id):
logger.debug("reset successfully")
try:
host_model = HostModel.objects.get(id=host_id)
clusters = ClusterModel.objects(host=host_model)
for cluster_item in clusters:
cluster_item.delete()
except Exception:
pass
return make_ok_resp()
else:
error_msg = "Failed to reset the host."
Expand Down

0 comments on commit 3e2e0a2

Please sign in to comment.