Esempio n. 1
0
 def create(self, **kwargs):
     if not os.path.exists(self.svc_loct):
         self._txt.load(text=self._svc_tmpl_)
         self._txt.set_param("prog", self.svc_name)
         self._txt.save(file=self.svc_loct)
         fs.chmod(self.svc_loct, 0o755)
     self.config(**kwargs)
     
     os.system("chkconfig --add %s" % self.svc_name)
Esempio n. 2
0
    def startup(self, instance):
        authkeys = """auth 1
1 sha1 heartbeat
"""
        self._txt.load(text=authkeys)
        self._txt.save("/etc/ha.d/authkeys")
        File.chmod("/etc/ha.d/authkeys", 0o600)
        
        peer_nic = None
        peer_linkip = None
        
        if instance == 0:
            peer_nic = self.machines["m1"]["nic"]
            peer_linkip  = self.machines["m1"]["linkip"]
        elif instance == 1:
            peer_nic = self.machines["m0"]["nic"]
            peer_linkip  = self.machines["m0"]["linkip"]
        else:
            raise Exception("instance must be 0 or 1")
        
        ha_cf = """logfile /var/log/hb.log
debugfile /var/log/heartbeat-debug.log
keepalive 1
warntime 10
deadtime 30
initdead 120
udpport 694
ucast %(peer_nic)s %(peer_linkip)s

auto_failback on
node %(m0_hostname)s
node %(m1_hostname)s
crm no
""" % { "m0_hostname":  self.machines["m0"]["hostname"], 
        "m1_hostname":  self.machines["m1"]["hostname"], 
        "peer_nic":     peer_nic,
        "peer_linkip":  peer_linkip,
      }
        self._txt.load(text=ha_cf)
        self._txt.save("/etc/ha.d/ha.cf")


        haresources = """%(m0_hostname)s  IPaddr::%(r0_virtual_addr)s/%(r0_virtual_cidr)s/%(r0_virtual_nic)s drbddisk::r0 Filesystem::%(r0_device)s::%(r0_dir)s::ext4 %(r0_services)s
%(m1_hostname)s  IPaddr::%(r1_virtual_addr)s/%(r1_virtual_cidr)s/%(r1_virtual_nic)s drbddisk::r1 Filesystem::%(r1_device)s::%(r1_dir)s::ext4 %(r1_services)s
""" % { "m0_hostname":          self.machines["m0"]["hostname"],
        "r0_virtual_nic":       self.resources["r0"]["virtual_ip"][0]["nic"],
        "r0_virtual_cidr":      self.resources["r0"]["virtual_ip"][0]["cidr"],
        "r0_virtual_addr":      self.resources["r0"]["virtual_ip"][0]["addr"],
        "r0_device":            self.resources["r0"]["device"],
        "r0_dir":               self.resources["r0"]["dir"],
        "r0_services":          " ".join(self.resources["r0"]["services"]) if self.resources["r0"]["services"] else "",
        
        "m1_hostname":          self.machines["m1"]["hostname"],
        "r1_virtual_nic":       self.resources["r1"]["virtual_ip"][0]["nic"],
        "r1_virtual_cidr":      self.resources["r1"]["virtual_ip"][0]["cidr"],
        "r1_virtual_addr":      self.resources["r1"]["virtual_ip"][0]["addr"],
        "r1_device":            self.resources["r1"]["device"],
        "r1_dir":               self.resources["r1"]["dir"],
        "r1_services":          " ".join(self.resources["r1"]["services"]) if self.resources["r1"]["services"] else "",
      }
        self._txt.load(text=haresources)
        self._txt.save("/etc/ha.d/haresources")
        
        self._svc.start()