* [spp] [PATCH 1/3] controller: move import websocket
2018-04-23 6:22 [spp] [PATCH 0/3] Misc improvements for spp controller ogawa.yasufumi
@ 2018-04-23 6:22 ` ogawa.yasufumi
2018-04-23 6:22 ` [spp] [PATCH 2/3] controller: add topo_resize command ogawa.yasufumi
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: ogawa.yasufumi @ 2018-04-23 6:22 UTC (permalink / raw)
To: ferruh.yigit, geminoa; +Cc: spp, ogawa.yasufumi
From: ogawa.yasufumi@lab.ntt.co.jp
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
To avoid error for a user who does not install websocket, move import
statement from top of the file into to_http method which calls
websocket.
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
src/controller/topo.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/controller/topo.py b/src/controller/topo.py
index 76dd54f..aa81e03 100644
--- a/src/controller/topo.py
+++ b/src/controller/topo.py
@@ -8,7 +8,6 @@ from spp_common import logger
import subprocess
import traceback
import uuid
-import websocket
import yaml
@@ -250,6 +249,7 @@ class Topo(object):
subprocess.call("rm -f %s" % tmpfile, shell=True)
def to_http(self, sec_list):
+ import websocket
tmpfile = "%s.dot" % uuid.uuid4().hex
self.to_dot(sec_list, tmpfile)
msg = open(tmpfile).read()
--
2.13.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [spp] [PATCH 2/3] controller: add topo_resize command
2018-04-23 6:22 [spp] [PATCH 0/3] Misc improvements for spp controller ogawa.yasufumi
2018-04-23 6:22 ` [spp] [PATCH 1/3] controller: move import websocket ogawa.yasufumi
@ 2018-04-23 6:22 ` ogawa.yasufumi
2018-04-23 6:22 ` [spp] [PATCH 3/3] docs: add description for " ogawa.yasufumi
2018-05-03 15:58 ` [spp] [PATCH 0/3] Misc improvements for spp controller Ferruh Yigit
3 siblings, 0 replies; 5+ messages in thread
From: ogawa.yasufumi @ 2018-04-23 6:22 UTC (permalink / raw)
To: ferruh.yigit, geminoa; +Cc: spp, ogawa.yasufumi
From: ogawa.yasufumi@lab.ntt.co.jp
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
topo_resize command is for changing size of an image of topo term.
# topo_resize without arg shows current ratio
spp > topo_resize
60%
# resize with percentage
spp > topo_resize 80%
80%
# resize with ratio
spp > topo_resize 0.8
80%
# it is also able to use int
spp > topo_resize 1
100%
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
src/controller/shell.py | 18 +++++++++++++++++-
src/controller/topo.py | 8 ++++----
2 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/src/controller/shell.py b/src/controller/shell.py
index ea5e8a9..1cf712c 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -31,6 +31,7 @@ class Shell(cmd.Cmd, object):
PLUGIN_DIR = 'command'
subgraphs = {}
+ topo_size = '60%'
def default(self, line):
"""Define defualt behaviour
@@ -646,6 +647,21 @@ class Shell(cmd.Cmd, object):
else:
pass
+ def do_topo_resize(self, args):
+ if args == '':
+ print(self.topo_size)
+ else:
+ if '%' in args:
+ self.topo_size = args
+ print(self.topo_size)
+ elif '.' in args:
+ ii = float(args) * 100
+ self.topo_size = str(ii) + '%'
+ print(self.topo_size)
+ else: # TODO(yasufum) add check for no number
+ self.topo_size = str(float(args) * 100) + '%'
+ print(self.topo_size)
+
def do_topo(self, args):
"""Output network topology
@@ -676,7 +692,7 @@ class Shell(cmd.Cmd, object):
print("Usage: topo dst [ftype]")
return False
elif (args_ary[0] == "term") or (args_ary[0] == "http"):
- res_ary = tp.show(args_ary[0])
+ res_ary = tp.show(args_ary[0], self.topo_size)
elif len(args_ary) == 1:
ftype = args_ary[0].split(".")[-1]
res_ary = tp.output(args_ary[0], ftype)
diff --git a/src/controller/topo.py b/src/controller/topo.py
index aa81e03..ff1349c 100644
--- a/src/controller/topo.py
+++ b/src/controller/topo.py
@@ -28,7 +28,7 @@ class Topo(object):
self.s2m_queues = s2m_queues
self.sub_graphs = sub_graphs
- def show(self, dtype):
+ def show(self, dtype, size):
res_ary = []
for sec_id in self.sec_ids:
self.m2s_queues[sec_id].put("status")
@@ -38,7 +38,7 @@ class Topo(object):
if dtype == "http":
self.to_http(res_ary)
elif dtype == "term":
- self.to_term(res_ary)
+ self.to_term(res_ary, size)
else:
print("Invalid file type")
return res_ary
@@ -259,7 +259,7 @@ class Topo(object):
ws.send(msg)
ws.close()
- def to_term(self, sec_list):
+ def to_term(self, sec_list, size):
tmpfile = "%s.jpg" % uuid.uuid4().hex
self.to_img(sec_list, tmpfile)
from distutils import spawn
@@ -272,7 +272,7 @@ class Topo(object):
img_cmd = "%s/%s/imgcat.sh" % (
os.path.dirname(__file__), '3rd_party')
# Resize image to fit the terminal
- img_size = "60%"
+ img_size = size
cmd = "convert -resize %s %s %s" % (img_size, tmpfile, tmpfile)
subprocess.call(cmd, shell=True)
subprocess.call("%s %s" % (img_cmd, tmpfile), shell=True)
--
2.13.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [spp] [PATCH 3/3] docs: add description for topo_resize command
2018-04-23 6:22 [spp] [PATCH 0/3] Misc improvements for spp controller ogawa.yasufumi
2018-04-23 6:22 ` [spp] [PATCH 1/3] controller: move import websocket ogawa.yasufumi
2018-04-23 6:22 ` [spp] [PATCH 2/3] controller: add topo_resize command ogawa.yasufumi
@ 2018-04-23 6:22 ` ogawa.yasufumi
2018-05-03 15:58 ` [spp] [PATCH 0/3] Misc improvements for spp controller Ferruh Yigit
3 siblings, 0 replies; 5+ messages in thread
From: ogawa.yasufumi @ 2018-04-23 6:22 UTC (permalink / raw)
To: ferruh.yigit, geminoa; +Cc: spp, ogawa.yasufumi
From: ogawa.yasufumi@lab.ntt.co.jp
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
docs/guides/commands/experimental.rst | 38 ++++++++++++++++++++++++++++++++++-
1 file changed, 37 insertions(+), 1 deletion(-)
diff --git a/docs/guides/commands/experimental.rst b/docs/guides/commands/experimental.rst
index 39531a2..8bb8e20 100644
--- a/docs/guides/commands/experimental.rst
+++ b/docs/guides/commands/experimental.rst
@@ -150,7 +150,7 @@ To generate a jpg image, run ``topo`` with the name ``network.jpg``.
topo_subgraph
-------------
-``topo_subgraph`` is a supplemental command for manageing subgraphs
+``topo_subgraph`` is a supplemental command for managing subgraphs
for ``topo``.
.. code-block:: console
@@ -218,6 +218,42 @@ delete subgraph ``guest_vm``.
spp > topo_subgraph del guest_vm
+topo_resize
+-----------
+
+``topo_resize`` is a supplemental command for changing the size of
+images displayed on the terminal with ``topo``.
+
+``topo`` displays an image generated from graphviz with default size.
+However, it is too small or large for some environments because it
+depends on the resolution actually.
+
+To check default size, run ``topo_resize`` with no arguments.
+It shows current size of the image.
+
+.. code-block:: console
+
+ # shows current size
+ spp > topo_resize
+ 60%
+
+You can resize it with percentage
+
+.. code-block:: console
+
+ # resize with percentage
+ spp > topo_resize 80%
+ 80%
+
+or ratio.
+
+.. code-block:: console
+
+ # resize with ratio
+ spp > topo_resize 0.8
+ 80%
+
+
load_cmd
--------
--
2.13.1
^ permalink raw reply [flat|nested] 5+ messages in thread