1 # Copyright 2013 GRNET S.A. All rights reserved.
3 # Redistribution and use in source and binary forms, with or
4 # without modification, are permitted provided that the following
7 # 1. Redistributions of source code must retain the above
8 # copyright notice, this list of conditions and the following
11 # 2. Redistributions in binary form must reproduce the above
12 # copyright notice, this list of conditions and the following
13 # disclaimer in the documentation and/or other materials
14 # provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 # POSSIBILITY OF SUCH DAMAGE.
29 # The views and conclusions contained in the software and
30 # documentation are those of the authors and should not be
31 # interpreted as representing official policies, either expressed
32 # or implied, of GRNET S.A.
34 # shared funcs for both blockd and filed
36 import os, sys, shutil, glob, argparse
38 XSEG_HOME="/root/archip/xseg/"
40 XSEGBD_SYSFS="/sys/bus/xsegbd/"
41 DEVICE_PREFIX="/dev/xsegbd"
42 BLOCKD_LOGS="/root/archip_logs/"
48 print "name\t\t\t\tsize"
50 for f in glob.glob(IMAGES + '*'):
51 print "%s\t\t\t\t%dM" % (os.path.basename(f), os.stat(f).st_size / 1024 / 1024)
54 except Exception, reason:
55 print >> sys.stderr, reason
58 def vlmc_create(args):
63 if size == None and snap == None:
64 print >> sys.stderr, "At least one of the size/snap args must be provided"
82 if snap != None and size < os.stat(snap).st_size:
83 print >> sys.stderr, "Given size smaller than snapshot volume size"
87 shutil.copy(snap, name)
89 f = os.open(name, os.O_WRONLY)
91 f = os.open(name, os.O_CREAT | os.O_WRONLY, 0755)
94 os.lseek(f, size - 1, os.SEEK_SET)
100 except Exception, reason:
101 print >> sys.stderr, reason
104 def vlmc_remove(args):
108 old_dir = os.getcwd()
114 print "file doesn't exist"
118 os.unlink(IMAGES + '/' + name)
122 except Exception, reason:
123 print >> sys.stderr, reason
128 os.stat("/sys/bus/xsegbd")
129 except Exception, reason:
130 print >> sys.stderr, reason
133 def vlmc_resize(args):
138 old_dir = os.getcwd()
143 f = os.open(name, os.O_WRONLY, 0755)
144 if size >= os.stat(name).st_size:
145 os.lseek(f, size - 1, os.SEEK_SET)
148 os.ftruncate(f, size)
153 for f in os.listdir(XSEGBD_SYSFS + "devices/"):
154 d_id = open(XSEGBD_SYSFS + "devices/" + f + "/id").read().strip()
155 d_name = open(XSEGBD_SYSFS + "devices/"+ f + "/name").read().strip()
157 fd = os.open(XSEGBD_SYSFS + "devices/" + d_id +"/refresh", os.O_WRONLY)
162 except Exception, reason:
163 print >> sys.stderr, reason
170 execfile(os.path.expanduser("~/.xsegrc"), globals())
172 execfile(rc, globals())