def remove_export(self, context, volume):
        """Removes an export for a logical volume."""
	print "Remove export for volume"
	remote = eqlscript.session (FLAGS.san_ip, FLAGS.san_login, FLAGS.san_password, False)
	# unassign volume
        # currently not necessary, because unrestricted
	remote.logout ()
    def delete_volume(self, volume):
        """Deletes a volume."""
	remote = eqlscript.session (FLAGS.san_ip, FLAGS.san_login, FLAGS.san_password, False)
		
#		result = remote.cmd ("vol delete %s" % (volume['name']))
#		result = remote.read_until ("Do you really want to delete the volume")
#		remote.write ("y\r")

	remote.logout ()
    def delete_snapshot(self, snapshot):
	#
        """Supports ensure_export and create_export"""
	remote = eqlscript.session (FLAGS.san_ip, FLAGS.san_login, FLAGS.san_password, False)
        # assign volume
        # currently not necessary, because unrestricted
	#result = remote.cmd ("show pool")

	#if remote.err ():
	#	raise exception.Error(_("error %s" % "".join (remote.err ())))

	print "".join(result)

	remote.logout ()
    def create_snapshot(self, snapshot):
	model_update = {}

	remote = eqlscript.session (FLAGS.san_ip, FLAGS.san_login, FLAGS.san_password, False)

	print ("Creating snapshot %s" % snapshot['name'])
	
	result = remote.cmd ("volume select %s clone %s description \"clone of volume %s\" unrestricted" % (snapshot['volume_name'], snapshot['name'], snapshot['volume_name']))
	if remote.err ():
		raise exception.Error(_("Failed to create snapshot %s of volume %s error %s" %  snapshot['name'], snapshot['volume_name'], "".join (remote.err ())))

	remote.logout ()

	return model_update
    def _do_export(self, context, volume, force_create):
	print "Do export for volume"

        """Supports ensure_export and create_export"""
	remote = eqlscript.session (FLAGS.san_ip, FLAGS.san_login, FLAGS.san_password, False)
        # assign volume
        # currently not necessary, because unrestricted
	result = remote.cmd ("show pool")

	#if remote.err ():
	#	raise exception.Error(_("error %s" % "".join (remote.err ())))

	print "".join(result)

	remote.logout ()

        model_update = {}
        return model_update
    def create_volume(self, volume):
	model_update = {}

	remote = eqlscript.session (FLAGS.san_ip, FLAGS.san_login, FLAGS.san_password, False)

	volName = volume['name']
		
	if int(volume['size']) == 0:
		volSize = '100MB'
        else:
		volSize = '%sGB' % volume['size']

	result = remote.cmd ("vol create %s %s %s unrestricted" % (volName, volSize, "thin-provision" if FLAGS.san_thin_provision else ""))
	print "".join(result)
	if remote.err ():
		print "".join(remote.err())
		raise exception.Error(_("Failed to create volume %s size %s with error %s" %  volName, volSize, "".join (remote.err ())))
	targre = re.compile (r"iscsi target name is\s+(.*)$", re.I | re.M)
	m = targre.search ("".join (result))
	if m:
		cluster_interface = '1'
		cluster_vip = FLAGS.san_ip
		iscsi_portal = cluster_vip + ":3260," + cluster_interface
		iscsi_iqn = m.group (1)
	
		model_update['provider_location'] = ("%s %s" %
							 (iscsi_portal,
							  iscsi_iqn))
										  
		#
		# Dump information about the volume
		#
		result = remote.cmd ("vol sel %s show" % volName)
		if remote.err ():
			raise exception.Error(_("Failed to show information about volume %s " %  volName, "".join (remote.err ())))

		remote.logout ()

		return model_update
    def create_volume_from_snapshot(self, volume, snapshot):
	model_update = {}

	remote = eqlscript.session (FLAGS.san_ip, FLAGS.san_login, FLAGS.san_password, False)

	print ("Creating volume %s from snapshot %s" % (volume['name'], snapshot['name']))
	
	result = remote.cmd ("volume select %s clone %s description \"clone of snapshot volume %s\" unrestricted" % (snapshot['name'], volume['name'], snapshot['volume_name']))
	if remote.err ():
		raise exception.Error(_("Failed to create volume %s of snapshot %s error %s" %  (volume['name'], snapshot['name'], "".join (remote.err ()))))
	print "".join(result)
	
	LOG.info("".join(result))
	
	targre = re.compile (r"is\s+([\w\d.-]+\:[0123456789abcdef]\-[0123456789abcdef]+\-[0123456789abcdef]+\-[0123456789abcdef]+\-[\w\d-]+)cloning", re.I | re.M)
	m = targre.search ("".join(result))
	if m:
		cluster_interface = '1'
		cluster_vip = FLAGS.san_ip
		iscsi_portal = cluster_vip + ":3260," + cluster_interface
		iscsi_iqn = m.group (1)
	
		model_update['provider_location'] = ("%s %s" %
							 (iscsi_portal,
							  iscsi_iqn))

		#
		# Dump information about the volume
		#
		result = remote.cmd ("vol sel %s show" % volume['name'])
		if remote.err ():
			raise exception.Error(_("Failed to show information about volume %s " %  volName, "".join (remote.err ())))

		remote.logout ()

		return model_update
        # currently not necessary, because unrestricted
	result = remote.cmd ("show pool")

	#if remote.err ():
	#	raise exception.Error(_("error %s" % "".join (remote.err ())))

	print "".join(result)

	remote.logout ()

        model_update = {}
        return model_update

    def remove_export(self, context, volume):
        """Removes an export for a logical volume."""
	print "Remove export for volume"
	remote = eqlscript.session (FLAGS.san_ip, FLAGS.san_login, FLAGS.san_password, False)
	# unassign volume
        # currently not necessary, because unrestricted
	remote.logout ()

if __name__ == "__main__":
	utils.default_flagfile()
	flags.FLAGS(sys.argv)
	logging.setup()
	print FLAGS.san_ip
  	"""Supports ensure_export and create_export"""
	remote = eqlscript.session (FLAGS.san_ip, FLAGS.san_login, FLAGS.san_password, False)
	remote.logout ()

Esempio n. 9
0
        telnet = True
        
if user == "root":
    print "Error: username cannot be root"
    sys.exit (1)

if not group or (not fn and not args):
    usage (1)
if not pwd:
    pwd = getpass.getpass ("Password: "******"Error connecting to group address", group
    sys.exit (1)
except eqlscript.LoginError:
    print "Error logging in to username", user
    sys.exit (1)
    
# Send the command, if just one, or the string of command from the file
if fn:
    cmds = file (fn, "r")
else:
    cmds = ( " ".join (args), )

for c in cmds:
    if debug: