Revision 3bae85da

b/snf-deploy/snfdeploy/__init__.py
13 13
import imp
14 14
import ast
15 15
from snfdeploy.lib import *
16
from snfdeploy import fabfile
17
from fabric.api import hide, env, settings, local, roles, execute, show
16 18

  
17 19
def print_available_actions(command):
18 20

  
......
243 245
    "everything": ["warnings", "running", "user", "output"]
244 246
    }
245 247

  
246
  hide = ",".join(level_aliases["everything"])
247
  show = None
248
  lhide = level_aliases["everything"]
249
  lshow = []
248 250

  
249 251
  if args.verbose == 1:
250
    show = ",".join(levels[:3])
251
    hide = ",".join(levels[3:])
252
    lshow = levels[:3]
253
    lhide = levels[3:]
252 254
  elif args.verbose == 2:
253
    show = ",".join(levels[:4])
254
    hide = ",".join(levels[4:])
255
    lshow = levels[:4]
256
    lhide = levels[4:]
255 257
  elif args.verbose >= 3 or args.debug:
256
    show = ",".join(levels)
257
    hide = None
258
    lshow = levels
259
    lhide = []
258 260

  
259
  if args.ssh_key:
260
    fabcmd = "fab -i %s " % args.ssh_key
261
  else:
262
    fabcmd = "fab "
263

  
264
  fabcmd += " --fabfile /usr/share/pyshared/snfdeploy/fabfile.py \
265
setup_env:confdir={0},packages={1},templates={2},cluster_name={3},\
266
autoconf={4},disable_colors={5},key_inject={6} \
267
".format(args.confdir, env.packages, env.templates, args.cluster_name,
268
         args.autoconf, args.disable_colors, args.key_inject)
261
#   fabcmd += " --fabfile {4}/fabfile.py \
262
# setup_env:confdir={0},packages={1},templates={2},cluster_name={3},\
263
# autoconf={5},disable_colors={6},key_inject={7} \
264
# ".format(args.confdir, env.packages, env.templates, args.cluster_name,
265
#          env.lib, args.autoconf, args.disable_colors, args.key_inject)
269 266

  
270 267
  if nodes:
271
    hosts = [env.nodes_info[n].hostname for n in nodes]
272
    actions = [a + ':hosts="%s"' % ";".join(hosts) for a in actions]
273

  
274
  extra = " ".join(actions)
275

  
276
  fabcmd += extra
277

  
278
  if show:
279
    fabcmd += " --show %s " % show
280
  if hide:
281
    fabcmd += " --hide %s " % hide
282

  
283
  # print("snf-deploy run " + " ".join(actions) + " -vvv")
284
  print(fabcmd)
268
    ips = [env.nodes_info[n].ip for n in nodes]
285 269

  
286
  if not args.dry_run:
287
    ret = os.system(fabcmd)
288
    if ret != 0:
289
        status = "exit with status %s" % ret
290
        sys.exit(status)
270
  fabfile.setup_env(args)
271
  with settings(hide(*lhide), show(*lshow)):
272
      print " ".join(actions)
273
      for a in actions:
274
        fn = getattr(fabfile, a)
275
        if not args.dry_run:
276
          if nodes:
277
             execute(fn, hosts=ips)
278
          else:
279
             execute(fn)
291 280

  
292 281

  
293 282
def cluster(args, env):
......
572 561
def main():
573 562
  args = parse_options()
574 563

  
575
  conf = Conf.configure(args.confdir, args.cluster_name, args, args.autoconf)
564
  conf = Conf(args)
576 565
  env = Env(conf)
577 566

  
578 567
  create_dir(env.run, False)
b/snf-deploy/snfdeploy/fabfile.py
18 18
from snfdeploy import massedit
19 19

  
20 20

  
21
def setup_env(confdir="conf", packages="packages", templates="files",
22
              cluster_name="ganeti1", autoconf=False, disable_colors=False,
23
              key_inject=False):
21
def setup_env(args):
24 22
    """Setup environment"""
25 23
    print("Loading configuration for synnefo...")
26
    print(" * Using config files under %s..." % confdir)
27
    print(" * Using %s and %s for packages and templates accordingly..."
28
          % (packages, templates))
29

  
30
    autoconf = ast.literal_eval(autoconf)
31
    disable_colors = ast.literal_eval(disable_colors)
32
    env.key_inject = ast.literal_eval(key_inject)
33
    conf = Conf.configure(confdir=confdir, cluster_name=cluster_name,
34
                          autoconf=autoconf)
24

  
25
    conf = Conf(args)
35 26
    env.env = Env(conf)
36 27

  
37
    env.local = autoconf
28
    env.local = args.autoconf
29
    env.key_inject = args.key_inject
38 30
    env.password = env.env.password
39 31
    env.user = env.env.user
40 32
    env.shell = "/bin/bash -c"
33
    env.key_filename = args.ssh_key
41 34

  
42
    if disable_colors:
35
    if args.disable_colors:
43 36
        disable_color()
44 37

  
45 38
    if env.env.cms.hostname in \
b/snf-deploy/snfdeploy/lib.py
146 146
        "synnefo": ["cred", "synnefo", "roles"],
147 147
        "squeeze": ["debian", "ganeti", "synnefo", "other"],
148 148
        "wheezy": ["debian", "ganeti", "synnefo", "other"],
149
        "ganeti": [],
150 149
    }
150
    confdir = "/etc/snf-deploy"
151 151

  
152
    def __init__(self, confdir, cluster_name):
153
        self.confdir = confdir
152
    def get_ganeti(self, cluster_name):
154 153
        self.files["ganeti"] = [cluster_name]
154

  
155

  
156
    def __init__(self, args):
157
        self.confdir = args.confdir
158
        self.get_ganeti(args.cluster_name)
155 159
        for f in self.files.keys():
156 160
            setattr(self, f, self.read_config(f))
161
        for f, sections in self.files.iteritems():
162
            for s in sections:
163
                for k, v in self.get_section(f, s):
164
                    if getattr(args, k, None):
165
                        self.set(f, s, k, getattr(args, k))
166
        if args.autoconf:
167
            self.autoconf()
168

  
169
    def autoconf(self):
170
        #domain = get_domain()
171
        #if domain:
172
        #    self.nodes.set("network", "domain", get_domain())
173
        # self.nodes.set("network", "subnet", "/".join(get_netinfo()))
174
        # self.nodes.set("network", "gateway", get_default_route()[0])
175
        self.nodes.set("hostnames", "node1", get_hostname())
176
        self.nodes.set("ips", "node1", get_netinfo()[0])
177
        self.nodes.set("info", "nodes", "node1")
178
        self.nodes.set("info", "public_iface", get_default_route()[1])
157 179

  
158 180
    def read_config(self, f):
159 181
        config = ConfigParser.ConfigParser()
......
178 200
        for f in self.files.keys():
179 201
            getattr(self, f).write(sys.stdout)
180 202

  
181
    def _configure(self, args):
182
        for f, sections in self.files.iteritems():
183
            for s in sections:
184
                for k, v in self.get_section(f, s):
185
                    if getattr(args, k, None):
186
                        self.set(f, s, k, getattr(args, k))
187

  
188
    @classmethod
189
    def configure(cls, confdir="/etc/snf-deploy",
190
                  cluster_name="ganeti1", args=None, autoconf=False):
191

  
192
        conf = cls(confdir, cluster_name)
193
        if args:
194
            conf._configure(args)
195
        if autoconf:
196
            conf.autoconf()
197

  
198
        return conf
199

  
200
    def autoconf(self):
201
        #domain = get_domain()
202
        #if domain:
203
        #    self.nodes.set("network", "domain", get_domain())
204
        # self.nodes.set("network", "subnet", "/".join(get_netinfo()))
205
        # self.nodes.set("network", "gateway", get_default_route()[0])
206
        self.nodes.set("hostnames", "node1", get_hostname())
207
        self.nodes.set("ips", "node1", get_netinfo()[0])
208
        self.nodes.set("info", "nodes", "node1")
209
        self.nodes.set("info", "public_iface", get_default_route()[1])
210

  
211

  
212 203

  
213 204
def debug(host, msg):
214 205

  

Also available in: Unified diff