def chown(vendorid, productid): # remove the 0x from the vendor and product id devid = vendorid[2:] + ':' + productid[2:] command = ['lsusb', '-d', devid] retcode, out, err = utils.execCmd(command, sudo=False, raw=True) if retcode != 0: sys.stderr.write('hostusb: cannot find usb device: %s\n' % devid) sys.exit(2) # find the device path: # /dev/bus/usb/xxx/xxx devpath = '/dev/bus/usb/' + out[4:7] + '/' + out[15:18] stat = os.stat(devpath) group = grp.getgrnam('qemu') gid = group.gr_gid user = pwd.getpwnam('qemu') uid = user.pw_uid # we don't use os.chown because we need sudo owner = str(uid) + ':' + str(gid) command = ['/bin/chown', owner, devpath] retcode, out, err = utils.execCmd(command, sudo=True, raw=True) if retcode != 0: sys.stderr.write('hostusb: error chown %s to %s, err = %s\n' % (devpath, owner, err)) sys.exit(2) log_dev_owner(devpath, stat.st_uid, stat.st_gid)
def chown(vendorid, productid): # remove the 0x from the vendor and product id devid = vendorid[2:] + ':' + productid[2:] command = ['lsusb', '-d', devid] retcode, out, err = utils.execCmd(command, sudo=False, raw=True) if retcode != 0: sys.stderr.write('hostusb: cannot find usb device: %s\n' % devid) sys.exit(2) devpath = '/dev/bus/usb/' + out[4:7] + '/' + out[15:18] uid, gid = get_owner(devpath) if uid == -1: sys.stderr.write( 'hostusb after_vm_destroy: cannot find devpath: %s in file: %s\n' % (devpath, HOOK_HOSTUSB_PATH)) return # we don't use os.chown because we need sudo owner = str(uid) + ':' + str(gid) command = ['/bin/chown', owner, devpath] retcode, out, err = utils.execCmd(command, sudo=True, raw=True) if retcode != 0: sys.stderr.write( 'hostusb after_vm_destroy: error chown %s to %s, err = %s\n' % (devpath, owner, err)) sys.exit(2)
def chown(vendorid, productid): # remove the 0x from the vendor and product id devid = vendorid[2:] + ":" + productid[2:] command = ["lsusb", "-d", devid] retcode, out, err = utils.execCmd(command, sudo=False, raw=True) if retcode != 0: sys.stderr.write("hostusb: cannot find usb device: %s\n" % devid) sys.exit(2) devpath = "/dev/bus/usb/" + out[4:7] + "/" + out[15:18] uid, gid = get_owner(devpath) if uid == -1: sys.stderr.write( "hostusb after_vm_destroy: cannot find devpath: %s in file: %s\n" % (devpath, HOOK_HOSTUSB_PATH) ) return # we don't use os.chown because we need sudo owner = str(uid) + ":" + str(gid) command = ["/bin/chown", owner, devpath] retcode, out, err = utils.execCmd(command, sudo=True, raw=True) if retcode != 0: sys.stderr.write("hostusb after_vm_destroy: error chown %s to %s, err = %s\n" % (devpath, owner, err)) sys.exit(2)
def adjust(self): """adjust ksm state according to configuration and current memory stress return whether ksm is running""" self._lock.acquire() try: utils.execCmd([constants.EXT_SERVICE, 'ksmtuned', 'retune'], sudo=True) self.state, self.pages = self.readState() finally: self._lock.release() return self.state
def _connect(self): logging.debug("Attempting connection to %s", self._socketName) utils.execCmd([constants.EXT_PREPARE_VMCHANNEL, self._socketName]) self._sock.settimeout(5) while not self._stopped: try: self._sock.connect(self._socketName) logging.debug("connected to %s", self._socketName) self._sock.settimeout(config.getint('vars', 'guest_agent_timeout')) return True except: time.sleep(1) return False
def _gen_keys(cluster_name, fsid, monitors, cluster_dir): ''' :: monitors = {ID: {'name': SHORT_HOSTNAME, 'address': IP_ADDR, 'port': INT}, ...} ''' mon_key_path = cluster_dir + '/mon.key' admin_key_path = cluster_dir + '/client.admin.keyring' mon_map_path = cluster_dir + '/mon.map' utils.execCmd([_ceph_authtool.cmd, '--create-keyring', mon_key_path, '--gen-key', '-n', 'mon.', '--cap', 'mon', 'allow *']) utils.execCmd([_ceph_authtool.cmd, '--create-keyring', admin_key_path, '--gen-key', '-n', 'client.admin', '--set-uid=0', '--cap', 'mon', 'allow *', '--cap', 'osd', 'allow *', '--cap', 'mds', 'allow']) utils.execCmd([_ceph_authtool.cmd, mon_key_path, '--import-keyring', admin_key_path]) cmd = [_monmaptool.cmd, '--create', '--clobber'] for m, v in monitors.iteritems(): cmd += ['--add', 'mon.' + m, v['address']] cmd += ['--fsid', fsid, mon_map_path] utils.execCmd(cmd) return True
def _gen_keys(cluster_name, fsid, monitors, cluster_dir): ''' :: monitors = {ID: {'name': SHORT_HOSTNAME, 'address': IP_ADDR, 'port': INT}, ...} ''' mon_key_path = cluster_dir + '/mon.key' admin_key_path = cluster_dir + '/client.admin.keyring' mon_map_path = cluster_dir + '/mon.map' utils.execCmd([ _ceph_authtool.cmd, '--create-keyring', mon_key_path, '--gen-key', '-n', 'mon.', '--cap', 'mon', 'allow *' ]) utils.execCmd([ _ceph_authtool.cmd, '--create-keyring', admin_key_path, '--gen-key', '-n', 'client.admin', '--set-uid=0', '--cap', 'mon', 'allow *', '--cap', 'osd', 'allow *', '--cap', 'mds', 'allow' ]) utils.execCmd( [_ceph_authtool.cmd, mon_key_path, '--import-keyring', admin_key_path]) cmd = [_monmaptool.cmd, '--create', '--clobber'] for m, v in monitors.iteritems(): cmd += ['--add', 'mon.' + m, v['address']] cmd += ['--fsid', fsid, mon_map_path] utils.execCmd(cmd) return True
def getRBDStats(pool_name, cluster_name): cmd = ["rbd", "du", "--cluster", cluster_name, "-p", pool_name, "--format=json"] rc, out, err = utils.execCmd(cmd) if not rc: return out else: return err
def getPoolList(clusterName): cmd = ["ceph", "--cluster", clusterName, "-f", "json", "osd", "lspools"] rc, out, err = utils.execCmd(cmd) if not rc: return out else: return err
def _execCmd(command): returnCode, output, error = execCmd(command) if returnCode: raise IPRoute2Error(error) return output
def info(image, format=None): cmd = [_qemuimg.cmd, "info"] if format: cmd.extend(("-f", format)) cmd.append(image) rc, out, err = utils.execCmd(cmd) if rc != 0: raise QImgError(rc, out, err) try: info = { 'format': __iregexSearch("format", out[1]), 'virtualsize': int(__iregexSearch("virtualsize", out[2])), } if len(out) > 4: info['clustersize'] = int(__iregexSearch("clustersize", out[4])) if len(out) > 5: info['backingfile'] = __iregexSearch("backingfile", out[5]) except: raise QImgError(rc, out, err, "unable to parse qemu-img info output") return info
def _getKeyPackages(): def kernelDict(): try: ver, rel = file('/proc/sys/kernel/osrelease').read(). \ strip().split('-', 1) except: logging.error('kernel release not found', exc_info=True) ver, rel = '0', '0' try: t = file('/proc/sys/kernel/version').read().split()[2:] del t[4] # Delete timezone t = time.mktime(time.strptime(' '.join(t))) except: logging.error('kernel build time not found', exc_info=True) t = '0' return dict(version=ver, release=rel, buildtime=t) KEY_PACKAGES = ['qemu-kvm', 'qemu-img', 'vdsm', 'spice-server', 'libvirt'] pkgs = {'kernel': kernelDict()} try: for pkg in KEY_PACKAGES: rc, out, err = utils.execCmd([ constants.EXT_RPM, '-q', '--qf', '%{NAME}\t%{VERSION}\t%{RELEASE}\t%{BUILDTIME}\n', pkg ], sudo=False) if rc: continue line = out[-1] n, v, r, t = line.split() pkgs[pkg] = dict(version=v, release=r, buildtime=t) except: logging.error('', exc_info=True) return pkgs
def getOSDDetails(clusterName): cmd = ["ceph", "osd", "df", "--cluster", clusterName, "-f", "json"] rc, out, err = utils.execCmd(cmd) if not rc: return out else: return err
def removeDeviceNode(devpath): # we don't use os.unlink because we need sudo command = ['/bin/rm', '-f', devpath] retcode, out, err = utils.execCmd(command, sudo=True, raw=True) if retcode != 0: sys.stderr.write('directlun after_vm_destroy: error rm -f %s, err = %s\n' % (devpath, err)) sys.exit(2)
def _getKeyPackages(): def kernelDict(): try: ver, rel = file('/proc/sys/kernel/osrelease').read(). \ strip().split('-', 1) except: logging.error('kernel release not found', exc_info=True) ver, rel = '0', '0' try: t = file('/proc/sys/kernel/version').read().split()[2:] del t[4] # Delete timezone t = time.mktime(time.strptime(' '.join(t))) except: logging.error('kernel build time not found', exc_info=True) t = '0' return dict(version=ver, release=rel, buildtime=t) KEY_PACKAGES = ['qemu-kvm', 'qemu-img', 'vdsm', 'spice-server', 'libvirt'] pkgs = {'kernel': kernelDict()} try: for pkg in KEY_PACKAGES: rc, out, err = utils.execCmd([constants.EXT_RPM, '-q', '--qf', '%{NAME}\t%{VERSION}\t%{RELEASE}\t%{BUILDTIME}\n', pkg], sudo=False) if rc: continue line = out[-1] n, v, r, t = line.split() pkgs[pkg] = dict(version=v, release=r, buildtime=t) except: logging.error('', exc_info=True) return pkgs
def _execGluster(cmd): rc, out, err = utils.execCmd(cmd) if rc != 0: if (err is not None and any(_TRANS_IN_PROGRESS in e.lower() for e in err)) or ( out is not None and any("connection failed" in o.lower() for o in out) ): raise GlusterLockedException(rc, out, err) return rc, out, err
def addOsdToCrush(clusterName, osdName, weight, host): hostStr = 'host='+host cmd = ["ceph", "--cluster", clusterName, "osd", "crush", "create-or-move", osdName, str(round(weight,9)), hostStr, "root=default"] try: rc, out, err = utils.execCmd(cmd) return rc except Exception as e: return 1
def getClusterStatus(clusterName): cmd = ["ceph", "-s", "--cluster", clusterName] rc, out, err = utils.execCmd(cmd) if not rc: for line in out.splitlines(): if line.strip().startswith("health"): return line.strip().split(' ')[1] return ''
def removeDeviceNode(devpath): # we don't use os.unlink because we need sudo command = ['/bin/rm', '-f', devpath] retcode, out, err = utils.execCmd(command, sudo=True, raw=True) if retcode != 0: sys.stderr.write( 'directlun after_vm_destroy: error rm -f %s, err = %s\n' % (devpath, err)) sys.exit(2)
def _execGluster(cmd): rc, out, err = utils.execCmd(cmd) if rc != 0: if ((err is not None and any(_TRANS_IN_PROGRESS in e.lower() for e in err)) or (out is not None and any("connection failed" in o.lower() for o in out))): raise GlusterLockedException(rc, out, err) return rc, out, err
def getRBDStats(pool_name, cluster_name): cmd = [ "rbd", "du", "--cluster", cluster_name, "-p", pool_name, "--format=json" ] rc, out, err = utils.execCmd(cmd) if not rc: return out else: return err
def removePool(clusterName, poolName): cmd = [ "ceph", "osd", "pool", "delete", poolName, poolName, "--yes-i-really-really-mean-it", "--cluster", clusterName ] rc, out, err = utils.execCmd(cmd) if not rc: return out else: return err
def resize(image, newSize, format=None): cmd = [_qemuimg.cmd, "resize"] if format: cmd.extend(("-f", format)) cmd.extend((image, str(newSize))) rc, out, err = utils.execCmd(cmd) if rc != 0: raise QImgError(rc, out, err)
def createPool(clusterName, poolName, pgNum=0): cmd = ["ceph", "--cluster", clusterName, "osd", "pool", "create", poolName] if pgNum: cmd += [pgNum] else: cmd += [DEFAULT_PG_NUM] rc, out, err = utils.execCmd(cmd) if not rc: return out else: return err
def check(image, format=None): cmd = [_qemuimg.cmd, "check"] if format: cmd.extend(("-f", format)) cmd.append(image) rc, out, err = utils.execCmd(cmd) if rc != 0: raise QImgError(rc, out, err)
def addOsdToCrush(clusterName, osdName, weight, host): hostStr = 'host=' + host cmd = [ "ceph", "--cluster", clusterName, "osd", "crush", "create-or-move", osdName, str(round(weight, 9)), hostStr, "root=default" ] try: rc, out, err = utils.execCmd(cmd) return rc except Exception as e: return 1
def cloneDeviceNode(srcpath, devpath): '''Clone a device node into a temporary private location.''' # we don't use os.remove/mknod/chmod/chown because we need sudo command = ['/bin/rm', '-f', devpath] retcode, out, err = utils.execCmd(command, sudo=True, raw=True) if retcode != 0: sys.stderr.write('directlun: error rm -f %s, err = %s\n' % (devpath, err)) sys.exit(2) stat = os.stat(srcpath) major = os.major(stat.st_rdev) minor = os.minor(stat.st_rdev) command = ['/bin/mknod', devpath, 'b', str(major), str(minor)] retcode, out, err = utils.execCmd(command, sudo=True, raw=True) if retcode != 0: sys.stderr.write('directlun: error mknod %s, err = %s\n' % (devpath, err)) sys.exit(2) mode = '660' command = ['/bin/chmod', mode, devpath] retcode, out, err = utils.execCmd(command, sudo=True, raw=True) if retcode != 0: sys.stderr.write('directlun: error chmod %s to %s, err = %s\n' % (devpath, mode, err)) sys.exit(2) group = grp.getgrnam('qemu') gid = group.gr_gid user = pwd.getpwnam('qemu') uid = user.pw_uid owner = str(uid) + ':' + str(gid) command = ['/bin/chown', owner, devpath] retcode, out, err = utils.execCmd(command, sudo=True, raw=True) if retcode != 0: sys.stderr.write('directlun: error chown %s to %s, err = %s\n' % (devpath, owner, err)) sys.exit(2)
def createFloppy(filename, path, content): if os.path.exists(path): os.remove(path) # create floppy file system command = ['/sbin/mkfs.msdos', '-C', path, '1440'] retcode, out, err = utils.execCmd(command, sudo=True, raw=True) if retcode != 0: sys.stderr.write('floppyinject-before-dest-migration: error /sbin/mkfs.msdos fs: %s\n' % err) sys.exit(2) owner = '36:36' command = ['/bin/chown', owner, path] retcode, out, err = utils.execCmd(command, sudo=True, raw=True) if retcode != 0: sys.stderr.write('floppyinject-before-dest-migration: error /bin/chown: %s' % err) sys.exit(2) # create floppy file system command = ['/bin/chmod', '0770', path] retcode, out, err = utils.execCmd(command, sudo=True, raw=True) if retcode != 0: sys.stderr.write('floppyinject-before-dest-migration: error /bin/chmod: %s' % err) sys.exit(2) # mount the floppy file mntpoint = tempfile.mkdtemp() command = ['/bin/mount', '-o', 'loop,uid=36,gid=36' , path, mntpoint] sys.stderr.write('shahar: %s\n' % ' '.join(command)) retcode, out, err = utils.execCmd(command, sudo=True, raw=True) if retcode != 0: sys.stderr.write('floppyinject-before-dest-migration: error /bin/mount: %s' % err) sys.exit(2) # write the file content contentpath = os.path.join(mntpoint, filename) f = open(contentpath, 'w') f.write(content) f.close() # unmounting command = ['/bin/umount', mntpoint] retcode, out, err = utils.execCmd(command, sudo=True, raw=True) if retcode != 0: sys.stderr.write('floppyinject-before-dest-migration: error /bin/umount: %s' % err) sys.exit(2) # remove tempdir command = ['/bin/rmdir', mntpoint] retcode, out, err = utils.execCmd(command, sudo=True, raw=True) if retcode != 0: sys.stderr.write('floppyinject-before-dest-migration: error /bin/rmdir: %s' % err) sys.exit(2)
def getIp(): ipRe = re.compile( r"(?:25[0-5]\.|2[0-4]\d\.|[01]?\d\d?\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)" ) wlanList = ['wlp2s0', 'wlan0'] wlanip = "" for wlan in wlanList: ip = utils.execCmd("ifconfig " + wlan) ipList = ipRe.findall(ip) if len(ipList) != 0: wlanip = ipList[0] break return wlanip
def createDirectory(dirpath): # we don't use os.mkdir/chown because we need sudo command = ['/bin/mkdir', '-p', dirpath] retcode, out, err = utils.execCmd(command, sudo=True, raw=True) if retcode != 0: sys.stderr.write('directlun: error mkdir %s, err = %s\n' % (dirpath, err)) sys.exit(2) mode = '755' command = ['/bin/chmod', mode, dirpath] if retcode != 0: sys.stderr.write('directlun: error chmod %s %s, err = %s\n' % (dirpath, mode, err)) sys.exit(2)
def main(): cmd = ["dbus-send", "--system", "--type=method_call", "--dest=org.storaged.Storaged", "/org/storaged/Storaged/Manager", "org.storaged.Storaged.Manager.EnableModules", "boolean:true"] rc, out, err = utils.execCmd(cmd) if rc != 0 : logger.error("Could not enable Storaged module") try: Skynetd().run() exit(0) except Exception as e: logger.error("Skynet Initialization failed: %s", str(e)) pass
def createFloppy(filename, path, content): if os.path.exists(path): os.remove(path) # create floppy file system command = ['/sbin/mkfs.msdos', '-C', path, '1440'] retcode, out, err = utils.execCmd(command, sudo=True, raw=True) if retcode != 0: sys.stderr.write('floppyinject: error /sbin/mkfs.msdos fs: %s\n' % err) sys.exit(2) owner = '36:36' command = ['/bin/chown', owner, path] retcode, out, err = utils.execCmd(command, sudo=True, raw=True) if retcode != 0: sys.stderr.write('floppyinject: error /bin/chown: %s' % err) sys.exit(2) # create floppy file system command = ['/bin/chmod', '0770', path] retcode, out, err = utils.execCmd(command, sudo=True, raw=True) if retcode != 0: sys.stderr.write('floppyinject: error /bin/chmod: %s' % err) sys.exit(2) # mount the floppy file mntpoint = tempfile.mkdtemp() command = ['/bin/mount', '-o', 'loop,uid=36,gid=36', path, mntpoint] sys.stderr.write('shahar: %s\n' % ' '.join(command)) retcode, out, err = utils.execCmd(command, sudo=True, raw=True) if retcode != 0: sys.stderr.write('floppyinject: error /bin/mount: %s' % err) sys.exit(2) # base64 decode the content content = base64.decodestring(content) # write the file content contentpath = os.path.join(mntpoint, filename) f = open(contentpath, 'w') f.write(content) f.close() # unmounting command = ['/bin/umount', mntpoint] retcode, out, err = utils.execCmd(command, sudo=True, raw=True) if retcode != 0: sys.stderr.write('floppyinject: error /bin/umount: %s' % err) sys.exit(2) # remove tempdir command = ['/bin/rmdir', mntpoint] retcode, out, err = utils.execCmd(command, sudo=True, raw=True) if retcode != 0: sys.stderr.write('floppyinject: error /bin/rmdir: %s' % err) sys.exit(2)
def __init__(self, cif): threading.Thread.__init__(self, name = 'KsmMonitor') self.setDaemon(True) self._cif = cif self.state, self.pages = False, 0 self._lock = threading.Lock() if config.getboolean('ksm', 'ksm_monitor_thread'): pids = utils.execCmd([constants.EXT_PGREP, '-xf', 'ksmd'], raw=False, sudo=False)[1] if pids: self._pid = pids[0].strip() self.start() else: self._cif.log.error('failed to find ksmd thread') self.cpuUsage = 0
def cloneDeviceNode(srcpath, devpath): """Clone a device node into a temporary private location.""" # we don't use os.remove/mknod/chmod/chown because we need sudo command = ['/bin/rm', '-f', devpath] retcode, out, err = utils.execCmd(command, sudo=True, raw=True) if retcode != 0: sys.stderr.write('directlun: error rm -f %s, err = %s\n' % (devpath, err)) sys.exit(2) stat = os.stat(srcpath) major = os.major(stat.st_rdev) minor = os.minor(stat.st_rdev) command = ['/bin/mknod', devpath, 'b', str(major), str(minor)] retcode, out, err = utils.execCmd(command, sudo=True, raw=True) if retcode != 0: sys.stderr.write('directlun: error mknod %s, err = %s\n' % (devpath, err)) sys.exit(2) mode = '660' command = ['/bin/chmod', mode, devpath] retcode, out, err = utils.execCmd(command, sudo=True, raw=True) if retcode != 0: sys.stderr.write('directlun: error chmod %s to %s, err = %s\n' % (devpath, mode, err)) sys.exit(2) group = grp.getgrnam('qemu') gid = group.gr_gid user = pwd.getpwnam('qemu') uid = user.pw_uid owner = str(uid) + ':' + str(gid) command = ['/bin/chown', owner, devpath] retcode, out, err = utils.execCmd(command, sudo=True, raw=True) if retcode != 0: sys.stderr.write('directlun: error chown %s to %s, err = %s\n' % (devpath, owner, err)) sys.exit(2)
def __init__(self, cif): threading.Thread.__init__(self, name='KsmMonitor') self.setDaemon(True) self._cif = cif self.state, self.pages = False, 0 self._lock = threading.Lock() if config.getboolean('ksm', 'ksm_monitor_thread'): pids = utils.execCmd([constants.EXT_PGREP, '-xf', 'ksmd'], raw=False, sudo=False)[1] if pids: self._pid = pids[0].strip() self.start() else: self._cif.log.error('failed to find ksmd thread') self.cpuUsage = 0
def _gen_keys(cluster_name, fsid, monitors, cluster_dir): """ :: monitors = {ID: {'name': SHORT_HOSTNAME, 'address': IP_ADDR, 'port': INT}, ...} """ mon_key_path = cluster_dir + "/mon.key" admin_key_path = cluster_dir + "/client.admin.keyring" mon_map_path = cluster_dir + "/mon.map" utils.execCmd( [_ceph_authtool.cmd, "--create-keyring", mon_key_path, "--gen-key", "-n", "mon.", "--cap", "mon", "allow *"] ) utils.execCmd( [ _ceph_authtool.cmd, "--create-keyring", admin_key_path, "--gen-key", "-n", "client.admin", "--set-uid=0", "--cap", "mon", "allow *", "--cap", "osd", "allow *", "--cap", "mds", "allow", ] ) utils.execCmd([_ceph_authtool.cmd, mon_key_path, "--import-keyring", admin_key_path]) cmd = [_monmaptool.cmd, "--create", "--clobber"] for m, v in monitors.iteritems(): cmd += ["--add", "mon." + m, v["address"]] cmd += ["--fsid", fsid, mon_map_path] utils.execCmd(cmd) return True
def _runHooksDir(domxml, dir, vmconf={}, raiseError=True): scripts = _scriptsPerDir(dir) scripts.sort() if not scripts: return domxml xmlfd, xmlname = tempfile.mkstemp() try: os.write(xmlfd, domxml or '') os.close(xmlfd) scriptenv = os.environ.copy() scriptenv.update(vmconf.get('custom', {})) if vmconf.get('vmId'): scriptenv['vmId'] = vmconf.get('vmId') ppath = scriptenv.get('PYTHONPATH', '') scriptenv['PYTHONPATH'] = ':'.join(ppath.split(':') + [P_VDSM]) scriptenv['_hook_domxml'] = xmlname for k, v in scriptenv.iteritems(): scriptenv[k] = unicode(v).encode('utf-8') errorSeen = False for s in scripts: rc, out, err = utils.execCmd([s], sudo=False, raw=True, env=scriptenv) logging.info(err) if rc != 0: errorSeen = True if rc == 2: break elif rc > 2: logging.warn('hook returned unexpected return code %s', rc) if errorSeen and raiseError: raise HookError() finalxml = file(xmlname).read() finally: os.unlink(xmlname) return finalxml
def check(image, format=None): cmd = [_qemuimg.cmd, "check"] if format: cmd.extend(("-f", format)) cmd.append(image) rc, out, err = utils.execCmd(cmd) #FIXME: handle different error codes and raise errors accordingly if rc != 0: raise QImgError(rc, out, err) try: check = {'offset': int(__iregexSearch("offset", out[1]))} #TODO: Add requires for qemu supporting offset and print exc_info except: raise QImgError(rc, out, err, "unable to parse qemu-img check output") return check
def _execGlusterXml(cmd): cmd.append('--xml') rc, out, err = utils.execCmd(cmd) _throwIfBusy(cmd, rc, out, err) try: tree = etree.fromstring(out) rv = int(tree.find('opRet').text) msg = tree.find('opErrstr').text errNo = int(tree.find('opErrno').text) except _etreeExceptions: raise GlusterXMLError(cmd, out) if rv == 0: return tree if errNo != 0: rv = errNo raise GlusterCmdFailed(cmd, rv, err=msg)
def create(image, size=None, format=None, backing=None, backingFormat=None): cmd = [_qemuimg.cmd, "create"] if format: cmd.extend(("-f", format)) if backing: cmd.extend(("-b", backing)) if backingFormat: cmd.extend(("-F", backingFormat)) cmd.append(image) if size: cmd.append(int(size)) rc, out, err = utils.execCmd(cmd) if rc != 0: raise QImgError(rc, out, err)
def check(image, format=None): cmd = [_qemuimg.cmd, "check"] if format: cmd.extend(("-f", format)) cmd.append(image) rc, out, err = utils.execCmd(cmd) #FIXME: handle different error codes and raise errors accordingly if rc != 0: raise QImgError(rc, out, err) try: check = { 'offset': int(__iregexSearch("offset", out[1])) } #TODO: Add requires for qemu supporting offset and print exc_info except: raise QImgError(rc, out, err, "unable to parse qemu-img check output") return check
def rbd_command(command_args, pool_name=None): """ Run a rbd CLI operation directly. This is a fallback to allow manual execution of arbitrary commands in case the user wants to do something that is absent or broken in Calamari proper. :param pool_name: Ceph pool name, or None to run without --pool argument :param command_args: Command line, excluding the leading 'rbd' part. """ if pool_name: args = ["rbd", "--pool", pool_name] + command_args else: args = ["rbd"] + command_args log.info('rbd_command {0}'.format(str(args))) rc, out, err = utils.execCmd(args) log.info('rbd_command {0} {1} {2}'.format(str(rc), out, err)) return {'out': out, 'err': err, 'status': rc}
def rbd_command(command_args, pool_name=None): """ Run a rbd CLI operation directly. This is a fallback to allow manual execution of arbitrary commands in case the user wants to do something that is absent or broken in Calamari proper. :param pool_name: Ceph pool name, or None to run without --pool argument :param command_args: Command line, excluding the leading 'rbd' part. """ if pool_name: args = ["rbd", "--pool", pool_name] + command_args else: args = ["rbd"] + command_args log.info("rbd_command {0}".format(str(args))) rc, out, err = utils.execCmd(args) log.info("rbd_command {0} {1} {2}".format(str(rc), out, err)) return {"out": out, "err": err, "status": rc}
def _execGlusterXml(cmd): cmd.append('--xml') rc, out, err = utils.execCmd(cmd) if rc != 0: if ((err is not None and any(_TRANS_IN_PROGRESS in e.lower() for e in err)) or (out is not None and any("connection failed" in o.lower() for o in out))): raise GlusterLockedException(rc, out, err) else: raise GlusterCmdFailedException(rc, out, err) try: tree = etree.fromstring('\n'.join(out)) rv = int(tree.find('opRet').text) msg = tree.find('opErrstr').text errNo = int(tree.find('opErrno').text) except _etreeExceptions: raise GlusterCmdFailedException(err=out) if rv == 0: return tree else: if errNo != 0: rv = errNo raise GlusterCmdFailedException(rc=rv, err=[msg])
if platform.system() == "Linux": import linuxTools as sEnv elif platform.system() == "Windows": import winTools as sEnv elif platform.system() == "Mac": import macTools as sEnv else: print("Unsupport os") if len(sys.argv) > 1: cf = ConfigParser.ConfigParser() cf.read("singleNet.conf") mUsername = cf.get("config", "username") mPassword = cf.get("config", "password") if sys.argv[1] == "1": mpin = utils.calc_pin(mUsername, mPassword) sEnv.connectWired(mUsername, mPassword, mpin) elif sys.argv[1] == "2": wlanip = "" wlanip = sEnv.getIp() if wlanip == "": print("wlan device not found or error in found ip address") else: passRes = utils.execCmd("java EncryptPassword "+mPassword) utils.connectWireless(mUsername, passRes, wlanip) else: print("Paramter error 1 for wired connect 2 for wireless connect") else: print("Paramter error 1 for wired connect 2 for wireless connect")
def start(): if not running(): utils.execCmd([constants.EXT_SERVICE, 'ksmtuned', 'start'], sudo=True) utils.execCmd([constants.EXT_SERVICE, 'ksm', 'start'], sudo=True)