- def free_slots (self):
- return self.max_plcs - len(self.plc_instances)
-
- def uname(self):
- if hasattr(self,'_uname') and self._uname: return self._uname
- return '*undef* uname'
-
- def plc_instance_by_vservername (self, vservername):
- for p in self.plc_instances:
- if p.vservername==vservername: return p
- return None
-
- def reboot (self, options):
- if not options.soft:
- self.reboot(options)
- else:
- self.run_ssh(['service','util-vserver','stop'],"Stopping all running vservers",
- dry_run=options.dry_run)
-
- def sense (self, options):
- print 'p',
- self._uname=self.backquote_ssh(['uname','-r']).strip()
- # try to find fullname (vserver_stat truncates to a ridiculously short name)
- # fetch the contexts for all vservers on that box
- map_command=['grep','.','/etc/vservers/*/context','/dev/null',]
- context_map=self.backquote_ssh (map_command)
- # at this point we have a set of lines like
- # /etc/vservers/2010.01.20--k27-f12-32-vplc03/context:40144
- ctx_dict={}
- for map_line in context_map.split("\n"):
- if not map_line: continue
- [path,xid] = map_line.split(':')
- ctx_dict[xid]=os.path.basename(os.path.dirname(path))
- # at this point ctx_id maps context id to vservername
-
- command=['vserver-stat']
- vserver_stat = self.backquote_ssh (command)
- for vserver_line in vserver_stat.split("\n"):
- if not vserver_line: continue
- context=vserver_line.split()[0]
- if context=="CTX": continue
- try:
- longname=ctx_dict[context]
- self.add_vserver(longname,context)
- except:
- print 'WARNING: found ctx %s in vserver_stat but was unable to figure a corresp. vserver'%context
-
- # scan timestamps
- running_vsnames = [ i.vservername for i in self.plc_instances ]
- command= ['grep','.']
- command += ['/vservers/%s.timestamp'%vs for vs in running_vsnames]
- command += ['/dev/null']
- ts_lines=self.backquote_ssh(command,trash_err=True).split('\n')
- for ts_line in ts_lines:
- if not ts_line.strip(): continue
- # expect /vservers/<vservername>.timestamp:<timestamp>
- try:
- (ts_file,timestamp)=ts_line.split(':')
- ts_file=os.path.basename(ts_file)
- (vservername,_)=os.path.splitext(ts_file)
- timestamp=int(timestamp)
- p=self.plc_instance_by_vservername(vservername)
- if not p:
- print 'WARNING zombie plc',self.hostname,ts_line
- print '... was expecting',vservername,'in',[i.vservername for i in self.plc_instances]
- continue
- p.set_timestamp(timestamp)
- except: print 'WARNING, could not parse ts line',ts_line
-
-