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 #!/usr/bin/env python2.7
38 from vlmc_shared import *
39 import os, sys, subprocess, argparse
46 result = [int(open(XSEGBD_SYSFS + "devices/" + f + "/srcport").read().strip()) for f in os.listdir(XSEGBD_SYSFS + "devices/")]
56 fd = os.open(XSEGBD_SYSFS + "add", os.O_WRONLY)
57 os.write(fd, "%s %d:%d:%d" % (name, port, FILED_PORT, REQS))
59 except Exception, reason:
60 print >> sys.stderr, reason
67 for f in os.listdir(XSEGBD_SYSFS + "devices/"):
68 d_id = open(XSEGBD_SYSFS + "devices/" + f + "/id").read().strip()
69 name = open(XSEGBD_SYSFS + "devices/"+ f + "/target").read().strip()
70 if device == DEVICE_PREFIX + d_id:
71 fd = os.open(XSEGBD_SYSFS + "remove", os.O_WRONLY)
76 print >> sys.stderr, "Device %s doesn't exist" % device
78 except Exception, reason:
79 print >> sys.stderr, reason
82 def vlmc_showmapped(args):
84 print "id\tpool\timage\tsnap\tdevice"
86 for f in os.listdir(XSEGBD_SYSFS + "devices/"):
87 d_id = open(XSEGBD_SYSFS + "devices/" + f + "/id").read().strip()
88 target = open(XSEGBD_SYSFS + "devices/"+ f + "/target").read().strip()
90 print "%s\t%s\t%s\t%s\t%s" % (d_id, '-', target, '-', DEVICE_PREFIX +
92 except Exception, reason:
93 print >> sys.stderr, reason
96 if __name__ == "__main__":
97 # parse arguments and discpatch to the correct func
98 parser = argparse.ArgumentParser(description='vlmc tool')
99 parser.add_argument('-c', '--config', type=str, nargs='?', help='config file')
100 subparsers = parser.add_subparsers()
102 create_parser = subparsers.add_parser('create', help='Create volume')
103 #group = create_parser.add_mutually_exclusive_group(required=True)
104 create_parser.add_argument('-s', '--size', type=int, nargs='?', help='requested size in MB for create')
105 create_parser.add_argument('--snap', type=str, nargs='?', help='create from snapshot')
106 create_parser.add_argument('-p', '--pool', type=str, nargs='?', help='for backwards compatiblity with rbd')
107 create_parser.add_argument('name', type=str, nargs=1, help='volume/device name')
108 create_parser.set_defaults(func=vlmc_create)
110 remove_parser = subparsers.add_parser('remove', help='Delete volume')
111 remove_parser.add_argument('name', type=str, nargs=1, help='volume/device name')
112 remove_parser.set_defaults(func=vlmc_remove)
113 remove_parser.add_argument('-p', '--pool', type=str, nargs='?', help='for backwards compatiblity with rbd')
115 rm_parser = subparsers.add_parser('rm', help='Delete volume')
116 rm_parser.add_argument('name', type=str, nargs=1, help='volume/device name')
117 rm_parser.set_defaults(func=vlmc_remove)
118 rm_parser.add_argument('-p', '--pool', type=str, nargs='?', help='for backwards compatiblity with rbd')
120 map_parser = subparsers.add_parser('map', help='Map volume')
121 map_parser.add_argument('name', type=str, nargs=1, help='volume/device name')
122 map_parser.set_defaults(func=vlmc_map)
123 map_parser.add_argument('-p', '--pool', type=str, nargs='?', help='for backwards compatiblity with rbd')
125 unmap_parser = subparsers.add_parser('unmap', help='Unmap volume')
126 unmap_parser.add_argument('name', type=str, nargs=1, help='volume/device name')
127 unmap_parser.set_defaults(func=vlmc_unmap)
128 unmap_parser.add_argument('-p', '--pool', type=str, nargs='?', help='for backwards compatiblity with rbd')
130 showmapped_parser = subparsers.add_parser('showmapped', help='Show mapped volumes')
131 showmapped_parser.set_defaults(func=vlmc_showmapped)
132 showmapped_parser.add_argument('-p', '--pool', type=str, nargs='?', help='for backwards compatiblity with rbd')
134 list_parser = subparsers.add_parser('list', help='List volumes')
135 list_parser.set_defaults(func=vlmc_list)
136 list_parser.add_argument('-p', '--pool', type=str, nargs='?', help='for backwards compatiblity with rbd')
138 ls_parser = subparsers.add_parser('ls', help='List volumes')
139 ls_parser.set_defaults(func=vlmc_list)
140 ls_parser.add_argument('-p', '--pool', type=str, nargs='?', help='for backwards compatiblity with rbd')
142 resize_parser = subparsers.add_parser('resize', help='Resize volume')
143 resize_parser.add_argument('-s', '--size', type=int, nargs=1, help='requested size in MB for resize')
144 resize_parser.add_argument('name', type=str, nargs=1, help='volume/device name')
145 resize_parser.set_defaults(func=vlmc_resize)
146 resize_parser.add_argument('-p', '--pool', type=str, nargs='?', help='for backwards compatiblity with rbd')
148 args = parser.parse_args()