Example #1
0
File: zfs.py Project: Simage/pyzfs
 def check(cls, name):
     zfs = Popen(['/sbin/zfs', 'list', name], stdout=-1)
     if zfs.wait():
         return False
     if zfs.stdout.next().startswith('cannot open'):
         return False
     return True
Example #2
0
    def loadrunning(cls):
        cls._loaded = []
        devfs = Popen(['/sbin/devfs','rule','showsets'],stdout=-1)
        devfs.wait()

        for line in devfs.stdout:
            cls._loaded.append(int(line.strip()))
Example #3
0
File: zfs.py Project: Simage/pyzfs
 def refresh(self, force=True):
     if (len(self.properties) > 0) and not force:
         return
     self.properties = {}
     zfs = Popen(['/sbin/zfs', 'get', 'all', self.parent], stdout=-1)
     if zfs.wait():
         raise Exception('properties could not be read')
     zfs.stdout.next()
     for line in zfs.stdout:
         prop = Property(*line.split())
         self.properties[prop.name] = prop
Example #4
0
File: zfs.py Project: Simage/pyzfs
 def populate(self, force=False):
     if not (force or (len(self) == 0)):
         return
     self.clear()
     zfs = Popen(['/sbin/zfs', 'list', '-r', '-t', 'snapshot', self.parent], stdout=-1)
     if zfs.wait():
         raise Exception('snapshots could not be read')
     zfs.stdout.next()
     for line in zfs.stdout:
         snap = Snapshot(line.split()[0])
         if snap.path == self.parent:
             self.append(snap)
Example #5
0
File: zfs.py Project: Simage/pyzfs
 def populate(self, force=False):
     if not (force or (len(self) == 0)):
         return
     self.clear()
     zfs = Popen(['/sbin/zfs', 'list', '-r', self.parent], stdout=-1)
     if zfs.wait():
         raise Exception('filesystems could not be read')
     zfs.stdout.next()
     for line in zfs.stdout:
         fs = FileSystem(line.split()[0])
         if fs.parent == self.parent:
             self.append(fs)
Example #6
0
    def _ifprestop(self):
        if not self.vlan:
            return
        ifc = Popen(['/usr/sbin/jexec',self.jid,'/sbin/ifconfig'], stdout=-1)
        ifc.wait()

        for line in ifc.stdout:
            if line.startswith('\t'):
                continue
            int = line.split(':')[0]
            if int.startswith('epair') and int.endswith('b'):
                break
        self._ifpair = int[:-1]
Example #7
0
    def fromdevfs(cls, name, id):
        id = int(id)
        if id in cls._byid:
            return cls._byid[id]

        lines = []
        devfs = Popen(['/sbin/devfs','rule','-s',str(id),'show'], stdout=-1)
        devfs.wait()
        for line in devfs.stdout:
            lines.append(line.strip())
        if len(lines):
            return cls.fromlines(name, id, lines)
        else:
            return None
Example #8
0
    def start(self, force=False):
        if self.running:
            print self.name+' is already running'
            return False
        if not (self.enable or force):
            return False
        print 'starting '+self.name
        self._mount()
        self._ifprestart()
        cmd = self._buildcommand()
        if self.vlan:
            jail = Popen(cmd, stdin=-1)
        else:
            jail = Popen(cmd)

        if jail.poll() > 0:
            print self.name+' failed'
            return

        self._ifpoststart()

        if self.vlan:
            if jail.poll() is None:
                jail.stdin.close()
        else:
            jail.wait()
        self.running = True
Example #9
0
    def _ifprestart(self):
        if self.vlan:
            # search for existing usable vlan
            ifc = Popen(['/sbin/ifconfig'], stdout=-1)
            ifc.wait()
            pairs = {}
            for line in ifc.stdout:
                if not line.startswith('epair'):
                    continue
                pair = line.split(':')[0][:-1]
                if pair in pairs:
                    pairs[pair] += 1
                else:
                    pairs[pair] = 1
            for k,v in sorted(pairs.items()):
                if v == 2:
                    self._ifpair = k
                    break
            else:
                # create a new vlan
                ifc = Popen(['/sbin/ifconfig','epair','create'], stdout=-1)
                ifc.wait()
                self._ifpair = ifc.stdout.readline().rstrip()[:-1]

            call(['/sbin/ifconfig','bridge0','addm',self._ifpair+'a'])
            call(['/sbin/ifconfig',self._ifpair+'a','up'])

        else:
            for ip in self.ip4:
                call(['/sbin/ifconfig',self.iface,'alias',ip,'netmask','255.255.255.255'])
            for ip in self.ip6:
                call(['/sbin/ifconfig',self.iface,'inet6',ip,'prefixlen','128'])
Example #10
0
    def loadrunning(cls):
        if len(cls._modules) == 0:
            cls.loadlist()

        for module in cls._modules.values():
            module.running = False

        jls = Popen('/usr/sbin/jls',stdout=-1)
        jls.wait()

        for line in jls.stdout:
            try:
                id,ip,hn,rd = line.split()
                for module in cls._modules.values():
                    if not module.enable:
                        continue
                    if rd == module.rootdir:
                        module.running = True
                        module.jid = id
                        break
            except:
                pass