Permalink
Browse files

Support code for our newest and bestest partitioning.

If you want to use this code on a running system, you'll need to execute:

echo "alter table storage_partition add column PartID         int(11) NOT NULL;" | /opt/stack/bin/mysql -u root -p cluster

I had to add a column to the storage_partition table.
  • Loading branch information...
1 parent 7f5c452 commit 04a28d346ab5bf594290e42975f985c95bd857f9 @gregorybruno gregorybruno committed Dec 21, 2016
@@ -451,6 +451,7 @@ CREATE TABLE storage_partition (
Mountpoint varchar(128) NOT NULL default '',
Size int(11) NOT NULL,
FsType varchar(128) NOT NULL default '',
+ PartID int(11) NOT NULL,
Options varchar(512) NOT NULL default ''
);
@@ -73,6 +73,11 @@ class Command(stack.commands.HostArgumentProcessor,
<param type='string' name='options' optional='0'>
Options that need to be supplied while adding partitions.
</param>
+
+ <param type='string' name='partid' optional='1'>
+ The relative partition id for this partition. Partitions will be
+ created in ascending partition id order.
+ </param>
<example cmd='add storage partition compute-0-0 device=sda mountpoint=/var
size=50 type=ext4'>
@@ -156,18 +161,18 @@ def run(self, params, args):
else:
name = args[0]
- device, size, fstype, mountpt, options = self.fillParams([
- ('device', None, True),
- ('size', None),
- ('type', None),
- ('mountpoint', None, True),
- ('options', None)
- ])
+ device, size, fstype, mountpt, options, partid = \
+ self.fillParams([
+ ('device', None, True),
+ ('size', None),
+ ('type', None),
+ ('mountpoint', None),
+ ('options', None),
+ ('partid', None),
+ ])
if not device:
raise ParamRequired(self, 'device')
- if not mountpt:
- raise ParamRequired(self, 'mountpoint')
# Validate size
if size:
@@ -184,6 +189,18 @@ def run(self, params, args):
if s < 0:
raise ParamValue(self, 'size', '>= 0')
+ # Validate partid
+ if partid:
+ try:
+ p = int(partid)
+ except:
+ partid = None
+
+ if p < 1:
+ raise ParamValue(self, 'partid', '>= 0')
+
+ partid = p
+
#
# look up the id in the appropriate 'scope' table
#
@@ -202,16 +219,22 @@ def run(self, params, args):
#
# make sure the specification for mountpt doesn't already exist
#
- self.checkIt(device, scope, tableid, mountpt)
+ if mountpt:
+ self.checkIt(device, scope, tableid, mountpt)
if not options:
options = ""
#
# now add the specifications to the database
#
+ sqlvars = "Scope, TableID, device, Mountpoint, Size, FsType, Options"
+ sqldata = "'%s', %s, '%s', '%s', %s, '%s', '%s'" % \
+ (scope, tableid, device, mountpt, size, fstype, options)
+
+ if partid:
+ sqlvars += ", PartID"
+ sqldata += ", %s" % partid
+
self.db.execute("""insert into storage_partition
- (Scope, TableID, device, Mountpoint,
- Size, FsType, Options) values ('%s', %s, '%s', '%s',
- %s, '%s', '%s') """ % (scope, tableid, device,
- mountpt, size, fstype, options))
+ (%s) values (%s) """ % (sqlvars, sqldata))
@@ -125,21 +125,21 @@ def run(self, params, args):
query = None
if scope == 'global':
if globalOnlyFlag:
- query = """select scope, device, mountpoint, size, fstype, options
+ query = """select scope, device, mountpoint, size, fstype, options, partid
from storage_partition
where scope = 'global'
order by fstype, size"""
else:
- query = """(select scope, device, mountpoint, size, fstype, options
+ query = """(select scope, device, mountpoint, size, fstype, options, partid
from storage_partition
where scope = 'global'
order by fstype, size) UNION ALL
(select a.name, p.device, p.mountpoint, p.size,
- p.fstype, p.options from storage_partition as p inner join
+ p.fstype, p.options, p.partid from storage_partition as p inner join
nodes as a on p.tableid=a.id where p.scope='host'
order by p.fstype, p.size) UNION ALL
(select a.name, p.device, p.mountpoint, p.size,
- p.fstype, p.options from storage_partition as p inner join
+ p.fstype, p.options, p.partid from storage_partition as p inner join
appliances as a on p.tableid=a.id where
p.scope='appliance' order by p.fstype, p.size)"""
elif scope == 'os':
@@ -148,13 +148,13 @@ def run(self, params, args):
#
return
elif scope == 'appliance':
- query = """select scope, device, mountpoint, size, fstype,
- options from storage_partition where scope = "appliance"
+ query = """select scope, device, mountpoint, size, fstype, options, partid
+ from storage_partition where scope = "appliance"
and tableid = (select id from appliances
where name = '%s') order by fstype, size""" % args[0]
elif scope == 'host':
- query = """select scope, device, mountpoint, size, fstype,
- options from storage_partition where scope="host" and
+ query = """select scope, device, mountpoint, size, fstype, options, partid
+ from storage_partition where scope="host" and
tableid = (select id from nodes
where name = '%s') order by fstype, size""" % args[0]
@@ -167,16 +167,27 @@ def run(self, params, args):
i = 0
for row in self.db.fetchall():
- name, device, mountpoint, size, fstype, options = row
+ name, device, mountpoint, size, fstype, options, partid = row
if size == -1:
size = "recommended"
elif size == -2:
size = "hibernation"
+
if name == "host" or name == "appliance":
name = args[0]
- self.addOutput(name, [ device, mountpoint,
- size, fstype, options])
+
+ if mountpoint == 'None':
+ mountpoint = None
+
+ if fstype == 'None':
+ fstype = None
+
+ if partid == 0:
+ partid = None
+
+ self.addOutput(name, [device, partid, mountpoint,
+ size, fstype, options, partid])
i += 1
- self.endOutput(header=['scope', 'device', 'mountpoint', 'size',
- 'fstype', 'options'], trimOwner = 0)
+
+ self.endOutput(header=['scope', 'device', 'partid', 'mountpoint', 'size', 'fstype', 'options'], trimOwner = 0)
@@ -55,22 +55,18 @@ class Implementation(stack.commands.ApplianceArgumentProcessor,
a comma-separated formatted file.
"""
- def doit(self, host, device, mountpoint, size, fstype, options, line):
+ def doit(self, host, device, partid, mountpoint, size, fstype,
+ options, line):
+
#
# error checking
#
if device == None:
msg = 'empty value found for "device" column at line %d' % line
raise CommandError(self.owner, msg)
- if mountpoint == None:
- msg = 'empty value found for "mountpoint" column at line %d' % line
- raise CommandError(self.owner, msg)
if size == None:
msg = 'empty value found for "size" column at line %d' % line
raise CommandError(self.owner, msg)
- if fstype == None or fstype == 'None':
- msg = 'empty value found for "type" column at line %d' % line
- raise CommandError(self.owner, msg)
if host not in self.owner.hosts.keys():
self.owner.hosts[host] = {}
@@ -84,6 +80,7 @@ def doit(self, host, device, mountpoint, size, fstype, options, line):
partition_detail_map['size'] = size
partition_detail_map['type'] = fstype
partition_detail_map['options'] = options
+ partition_detail_map['partid'] = partid
# Append partition info to the map
partitions_list.append(partition_detail_map)
@@ -96,11 +93,12 @@ def run(self, args):
reader = stack.csv.reader(open(filename, 'rU'))
header = None
- line = 0
name = None
type_dict = {}
+ rowid = 1
+ line = 0
for row in reader:
line += 1
@@ -110,7 +108,7 @@ def run(self, args):
#
# make checking the header easier
#
- required = ['name', 'device', 'mountpoint', 'size', 'type']
+ required = ['name', 'device', 'size' ]
for i in range(0, len(row)):
if header[i] in required:
@@ -121,12 +119,15 @@ def run(self, args):
raise CommandError(self.owner, msg)
continue
-
+
+ rowid += 1
+
device = None
- mountpoint = None
+ mountpoint = ''
size = None
- type = None
+ type = ''
options = None
+ partid = None
for i in range(0, len(row)):
field = row[i]
@@ -136,6 +137,12 @@ def run(self, args):
if header[i] == 'name':
name = field.lower()
+ #
+ # every time the name changes, reset
+ # the rowid
+ #
+ rowid = 1
+
elif header[i] == 'device':
device = field.lower()
@@ -160,7 +167,15 @@ def run(self, args):
type = field.lower()
elif header[i] == 'options':
options = field
-
+ elif header[i] == 'partid':
+ try:
+ partid = int(field)
+ if partid < 1:
+ msg = 'partid "%d" must be 1 or greater' % partid
+ raise CommandError(self.owner, msg)
+ except:
+ pass
+
#
# the first non-header line must have a host name
#
@@ -177,8 +192,11 @@ def run(self, args):
msg = '"%s" is not host nor is it an appliance in the database' % name
raise CommandError(self.owner, msg)
+ if not partid:
+ partid = rowid
+
for host in hosts:
- self.doit(host, device, mountpoint,
+ self.doit(host, device, partid, mountpoint,
size, type, options, line)
#
# Create type_dict with the {fstype : mountpoints}
@@ -229,3 +247,4 @@ def run(self, args):
'needs "--name=<volname>" ' + \
'in the OPTIONS field' % (d, host)
raise CommandError(self.owner, msg)
+
@@ -83,12 +83,18 @@ def run(self, args):
size = partition['size']
type = partition['type']
options = partition['options']
+ partid = partition['partid']
+
+ if mountpt:
+ cmdargs.append('mountpoint=%s' % mountpt)
+ if type:
+ cmdargs.append('type=%s' % type)
- cmdargs.append('mountpoint=%s' % mountpt)
cmdargs.append('size=%s' % size)
- cmdargs.append('type=%s' % type)
if options:
cmdargs.append('options=%s' % options)
+ if partid:
+ cmdargs.append('partid=%s' % partid)
self.owner.call('add.storage.partition',
cmdargs)
@@ -64,6 +64,8 @@ def run(self, params, args):
if len(hosts) != 1:
raise ArgUnique(self, 'host')
+ self.beginOutput()
+
host = hosts[0]
#
@@ -72,7 +74,8 @@ def run(self, params, args):
#
output = self.call('list.storage.controller', [ host ])
if output:
- print(output)
+ self.addOutput('', '%s' % output)
+ self.endOutput(padChar = '')
return
#
@@ -82,21 +85,23 @@ def run(self, params, args):
output = self.call('list.storage.controller', [ appliance ])
if output:
- print(output)
+ self.addOutput('', '%s' % output)
+ self.endOutput(padChar = '')
return
#
# finally check the global level
#
output = self.call('list.storage.controller')
if output:
- print(output)
+ self.addOutput('', '%s' % output)
+ self.endOutput(padChar = '')
return
#
# if we made it here, there is no storage controller
# configuration for this host
#
output = []
- print(output)
-
+ self.addOutput('', '%s' % output)
+ self.endOutput(padChar = '')
Oops, something went wrong.

0 comments on commit 04a28d3

Please sign in to comment.