+ def add_lxc (self,lxcname,pid):
+ for plc in self.plc_instances:
+ if plc.lxcname==lxcname:
+ header("WARNING, duplicate myplc %s running on %s"%\
+ (lxcname,self.hostname),banner=False)
+ return
+ self.plc_instances.append(PlcLxcInstance(self,lxcname,pid))
+
+
+ # a line describing the box
+ def line(self):
+ return "%s [max=%d,free=%d] (%s)"%(self.hostname_fedora(virt="lxc"),
+ self.max_plcs,self.free_slots(),
+ self.uptime(),
+ )
+
+ def plc_instance_by_lxcname (self, lxcname):
+ for p in self.plc_instances:
+ if p.lxcname==lxcname: return p
+ return None
+
+ # essentially shutdown all running containers
+ def soft_reboot (self, options):
+ command="rsync lxc-driver.sh %s:/root"%self.hostname
+ commands.getstatusoutput(command)
+ self.run_ssh(['/root/lxc-driver.sh','-c','stop_all'],"Stopping all running lxc containers on %s"%(self.hostname,),
+ dry_run=options.dry_run)
+
+
+ # sense is expected to fill self.plc_instances with PlcLxcInstance's
+ # to describe the currently running VM's
+ def sense (self, options):
+ print "xp",
+ command="rsync lxc-driver.sh %s:/root"%self.hostname
+ commands.getstatusoutput(command)
+ command=['/root/lxc-driver.sh','-c','sense_all']
+ lxc_stat = self.backquote_ssh (command)
+ for lxc_line in lxc_stat.split("\n"):
+ if not lxc_line: continue
+ lxcname=lxc_line.split(";")[0]
+ pid=lxc_line.split(";")[1]
+ timestamp=lxc_line.split(";")[2]
+ self.add_lxc(lxcname,pid)
+ try: timestamp=int(timestamp)
+ except: timestamp=0
+ p=self.plc_instance_by_lxcname(lxcname)
+ if not p:
+ print 'WARNING zombie plc',self.hostname,lxcname
+ print '... was expecting',lxcname,'in',[i.lxcname for i in self.plc_instances]
+ continue
+ p.set_timestamp(timestamp)