+# Copyright 2013 GRNET S.A. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or
+# without modification, are permitted provided that the following
+# conditions are met:
+#
+# 1. Redistributions of source code must retain the above
+# copyright notice, this list of conditions and the following
+# disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following
+# disclaimer in the documentation and/or other materials
+# provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# The views and conclusions contained in the software and
+# documentation are those of the authors and should not be
+# interpreted as representing official policies, either expressed
+# or implied, of GRNET S.A.
+
#!/usr/bin/env python2.7
#
# vlmc tool for filed
-import os, sys, subprocess, shutil, re, argparse
-
-XSEG_HOME="/root/archip/xseg/"
-IMAGES="/srv/pithos/archip-data/images/"
-XSEGBD_SYSFS="/sys/bus/xsegbd/"
-DEVICE_PREFIX="/dev/xsegbd"
-BLOCKD_LOGS="/root/logs/"
-FILED_PORT=0
-
-def vlmc_list(args):
- print "name\t\t\t\tsize"
- try:
- for f in os.listdir(IMAGES):
- print "%s\t\t\t\t%dM" % (f, os.stat(IMAGES + f).st_size / 1024 / 1024)
-
- sys.exit(0)
- except Exception, reason:
- print >> sys.stderr, reason
- sys.exit(-1)
-
-def vlmc_create(args):
- name = args.name[0]
- size = args.size
- snap = args.snap
-
- try:
- old_dir = os.getcwd()
- os.chdir(IMAGES)
-
- try:
- os.stat(name)
- print "file exists"
- os.chdir(old_dir)
- sys.exit(-1)
- except:
- pass
-
- if snap:
- shutil.copyfile(snap, name)
- else:
- f = os.open(name, os.O_CREAT | os.O_WRONLY, 0755)
- size *= 1024*1024
- os.lseek(f, size - 1, os.SEEK_SET)
- os.write(f, "1")
- os.close(f)
-
- os.chdir(old_dir)
- sys.exit(0)
- except Exception, reason:
- print >> sys.stderr, reason
- sys.exit(-1)
-
-def vlmc_remove(args):
- name = args.name[0]
-
- try:
- old_dir = os.getcwd()
- os.chdir(IMAGES)
-
- try:
- os.stat(name)
- except:
- print "file doesn't exist"
- os.chdir(old_dir)
- sys.exit(-1)
-
- os.unlink(IMAGES + '/' + name)
-
- os.chdir(old_dir)
- sys.exit(0)
- except Exception, reason:
- print >> sys.stderr, reason
- sys.exit(-1)
+from vlmc_shared import *
+import os, sys, subprocess, argparse
def vlmc_map(args):
+ xsegbd_loaded()
name = args.name[0]
prev = 0
try:
result = [int(open(XSEGBD_SYSFS + "devices/" + f + "/srcport").read().strip()) for f in os.listdir(XSEGBD_SYSFS + "devices/")]
result.sort()
- for p in result:
+ for p in result:
if p - prev > 1:
break
else:
port = prev + 1
fd = os.open(XSEGBD_SYSFS + "add", os.O_WRONLY)
- os.write(fd, "%s %d:%d:128" % (name, port, FILED_PORT))
+ os.write(fd, "%s %d:%d:%d" % (name, port, FILED_PORT, REQS))
os.close(fd)
except Exception, reason:
print >> sys.stderr, reason
sys.exit(-1)
def vlmc_unmap(args):
+ xsegbd_loaded()
device = args.name[0]
try:
for f in os.listdir(XSEGBD_SYSFS + "devices/"):
d_id = open(XSEGBD_SYSFS + "devices/" + f + "/id").read().strip()
- name = open(XSEGBD_SYSFS + "devices/"+ f + "/name").read().strip()
+ name = open(XSEGBD_SYSFS + "devices/"+ f + "/target").read().strip()
if device == DEVICE_PREFIX + d_id:
fd = os.open(XSEGBD_SYSFS + "remove", os.O_WRONLY)
os.write(fd, d_id)
os.close(fd)
- break
+ sys.exit(0)
+ print >> sys.stderr, "Device %s doesn't exist" % device
+ sys.exit(-1)
except Exception, reason:
print >> sys.stderr, reason
sys.exit(-1)
def vlmc_showmapped(args):
+ xsegbd_loaded()
print "id\tpool\timage\tsnap\tdevice"
try:
for f in os.listdir(XSEGBD_SYSFS + "devices/"):
d_id = open(XSEGBD_SYSFS + "devices/" + f + "/id").read().strip()
- name = open(XSEGBD_SYSFS + "devices/"+ f + "/name").read().strip()
+ target = open(XSEGBD_SYSFS + "devices/"+ f + "/target").read().strip()
- print "%s\t%s\t%s\t%s\t%s" % (d_id, '-', name, '-', DEVICE_PREFIX +
+ print "%s\t%s\t%s\t%s\t%s" % (d_id, '-', target, '-', DEVICE_PREFIX +
d_id)
except Exception, reason:
print >> sys.stderr, reason
subparsers = parser.add_subparsers()
create_parser = subparsers.add_parser('create', help='Create volume')
- group = create_parser.add_mutually_exclusive_group(required=True)
- group.add_argument('-s', '--size', type=int, nargs='?', help='requested size in MB for create')
- group.add_argument('--snap', type=str, nargs='?', help='create from snapshot')
+ #group = create_parser.add_mutually_exclusive_group(required=True)
+ create_parser.add_argument('-s', '--size', type=int, nargs='?', help='requested size in MB for create')
+ create_parser.add_argument('--snap', type=str, nargs='?', help='create from snapshot')
create_parser.add_argument('-p', '--pool', type=str, nargs='?', help='for backwards compatiblity with rbd')
create_parser.add_argument('name', type=str, nargs=1, help='volume/device name')
create_parser.set_defaults(func=vlmc_create)
ls_parser.set_defaults(func=vlmc_list)
ls_parser.add_argument('-p', '--pool', type=str, nargs='?', help='for backwards compatiblity with rbd')
- args = parser.parse_args()
-
- #FIXME
- try:
- if args.config == None:
- execfile(os.path.expanduser("~/.xsegrc"))
- else:
- execfile(args.config)
- except:
- pass
+ resize_parser = subparsers.add_parser('resize', help='Resize volume')
+ resize_parser.add_argument('-s', '--size', type=int, nargs=1, help='requested size in MB for resize')
+ resize_parser.add_argument('name', type=str, nargs=1, help='volume/device name')
+ resize_parser.set_defaults(func=vlmc_resize)
+ resize_parser.add_argument('-p', '--pool', type=str, nargs='?', help='for backwards compatiblity with rbd')
+ args = parser.parse_args()
+ loadrc(args.config)
args.func(args)