Esempio n. 1
0
def main():
    try:
        if len(sys.argv)<2: raise Exception("Usage: stores.py <list>|<create>|<remove>|<publish>|<unpublish>")
        action=sys.argv[1]
        stores=LocalStoreList()
        if action=="list": stores.write(sys.stdout)
        elif action=="create": 
            if len(sys.argv)<4: raise Exception("Usage: stores.py create <disk> <type>")
            ret=stores.add(sys.argv[2], sys.argv[3])
            return xmlmsg("result", ret)
        elif action=="remove":
            if len(sys.argv)<3: raise Exception("Usage: stores.py remove <store>")
            ret=stores.remove(sys.argv[2],)
            return xmlmsg("result", ret)
        elif action=="publish":
            if len(sys.argv)<5: raise Exception("Usage: stores.py publish <store> <virtual host> <port> [redirect404]")
            redirect404=None
            if len(sys.argv)>5: redirect404=sys.argv[5]
            ret=stores.publish(sys.argv[2], sys.argv[3], sys.argv[4], redirect404)
            return xmlmsg("result", ret)
        elif action=="unpublish":
            if len(sys.argv)<3: raise Exception("Usage: stores.py unpublish <store>")
            ret=stores.unpublish(sys.argv[2])
            return xmlmsg("result", ret)
        else: raise Exception("Usage: stores.py <list>|<create>|<remove>|<publish>|<unpublish>")
    except Exception, e:
        return xmlmsg("error", str(e))
def main():
    try:
        if len(sys.argv) < 2:
            raise Exception("Usage: remotestores.py <list>|<create>|<remove>|<createDisk>|<removeDisk>")
        action = sys.argv[1]
        stores = StoreList()
        if action == "list":
            stores.write(sys.stdout)
        elif action == "create":
            if len(sys.argv) < 5:
                raise Exception("Usage: remotestores.py create <disk uuid> <store uuid> <type>")
            ret = stores.addStore(sys.argv[2], sys.argv[3], sys.argv[4])
            return xmlmsg("result", ret)
        elif action == "remove":
            if len(sys.argv) < 3:
                raise Exception("Usage: remotestores.py remove <store uuid>")
            ret = stores.removeStore(sys.argv[2])
            return xmlmsg("result", ret)
        elif action == "createDisk":
            if len(sys.argv) < 4:
                raise Exception("Usage: remotestores.py createDisk <disk uuid> <host>")
            ret = stores.addDisk(sys.argv[2], sys.argv[3])
            return xmlmsg("result", ret)
        elif action == "removeDisk":
            if len(sys.argv) < 3:
                raise Exception("Usage: remotestores.py removeDisk <disk uuid>")
            ret = stores.removeDisk(sys.argv[2])
            return xmlmsg("result", ret)
        else:
            raise Exception("Usage: stores.py <list>|<create>|<remove>|<createDisk>|<removeDisk>")
    except Exception, e:
        return xmlmsg("error", str(e))
Esempio n. 3
0
def main():
   if len(sys.argv)<2: return xmlmsg("error","Usage: prepare.py <device> [-f]. Example: prepare.py /dev/sdb")
   vol=volume(sys.argv[1])
   force=False
   if len(sys.argv)>2 and sys.argv[2]=="-f": force=True
   if vol.type<>"empty" and not force: return xmlmsg("error","Disk "+sys.argv[1]+" is not empty")
   (ok,errmsg)=vol.prepare()
   if ok==False: return xmlmsg("error",errmsg)
   else:
         (ok,errmsg2)=vol.mount()
         if ok==False: return xmlmsg("error",errmsg2)
         return xmlmsg("result",errmsg)
Esempio n. 4
0
def main():
   if len(sys.argv)<2: return xmlmsg("error","Usage: unmount.py <device>. Example: unmount.py /dev/sdc")
   dev=sys.argv[1]
   dir=None
   for line in open("/etc/mtab","r"):
        tab=line.split(" ")
        if len(tab)>1 and tab[0]==dev and tab[1][:16]=="/var/www/volumes": dir=tab[1]
   if dir==None: return xmlmsg("error","Not a node-data volume")
   (ok,errmsg)=tools.umount(dev)
  
  
   if ok<>0: return xmlmsg("error",str(errmsg))
   try:
     os.rmdir(dir)
   except Exception,e:
     return xmlmsg("error",str(e))
Esempio n. 5
0
def main():
   if len(sys.argv)<2: return xmlmsg("error","Usage: mount.py <device>|--all. Example: mount.py /dev/sdc")
   if sys.argv[1]=="--all": 
        out=fdisk.volumelist()
        mounted=0
        for disk in out.disks:
            vol=volume(disk.device)
            if vol.type<>"node-data": continue
            (ok, errmsg)=vol.mount()
            if ok: mounted=mounted+1
        return xmlmsg("return", str(mounted))
   else:
      vol=volume(sys.argv[1])
      if vol.type<>"node-data": return xmlmsg("error","Disk "+sys.argv[1]+" is of unknown type")
      (ok,errmsg)=vol.mount()
      if ok==False: return xmlmsg("error",str(errmsg))
      else: return xmlmsg("result",str(errmsg))
Esempio n. 6
0
def main():
    try:
        if len(sys.argv)<2: raise Exception("Usage: encoders.py <types>|<list>|<create>|<remove>")
        action=sys.argv[1]
        stores=EncodersList()
        if action=="list": stores.write(sys.stdout)
        elif action=="types": stores.writeTypes(sys.stdout)
        elif action=="create": 
            ret=stores.create(sys.stdin)
            return xmlmsg("result", ret)
        elif action=="remove":
            if len(sys.argv)<3: raise Exception("Usage: encoders.py remove <encoder>")
            ret=stores.remove(sys.argv[2],)
            return xmlmsg("result", ret)
        else: raise Exception("Usage: encoders.py <types>|<list>|<create>|<remove>")
    except Exception, e:
        return xmlmsg("error", str(e))
Esempio n. 7
0
def main():
    try:
        if len(sys.argv)<2: raise Exception("Usage: links.py <list>|<create>|<remove>|<modify>")
        action=sys.argv[1]
        links=Links()
        if action=="list": links.write(sys.stdout)
        elif action=="create": 
            if len(sys.argv)<8: raise Exception("Usage: links.py create <srcStore> <destStore> <srcAssetItem> <destAssertItem> <expireDate> <expireTime>")
            ret=links.add(sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5], sys.argv[6]+" "+sys.argv[7])
            return xmlmsg("result", "OK")
        elif action=="modify": 
            if len(sys.argv)<6: raise Exception("Usage: links.py modify <destStore> <destAssetItem> <expireDate> <expireTime>")
            ret=links.modify(sys.argv[2], sys.argv[3],  sys.argv[4]+" "+sys.argv[5])
            return xmlmsg("result", "OK")
        elif action=="remove":
            if len(sys.argv)<4: raise Exception("Usage: links.py remove <destStore> <destAssetItem>")
            ret=links.remove(sys.argv[2],sys.argv[3])
            return xmlmsg("result", "OK")
        else: raise Exception("Usage: links.py <list>|<create>|<remove>|<modify>")
    except Exception, e:
        return xmlmsg("error", str(e))
Esempio n. 8
0
def main():
    try:
        if len(sys.argv)<2: raise Exception("Usage: keys.py <get>|<authorize>|<unauthorize>")
        action=sys.argv[1]
        if action=="get":   # list  <status> <task guid>
          with open(PUBKEY, "r") as f:   return xmlmsg("result", f.read().split(" ")[1])
        elif action=="authorize":
            if len(sys.argv)<3: raise Exception("Usage: keys.py authorize <key>")
            found=False
            with open(KEYSTORE, "r+") as f: 
                for line in f:
                    if line.split(" ")[1]==sys.argv[2]: return xmlmsg("result", "0")
                f.write("ssh-rsa "+sys.argv[2]+" node\n")
            return xmlmsg("result", "1")
        elif action=="unauthorize":
            if len(sys.argv)<3: raise Exception("Usage: keys.py unauthorize <key>")
            with open(KEYSTORE, "r") as f: lines=[l for l in f.readlines() if l.split(" ")[1]<>sys.argv[2]]
            with open(KEYSTORE, "w") as f: f.writelines(lines)
            return xmlmsg("result", "OK")
        else: raise Exception("Usage: keys.py <get>|<authorize>|<unauthorize>")
    except Exception, e:
        return xmlmsg("error", str(e))
Esempio n. 9
0
def main():
    try:
        if len(sys.argv) < 2:
            raise Exception("Usage: queue.py <list>|<clear>|<remove>|<retry>")
        action = sys.argv[1]
        queue = XMLJobManager()
        if action == "list":  # list  <status> <task guid>
            status = None
            startTask = None
            try:
                if len(sys.argv) > 2:
                    status = int(sys.argv[2])
            except Exception, e:
                pass
            if len(sys.argv) > 3:
                startTask = sys.argv[3]
            queue.list(sys.stdout, status, startTask)
        elif action == "remove":
            if len(sys.argv) < 3:
                raise Exception("Usage: queue.py remove <workflow>")
            ret = queue.removeWorkflow(sys.argv[2])
            return xmlmsg("result", "OK")
Esempio n. 10
0
                    status = int(sys.argv[2])
            except Exception, e:
                pass
            if len(sys.argv) > 3:
                startTask = sys.argv[3]
            queue.list(sys.stdout, status, startTask)
        elif action == "remove":
            if len(sys.argv) < 3:
                raise Exception("Usage: queue.py remove <workflow>")
            ret = queue.removeWorkflow(sys.argv[2])
            return xmlmsg("result", "OK")
        elif action == "retry":
            if len(sys.argv) < 3:
                raise Exception("Usage: queue.py retry <workflow>")
            ret = queue.retryWorkflow(sys.argv[2])
            return xmlmsg("result", "OK")
        elif action == "clear":
            if len(sys.argv) < 3:
                raise Exception("Usage: queue.py clear <status>")
            if sys.argv[2].lower() == "all":
                ret = queue.clearAll()
            else:
                ret = queue.clear(int(sys.argv[2]))
            return xmlmsg("result", str(ret))
        else:
            raise Exception("Usage: stores.py <list>|<create>|<remove>|<retry>")
    except Exception, e:
        return xmlmsg("error", str(e))


main()
Esempio n. 11
0
                extra.setAttribute("action", "MOVE")
                extra.setAttribute("srcStore", task.attributes["srcStore"])
                if task.attributes.has_key("destAssetItem"):  extra.setAttribute("srcAssetItem", task.attributes["destAssetItem"])
                else: extra.setAttribute("srcAssetItem", task.attributes["srcAssetItem"])
                extra.setAttribute("destStore", store.uuid)
                doc.documentElement.insertBefore(extra, task.element.nextSibling)

        


try:
    workflow=parse(sys.stdin)
    if workflow.documentElement.tagName<>"workflow": raise Exception("Root tag should be workflow")
    if not workflow.documentElement.hasAttribute("guid"): workflow.documentElement.setAttribute("guid",  uuid4().get_hex())

    guid=workflow.documentElement.getAttribute("guid")
    with LockedFile(Config.QUEUEDIR+"/Queue.xml","r") as f:
        doc=parse(f)
    for wfnode in doc.getElementsByTagName("workflow"):
      oldguid=wfnode.getAttribute("guid")
      if guid==oldguid:  raise Exception("Duplicate workflow guid")
    verify(workflow)
    doc.documentElement.appendChild(workflow.documentElement)
    doc.documentElement.setAttribute("dateStart", "")
    doc.documentElement.setAttribute("dateFinished", "")
    with LockedFile(Config.QUEUEDIR+"/Queue.xml","w") as f:
        doc.writexml(f)
    xmlmsg("result", guid)
except Exception,   e:
    xmlmsg("error", str(e))
Esempio n. 12
0
from nodetools.tools import tools,xmlmsg
import sys
import os


def main():
   if len(sys.argv)<2: return xmlmsg("error","Usage: unmount.py <device>. Example: unmount.py /dev/sdc")
   dev=sys.argv[1]
   dir=None
   for line in open("/etc/mtab","r"):
        tab=line.split(" ")
        if len(tab)>1 and tab[0]==dev and tab[1][:16]=="/var/www/volumes": dir=tab[1]
   if dir==None: return xmlmsg("error","Not a node-data volume")
   (ok,errmsg)=tools.umount(dev)
  
  
   if ok<>0: return xmlmsg("error",str(errmsg))
   try:
     os.rmdir(dir)
   except Exception,e:
     return xmlmsg("error",str(e))
   return xmlmsg("result","OK")
   
   
 
 
if __name__=="__main__":
   main()