Commit 75ff941e by Őry Máté

update fabfile

parent 8cdbd55d
import contextlib import contextlib
import datetime import datetime
from fabric.api import env, run, settings, sudo, prefix, cd from fabric.api import env, run, settings, sudo, prefix, cd, execute
from fabric.decorators import roles from fabric.decorators import roles, parallel
from vm.models import Node from vm.models import Node
from storage.models import DataStore from storage.models import DataStore
def get_hosts(): env.roledefs['portal'] = ['localhost']
env.roledefs['portal'] = ['localhost'] env.roledefs['node'] = [unicode(n.host.ipv4)
env.roledefs['nodes'] = [unicode(n.host.ipv4)
for n in Node.objects.filter(enabled=True)] for n in Node.objects.filter(enabled=True)]
env.roledefs['storage'] = [DataStore.objects.get().hostname] env.roledefs['storage'] = [DataStore.objects.get().hostname]
print env.roledefs
def update_all(): def update_all():
update_node() execute(stop_portal)
update_portal() execute(update_node)
execute(update_portal)
@roles('portal') @roles('portal')
...@@ -94,12 +92,28 @@ def update_portal(test=False): ...@@ -94,12 +92,28 @@ def update_portal(test=False):
test() test()
@roles('portal')
def stop_portal(test=False):
_stop_services("portal", "mancelery")
@parallel
@roles('node') @roles('node')
def update_node(): def update_node():
"Update and restart nodes" "Update and restart nodes"
with _stopped("node", "agent"): with _stopped("node", "agent"):
pull("~/circle/vmdriver") pull("~/vmdriver")
pull("~/circle/agentdriver") pull("~/agentdriver")
@parallel
@roles('node')
def checkout(vmdriver="master", agent="master"):
"""Checkout specific branch on nodes"""
with settings(warn_only=True), cd("~/vmdriver"):
run("git checkout %s" % vmdriver)
with settings(warn_only=True), cd("~/agentdriver"):
run("git checkout %s" % agent)
def _stop_services(*services): def _stop_services(*services):
...@@ -122,7 +136,7 @@ def _restart_service(*services): ...@@ -122,7 +136,7 @@ def _restart_service(*services):
@contextlib.contextmanager @contextlib.contextmanager
def _stopped(*services): def _stopped(*services):
_stop_services(True, *services) _stop_services(*services)
yield yield
_start_services(*services) _start_services(*services)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment