Exemple #1
0
	def run(self, params, args):
		(args, nas, zpool, volume, remotehost, size) = self.fillPositionalArgs(
				('nas', 'zpool', 'volume', 'remotehost', 'size'))

		sync,remotepool, = self.fillParams( [('img_sync', None),('remotepool',None)] )

		if not nas or not zpool or not volume or not remotehost or not size:
			self.abort("you must pass 5 arguments nas_name zpool volume remotehost size")

		if sync is None:
			sync =  self.db.getHostAttr(remotehost,'img_sync')

		sync = False if sync is None else self.str2bool(sync)

		if sync and remotepool is None:
			self.abort("img_sync was true but not remotepool was specified")

		# debugging output
		print "mapping ", nas, ":", zpool, "/", volume, " on ", remotehost

		launcher = CommandLauncher()
		initiator = launcher.callListInitiator(remotehost)
		device = launcher.callAddHostStoragemap(nas, zpool, volume, remotehost, remotepool, size, sync,initiator)
		self.beginOutput()
		self.addOutput(nas, device)
		self.endOutput(padChar='')
    def run(self, node):
        # here you can relocate your VM in rocks DB
        # node is of type rocks.db.mappings.base.Node
        if not node.vm_defs.physNode or len(node.vm_defs.disks) <= 0:
            raise rocks.util.CommandError("Unable to allocate " + \
             "storage for " + node.name)
        disk = node.vm_defs.disks[0]
        phys = node.vm_defs.physNode.name
        sync = self.owner.str2bool(self.db.getHostAttr(phys, 'img_sync'))
        sync_virt = self.db.getHostAttr(node.name, 'img_sync')
        if (sync_virt is not None):
            sync = sync and self.owner.str2bool(sync_virt)
        remotepool = self.db.getHostAttr(phys, 'vm_container_zpool')
        size = str(disk.size)
        volume = node.name + '-vol'
        if not (disk.img_nas_server and disk.img_nas_server.server_name):
            # the node does not use img-storage system
            return
        nas_name = disk.img_nas_server.server_name
        zpool_name = disk.img_nas_server.zpool_name
        # nas, zpool, volume, remotehost, remotepool, size, sync,
        launcher = CommandLauncher()
        initiator = launcher.callListInitiator(phys)
        device = launcher.callAddHostStoragemap(nas_name, zpool_name, volume,
                                                phys, remotepool, size, sync,
                                                initiator)

        disk.vbd_type = "phy"
        disk.prefix = os.path.dirname(device)
        disk.name = os.path.basename(device)
        print nas_name + ":" + volume + " mapped to " + phys + ":" + device
        return