summaryrefslogtreecommitdiff
path: root/fabfile
diff options
context:
space:
mode:
authorLeif Johansson <leifj@sunet.se>2014-02-22 21:43:18 +0100
committerLeif Johansson <leifj@sunet.se>2014-02-22 21:43:18 +0100
commit31772848b3dfcf53971ae1a98020e1ff8875aa90 (patch)
tree623e644e57cec8d6956fe692ea22b69f5db77f59 /fabfile
parent67337f5c7cba477b9e4a37d0e85ca5b0e7426f65 (diff)
parent9b801d3be8e0268994169729cf5d5dd4600367cb (diff)
merged pull-request
Diffstat (limited to 'fabfile')
-rw-r--r--fabfile/__init__.py36
-rw-r--r--fabfile/db.py45
2 files changed, 54 insertions, 27 deletions
diff --git a/fabfile/__init__.py b/fabfile/__init__.py
index caf123f..d87fbdd 100644
--- a/fabfile/__init__.py
+++ b/fabfile/__init__.py
@@ -1,44 +1,23 @@
from fabric.api import run,env
-from fabric.operations import get
+from fabric.operations import get,put
import os
import yaml
import re
-
-def _all_hosts():
- return filter(lambda fn: '.' in fn and not fn.startswith('.') and os.path.isdir(fn),os.listdir("."))
-
-def _roledefs():
- rules = dict()
-
- rules_file = "cosmos-rules.yaml";
- if os.path.exists(rules_file):
- with open(rules_file) as fd:
- rules.update(yaml.load(fd))
-
- roles = dict()
- for node_name in _all_hosts():
- for reg,cls in rules.iteritems():
- if re.search(reg,node_name):
- for cls_name in cls.keys():
- h = roles.get(cls_name,[])
- h.append(node_name)
- roles[cls_name] = h
- return roles
+import sys
+from fabfile.db import cosmos_db
env.user = 'root'
env.timeout = 30
env.connection_attempts = 3
env.warn_only = True
env.skip_bad_hosts = True
-env.roledefs = _roledefs()
-
-#print repr(env.roledefs)
+env.roledefs = cosmos_db()['members']
def all():
- env.hosts = _all_hosts()
+ env.hosts = cosmos_db()['members']['all']
def cosmos():
- run("cosmos update && cosmos apply");
+ run("cosmos update ; cosmos -v apply");
def upgrade():
run("apt-get -qq update && apt-get -y -q dist-upgrade");
@@ -51,3 +30,6 @@ def chassis():
def newvm(fqdn,ip,domain):
run("vmbuilder kvm ubuntu --domain %s --dest /var/lib/libvirt/images/%s.img --arch x86_64 --hostname %s --mem 512 --ip %s --addpkg openssh-server" % (domain,fqdn,fqdn,ip))
+
+def cp(local,remote):
+ put(local,remote)
diff --git a/fabfile/db.py b/fabfile/db.py
new file mode 100644
index 0000000..129aa50
--- /dev/null
+++ b/fabfile/db.py
@@ -0,0 +1,45 @@
+import os
+import yaml
+import re
+
+def _all_hosts():
+ return filter(lambda fn: '.' in fn and not fn.startswith('.') and os.path.isdir(fn),os.listdir("."))
+
+def _load_db():
+ rules = dict()
+ rules_file = "cosmos-rules.yaml";
+ if os.path.exists(rules_file):
+ with open(rules_file) as fd:
+ rules.update(yaml.load(fd))
+
+ all_hosts = _all_hosts()
+
+ members = dict()
+ for node_name in all_hosts:
+ for reg,cls in rules.iteritems():
+ if re.search(reg,node_name):
+ for cls_name in cls.keys():
+ h = members.get(cls_name,[])
+ h.append(node_name)
+ members[cls_name] = h
+ members['all'] = all_hosts
+
+ classes = dict()
+ for node_name in all_hosts:
+ node_classes = dict()
+ for reg,cls in rules.iteritems():
+ if re.search(reg,node_name):
+ node_classes.update(cls)
+ classes[node_name] = node_classes
+
+ return dict(classes=classes,members=members)
+
+_db = None
+def cosmos_db():
+ global _db
+ if _db is None:
+ _db = _load_db()
+ return _db
+
+if __name__ == '__main__':
+ print yaml.dump(cosmos_db())