2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-12-23 19:52:10 +00:00

Add resource name to the storage messages

The storage messages need to have the references preserved
for CLI consumption.
This commit is contained in:
Jarrod Johnson 2018-10-30 15:46:54 -04:00
parent 079dfed11e
commit 6378f823f3
3 changed files with 133 additions and 2 deletions

View File

@ -0,0 +1,123 @@
#!/usr/bin/python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2018 Lenovo
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import optparse
import os
import signal
import sys
try:
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
except AttributeError:
pass
path = os.path.dirname(os.path.realpath(__file__))
path = os.path.realpath(os.path.join(path, '..', 'lib', 'python'))
if path.startswith('/opt'):
sys.path.append(path)
import confluent.client as client
exitcode = 0
class OptParser(optparse.OptionParser):
def format_epilog(self, formatter):
return self.expand_prog_name(self.epilog)
def showstorage(noderange, options, args):
global exitcode
session = client.Command()
storagebynode = {}
disks = {}
arrays = {}
volumes = {}
scfg = session.read('/noderange/{0}/configuration/storage/all'.format(
noderange))
for e in scfg:
if 'error' in e:
sys.stderr.write(e['error'] + '\n')
exitcode = e.get('errorcode', 1)
for node in e.get('databynode', {}):
if node not in storagebynode:
storagebynode[node] = {'disks': [], 'arrays': [], 'volumes': []}
curr = e['databynode'][node]
storagebynode[node][curr['type'] + 's'].append(curr)
for node in storagebynode:
for disk in storagebynode[node]['disks']:
print(repr(disk))
def createstorage(noderange, options, args):
session = client.Command()
def deletestorage(noderange, options, args):
pass
def setstorage(noderange, options, args):
pass
funmap = {
'create': createstorage,
'show': showstorage,
'set': setstorage,
'delete': deletestorage,
'rm': deletestorage,
}
def main():
argparser = OptParser(
usage='Usage: %prog <noderange> [show|create|set|delete]',
epilog='',
)
argparser.add_option('-r', '--raidlevel', type='int',
help='RAID level to use when creating an array')
argparser.add_option('-d', '--disks', type='str',
help='Comma separated list of disks to use, or the '
'word "rest" to indicate use of all available '
'disks')
argparser.add_option('-s', '--size', type='str',
help='Comma separated list of sizes to use when '
'creating volumes. The sizes may be absolute '
'size (e.g. 16gb), percentage (10%) or the word '
'"rest" to use remaining capacity, default '
'behavior is to use all capacity to make a '
'volume')
argparser.add_option('-n', '--name', type='str',
help='Comma separated list of names to use when '
'naming volumes, or selecting a volume for '
'delete. Default behavior is to use '
'implementation provided default names.')
(options, args) = argparser.parse_args()
try:
noderange = args[0]
operation = args[1]
except IndexError:
argparser.print_help()
sys.exit(1)
client.check_globbing(noderange)
try:
handler = funmap[operation]
except KeyError:
argparser.print_help()
sys.exit(1)
handler(noderange, options, args)
if __name__ == '__main__':
main()

View File

@ -32,6 +32,11 @@ valid_health_values = set([
'unknown',
])
def simplify_name(name):
return name.lower().replace(' ', '_').replace('/', '-').replace(
'_-_', '-')
def _htmlify_structure(indict):
ret = "<ul>"
if isinstance(indict, dict):
@ -1330,7 +1335,8 @@ class Volume(ConfluentMessage):
self.kvpairs = {
name: {
'type': 'volume',
'name': volname,
'name': simplify_name(volname),
'label': volname,
'size': size,
'state': state,
'array': array,
@ -1365,6 +1371,7 @@ class Disk(ConfluentMessage):
self.kvpairs = {
name: {
'type': 'disk',
'name': simplify_name(label),
'label': label,
'description': description,
'diskid': diskid,

View File

@ -130,7 +130,8 @@ def hex2bin(hexstring):
def simplify_name(name):
return name.lower().replace(' ', '_').replace('/', '-')
return name.lower().replace(' ', '_').replace('/', '-').replace(
'_-_', '-')
def sanitize_invdata(indata):