Example #1
0
def run(task, cmd):
    code, output = commands.getstatusoutput(cmd)
    if code != 0:
        log("%s: %s exitted with code %d: %s" % (task, cmd, code, output))
        raise BackendError
    log("%s: %s" % (task, cmd))
    return output
Example #2
0
def run(task, cmd):
    code, output = commands.getstatusoutput(cmd)
    if code <> 0:
        log("%s: %s exitted with code %d: %s" % (task, cmd, code, output))
        raise (BackendError("command failed", [str(code), output]))
    log("%s: %s" % (task, cmd))
    return output
Example #3
0
def run(task, cmd):
    code, output = commands.getstatusoutput(cmd)
    if code <> 0:
        log("%s: %s exitted with code %d: %s" % (task, cmd, code, output))
        raise (BackendError("command failed", [ str(code), output ]))
    log("%s: %s" % (task, cmd))
    return output
Example #4
0
 def sr_scan(self, task, sr):
     global root
     log("scanning")
     results = []
     for name in os.listdir(root):
         if name.endswith(metadata_suffix):
             path = root + "/" + name
             f = open(path, "r")
             try:
                 vdi_info = json.loads(f.read())
                 results.append(smapiv2.make_vdi_info(vdi_info))
             finally:
                 f.close()
     return results
Example #5
0
 def sr_scan(self, task, sr):
     global root
     log("scanning")
     results = []
     for name in os.listdir(root):
         if name.endswith(metadata_suffix):
             path = root + "/" + name
             f = open(path, "r")
             try:
                 vdi_info = json.loads(f.read())
                 results.append(smapiv2.make_vdi_info(vdi_info))
             finally:
                 f.close()
     return results
Example #6
0
 def vdi_attach(self, task, dp, sr, vdi, read_write):
     path = path_of_vdi(vdi) + disk_suffix
     loop = self.device.add(task, path)
     log("loop = %s" % repr(loop))
     return loop
Example #7
0
                      "--ip-addr",
                      dest="ip",
                      help="listen on IP",
                      metavar="IP")
    parser.add_option("-d",
                      "--daemon",
                      action="store_true",
                      dest="daemon",
                      help="run as a background daemon",
                      metavar="DAEMON")
    (options, args) = parser.parse_args()
    if options.logfile:
        from smapiv2 import reopenlog
        reopenlog(options.logfile)
    if not options.ip and not options.ip:
        print >> sys.stderr, "Need an --ip-addr and --port. Use -h for help"
        sys.exit(1)

    ip = options.ip
    port = int(options.port)

    arch = run("startup", "uname")
    if arch == "Linux":
        log("startup: Using loop devices")
        start(RawFiles(Loop()), ip, port, options.daemon)
    elif arch == "FreeBSD":
        log("startup: Using mdconfig devices")
        start(RawFiles(Mdconfig()), ip, port, options.daemon)
    else:
        log("startup: Unknown architecture: %s" % arch)
Example #8
0
 def vdi_attach(self, task, dp, sr, vdi, read_write):
     path = path_of_vdi(vdi) + disk_suffix
     loop = self.device.add(task, path)
     log("loop = %s" % repr(loop))
     return loop
Example #9
0
        self.device.remove(task, path)
        
if __name__ == "__main__":
    from optparse import OptionParser

    parser = OptionParser()
    parser.add_option("-l", "--log", dest="logfile", help="log to LOG", metavar="LOG")
    parser.add_option("-p", "--port", dest="port", help="listen on PORT", metavar="PORT")
    parser.add_option("-i", "--ip-addr", dest="ip", help="listen on IP", metavar="IP")
    parser.add_option("-d", "--daemon", action="store_true", dest="daemon", help="run as a background daemon", metavar="DAEMON")
    (options, args) = parser.parse_args()
    if options.logfile:
        from smapiv2 import reopenlog
        reopenlog(options.logfile)
    if not options.ip and not options.ip:
        print >>sys.stderr, "Need an --ip-addr and --port. Use -h for help"
        sys.exit(1)

    ip = options.ip
    port = int(options.port)

    arch = run("startup", "uname")
    if arch == "Linux":
        log("startup: Using loop devices")
        start(RawFiles(Loop()), ip, port, options.daemon)
    elif arch == "FreeBSD":
        log("startup: Using mdconfig devices")
        start(RawFiles(Mdconfig()), ip, port, options.daemon)
    else:
        log("startup: Unknown architecture: %s" % arch)