[spp] [PATCH 1/8] cli: remove topo_resize command
Yasufumi Ogawa
yasufum.o at gmail.com
Mon Aug 12 09:12:35 CEST 2019
As `topo_size` is introduced in config and `topo_resize` command is not
required anymore, remove this command.
Signed-off-by: Yasufumi Ogawa <yasufum.o at gmail.com>
---
src/cli/commands/topo.py | 59 +++++++++++++++++++++-------------------
src/cli/shell.py | 10 ++-----
2 files changed, 33 insertions(+), 36 deletions(-)
diff --git a/src/cli/commands/topo.py b/src/cli/commands/topo.py
index 21ef1ec..58c59d1 100644
--- a/src/cli/commands/topo.py
+++ b/src/cli/commands/topo.py
@@ -25,7 +25,11 @@ class SppTopo(object):
def __init__(self, spp_ctl_cli, subgraphs, size):
self.spp_ctl_cli = spp_ctl_cli
self.subgraphs = subgraphs
- self.graph_size = size
+ self.graph_size = None
+
+ if self.resize(size) is not True:
+ print('Config "topo_size" is invalid value.')
+ exit()
def run(self, args, sec_ids):
args_ary = args.split()
@@ -42,6 +46,32 @@ class SppTopo(object):
else:
print("Usage: topo dst [ftype]")
+ def resize(self, size):
+ """Parse given size and set to self.graph_size.
+
+ The format of `size` is percentage or ratio. Return True if succeeded
+ to parse, or False if invalid format.
+ """
+
+ size = str(size)
+ matched = re.match(r'(\d+)%$', size)
+ if matched: # percentage
+ i = int(matched.group(1))
+ if i > 0 and i <= 100:
+ self.graph_size = size
+ return True
+ else:
+ return False
+ elif re.match(r'0\.\d+$',size): # ratio
+ i = float(size) * 100
+ self.graph_size = str(i) + '%'
+ return True
+ elif size == '1':
+ self.graph_size = '100%'
+ return True
+ else:
+ return False
+
def show(self, dtype, sec_ids, size):
res_ary = []
error_codes = self.spp_ctl_cli.rest_common_error_codes
@@ -319,21 +349,6 @@ class SppTopo(object):
topo_doc += "commands/experimental.html"
print("See '%s' for required packages." % topo_doc)
- def resize_graph(self, args):
- if args == '':
- print(self.graph_size)
- else:
- if '%' in args:
- self.graph_size = args
- print(self.graph_size)
- elif '.' in args:
- ii = float(args) * 100
- self.graph_size = str(ii) + '%'
- print(self.graph_size)
- else: # TODO(yasufum) add check for no number
- self.graph_size = str(float(args) * 100) + '%'
- print(self.graph_size)
-
def format_sec_status(self, sec_id, stat):
"""Return formatted secondary status as a hash
@@ -479,18 +494,6 @@ class SppTopo(object):
print(msg)
- @classmethod
- def help_resize(cls):
- msg = """Change the size of the image of topo command.
-
- You can specify the size by percentage or ratio.
-
- spp > topo resize 60% # percentage
- spp > topo resize 0.6 # ratio
- """
-
- print(msg)
-
@classmethod
def help_subgraph(cls):
msg = """Edit subgarph for topo command.
diff --git a/src/cli/shell.py b/src/cli/shell.py
index 34c12a1..d98cc8b 100644
--- a/src/cli/shell.py
+++ b/src/cli/shell.py
@@ -627,6 +627,8 @@ class Shell(cmd.Cmd, object):
# Command prompt should be updated immediately
if key == 'prompt':
self.prompt = self.cli_config['prompt']['val']
+ elif key == 'topo_size':
+ self.spp_topo.resize(self.cli_config['topo_size']['val'])
def help_config(self):
"""Print help message of config command."""
@@ -904,14 +906,6 @@ class Shell(cmd.Cmd, object):
else:
pass
- def do_topo_resize(self, args):
- """Change the size of the image of topo_resize command."""
- self.spp_topo.resize_graph(args)
-
- def help_topo_resize(self):
- """Print help message of topo command."""
- topo.SppTopo.help_resize()
-
def do_topo(self, args):
"""Output network topology."""
self.spp_topo.run(args, self.get_sec_ids('nfv'))
--
2.17.1
More information about the spp
mailing list