Extend supported actions with the 'snapshot' action, which is used
to snapshot an existing image. Also add 'setinfo' action as NOP.
Finally, refactor 'ReadEnv' function to return a dictionary instead of a
tuple.
-# Copyright (C) 2012 Greek Research and Technology Network
+# Copyright (C) 2012-2013 Greek Research and Technology Network
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
- """Read the enviromental variables
- """
-
+ """Read the enviromental variables"""
name = os.getenv("VOL_NAME")
if name is None:
sys.stderr.write('The environment variable VOL_NAME is missing.\n')
return None
name = os.getenv("VOL_NAME")
if name is None:
sys.stderr.write('The environment variable VOL_NAME is missing.\n')
return None
- size = os.getenv("VOL_SIZE")
- origin = os.getenv("EXTP_ORIGIN")
- return (name, size, origin)
+
+ return {"name": name,
+ "size": os.getenv("VOL_SIZE"),
+ "origin": os.getenv("EXTP_ORIGIN"),
+ "snapshot_name": os.getenv("VOL_SNAPSHOT_NAME"),
+ }
- """Create a new vlmc Image
- """
- name, size, origin = env
+ """Create a new vlmc Image."""
+ name = env.get("name")
+ size = env.get("size")
+ origin = env.get("origin")
+
+ sys.stderr.write("Creating volume '%s' of size '%s' from '%s'\n"
+ % (name, size, origin))
vlmc.create(name=name, size=int(size), snap=origin)
return 0
vlmc.create(name=name, size=int(size), snap=origin)
return 0
+def snapshot(env):
+ """Create a snapshot of an existing vlmc Image."""
+ name = env.get("name")
+ snapshot_name = env.get("snapshot_name")
+ sys.stderr.write("Creating snapshot '%s' from '%s'\n" %
+ (snapshot_name, name))
+ vlmc.snapshot(name=name, snap_name=snapshot_name)
+ return 0
+
+
def attach(env):
"""Map an existing vlmc Image to a block device
This function maps an existing vlmc Image to a block device
e.g. /dev/xsegbd{X} and returns the device path. If the mapping
already exists, it returns the corresponding device path.
def attach(env):
"""Map an existing vlmc Image to a block device
This function maps an existing vlmc Image to a block device
e.g. /dev/xsegbd{X} and returns the device path. If the mapping
already exists, it returns the corresponding device path.
# Check if the mapping already exists
d_id = vlmc.is_mapped(name)
# Check if the mapping already exists
d_id = vlmc.is_mapped(name)
This function unmaps an vlmc device from the Image it is mapped to.
It is idempotent if the mapping doesn't exist at all.
This function unmaps an vlmc device from the Image it is mapped to.
It is idempotent if the mapping doesn't exist at all.
#try:
# Check if the mapping already exists
#try:
# Check if the mapping already exists
- """Grow an existing vlmc Image
- """
- name, size, _ = env
+ """Grow an existing vlmc Image"""
+ name = env.get("name")
+ size = env.get("size")
+ sys.stderr.write("Resizing '%s'. New size '%s'\n" % (name, size))
vlmc.resize(name=name, size=int(size))
return 0
def remove(env):
vlmc.resize(name=name, size=int(size))
return 0
def remove(env):
- """ Delete a vlmc Image
- """
-
- name, _, _ = env
+ """Delete a vlmc Image"""
+ name = env.get("name")
+ sys.stderr.write("Deleting '%s'\n" % name)
vlmc.remove(name=name)
return 0
vlmc.remove(name=name)
return 0
+def setinfo(env):
+ return 0
+
+
def main():
env = ReadEnv()
if env is None:
def main():
env = ReadEnv()
if env is None:
- try:
- action = {
- 'attach': attach,
- 'create': create,
- 'detach': detach,
- 'grow': grow,
- 'remove': remove,
- 'verify': verify
- }[os.path.basename(sys.argv[0])]
- except:
- sys.stderr.write("Op not supported\n")
- return 1
+ actions = {
+ 'create': create,
+ 'snapshot': snapshot,
+ 'attach': attach,
+ 'detach': detach,
+ 'grow': grow,
+ 'remove': remove,
+ 'verify': verify,
+ 'setinfo': setinfo,
+ }
+ action_name = os.path.basename(sys.argv[0])
+ action = actions[action_name]
+ except KeyError:
+ sys.stderr.write("Action '%s' not supported\n" % action_name)
+ return 1
- sys.stderr.write(str(e) + '\n')
+ sys.stderr.write("Archipelago error: %s\n" % e)
return 1
if __name__ == "__main__":
return 1
if __name__ == "__main__":