Revision 3bae85da snf-deploy/snfdeploy/lib.py

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