3 # Copyright (C) 2012 Greek Research and Technology Network
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 """ vlmc provider wrapper-script for ganeti extstorage disk template
22 The script takes it's input from environment variables. Specifically the
23 following variables should be present:
25 - VOL_NAME: The name of the new Image file
26 - VOL_SIZE: The size of the new Image (in megabytes)
28 The following variables are optional:
30 - EXTP_ORIGIN: The name of the Image file to snapshot
32 The code branches to the correct function, depending on the name (sys.argv[0])
33 of the executed script (attach, create, etc).
35 Returns O after successfull completion, 1 on failure
42 from archipelago.common import Error, DEVICE_PREFIX, loadrc
43 from archipelago import vlmc as vlmc
47 """Read the enviromental variables
50 name = os.getenv("VOL_NAME")
52 sys.stderr.write('The environment variable VOL_NAME is missing.\n')
54 size = os.getenv("VOL_SIZE")
55 origin = os.getenv("EXTP_ORIGIN")
56 return (name, size, origin)
60 """Create a new vlmc Image
62 name, size, origin = env
63 vlmc.create(name=name, size=int(size), snap=origin)
68 """Map an existing vlmc Image to a block device
70 This function maps an existing vlmc Image to a block device
71 e.g. /dev/xsegbd{X} and returns the device path. If the mapping
72 already exists, it returns the corresponding device path.
77 # Check if the mapping already exists
78 d_id = vlmc.is_mapped(name)
80 # The mapping exists. Return it.
81 sys.stdout.write("%s" % str(DEVICE_PREFIX + str(d_id)))
83 # The mapping doesn't exist. Create it.
84 d_id = vlmc.map_volume(name=name)
85 # The device was successfully mapped. Return it.
86 #maybe assert (d_id == vlmc.is_mapped(name)
87 sys.stdout.write("%s" % str(DEVICE_PREFIX + str(d_id)))
92 """Unmap a vlmc device from the Image it is mapped to
94 This function unmaps an vlmc device from the Image it is mapped to.
95 It is idempotent if the mapping doesn't exist at all.
100 # Check if the mapping already exists
101 d_id = vlmc.is_mapped(name)
103 # The mapping exists. Unmap the vlmc device.
104 vlmc.unmap_volume(name=str(DEVICE_PREFIX + str(d_id)))
105 #assert(vlmc.is_mapped(name) == None)
108 # sys.stderr.write(str(e)+'\n')
113 """Grow an existing vlmc Image
117 vlmc.resize(name=name, size=int(size))
122 """ Delete a vlmc Image
127 vlmc.remove(name=name)
138 sys.stderr.write("Wrong environment. Aborting...\n")
151 }[os.path.basename(sys.argv[0])]
153 sys.stderr.write("Op not supported\n")
159 sys.stderr.write(str(e) + '\n')
162 if __name__ == "__main__":