]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
add a remote helper function to set priorities in ceph.repo
authorAlfredo Deza <alfredo.deza@inktank.com>
Fri, 6 Jun 2014 14:42:17 +0000 (10:42 -0400)
committerAlfredo Deza <alfredo.deza@inktank.com>
Fri, 6 Jun 2014 14:42:17 +0000 (10:42 -0400)
Signed-off-by: Alfredo Deza <alfredo.deza@inktank.com>
ceph_deploy/hosts/remotes.py

index e3f716a0f0f019be1b196742d81fffabbeac13be..b11f7c60f2698d96d857f6d365f95ea6f69e7dd1 100644 (file)
@@ -1,3 +1,4 @@
+import ConfigParser
 import errno
 import socket
 import os
@@ -56,6 +57,34 @@ def write_yum_repo(content, filename='ceph.repo'):
     write_file(repo_path, content)
 
 
+def set_repo_priority(sections, path='/etc/yum.repos.d/ceph.repo', priority='1'):
+    Config = ConfigParser.ConfigParser()
+    Config.read(path)
+    Config.sections()
+    for section in sections:
+        Config.set(section, 'priority', priority)
+
+    with open(path, 'wb') as fout:
+        Config.write(fout)
+
+    # And now, because ConfigParser is super duper, we need to remove the
+    # assignments so this looks like it was before
+    def remove_whitespace_from_assignments():
+        separator = "="
+        lines = file(path).readlines()
+        fp = open(path, "w")
+        for line in lines:
+            line = line.strip()
+            if not line.startswith("#") and separator in line:
+                assignment = line.split(separator, 1)
+                assignment = map(str.strip, assignment)
+                fp.write("%s%s%s\n" % (assignment[0], separator, assignment[1]))
+            else:
+                fp.write(line + "\n")
+
+    remove_whitespace_from_assignments()
+
+
 def write_conf(cluster, conf, overwrite):
     """ write cluster configuration to /etc/ceph/{cluster}.conf """
     path = '/etc/ceph/{cluster}.conf'.format(cluster=cluster)