def verify(doc): mng=XMLJobManager() slist=StoreList() llist=LocalStoreList() mng.registerPlugins() workflow=XMLWorkflow(doc.documentElement) for task in workflow.tasks: exc=getTaskExecutor(mng, task) if task.attributes.has_key("destStore"): store=llist.getByUuid(task.attributes["destStore"]) if store<>None: continue store=slist.getByUuid(task.attributes["destStore"]) if store==None: raise Exception("Unknown destination store") # oops, requested remote destination store and executor does not support it # change destination store to local one and add MOVE task after that if not exc.supportsRemoteDestination: task.element.setAttribute("destStore", task.attributes["srcStore"]) extra=doc.createElement("task") extra.setAttribute("guid", uuid4().get_hex()) 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)
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))
def __init__(self,reporter, workflow,task, move): super(CopyMoveExecutor, self).__init__(reporter, workflow, task) slist=LocalStoreList() self.move=move self.srcassetuid=task.attributes["srcAssetItem"] self.dstassetuid=task.attributes["srcAssetItem"] if task.attributes.has_key("destAssetItem"): self.dstassetuid=task.attributes["destAssetItem"] self.overwrite=False if task.attributes.has_key("overwrite"): self.overwrite=(task.attributes["overwrite"].lower()=="true") self.srcasset=slist.getByUuid(task.attributes["srcStore"]).findAsset(task.attributes["srcAssetItem"]) self.targetstore=slist.getByUuid(task.attributes["destStore"]) self.isLocal=True if self.targetstore==None: self.isLocal=False slist2=StoreList() self.targetstore=slist2.getByUuid(task.attributes["destStore"]) if self.targetstore==None: raise Exception("Unknown destination store") self.desthost=slist2.getDisk(self.targetstore.diskuuid).host