Skip to content

Commit

Permalink
Related-Bug: #1463208 - Changing Cliff code to match version 1.5.4
Browse files Browse the repository at this point in the history
The debian package of cliff available in trusty repos is 1.5.4
The code was previously written for cliff version 1.10
This commit rolls back and rewrites smgr cli app code to reflect that
Some changes made to config files to match packaging script changes

Patch 2:
Removed pip from setup script
Modified POST call to allow match keys for run_inventory

Change-Id: Ie8af3bd7b428a340274619e85cb2d9fac35276c7
  • Loading branch information
nitishkrishna committed Sep 23, 2015
1 parent 052ee66 commit ea0ac96
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 33 deletions.
5 changes: 2 additions & 3 deletions src/smgr_cliff_client/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pbr>=0.11
cliff>=1.10.0
pbr>=0.7.0
cliff>=1.4.5
configparser>=3.3
pyparsing>=2
#argcomplete>=0.8.9
2 changes: 1 addition & 1 deletion src/smgr_cliff_client/servermanagerclient
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export SMGR_IP=10.84.30.2
export SMGR_IP=1.1.1.1
export SMGR_PORT=9001
12 changes: 7 additions & 5 deletions src/smgr_cliff_client/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ def get_contrail_sku():
VERSION = CONTRAIL_VERSION + "-" + CONTRAIL_SKU

import setuptools
from pip import req, download
from pip.req import parse_requirements
from pip.download import PipSession
import ConfigParser

install_reqs = req.parse_requirements("requirements.txt", session=download.PipSession())
reqs = [str(ir.req) for ir in install_reqs]
install_reqs = []

for line in open('requirements.txt', 'r'):
if not str(line.strip()).startswith("#"):
install_reqs.append(line.strip())

reqs = install_reqs
config = ConfigParser.ConfigParser()
config.read('setup.cfg')

Expand Down
14 changes: 13 additions & 1 deletion src/smgr_cliff_client/setup_server_manager_client.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
#!/bin/bash
set -e

HOST_IP_LIST=`ifconfig | sed -n -e 's/:127\.0\.0\.1 //g' -e 's/ *inet addr:\([0-9.]\+\).*/\1/gp'`
HOST_IP=`echo $HOST_IP_LIST | cut -d' ' -f1`
if [ -f /opt/contrail/contrail_server_manager/IP.txt ];
then
HOST_IP=$(cat /opt/contrail/contrail_server_manager/IP.txt)
fi
echo $HOST_IP
mkdir -p /etc/contrail/
cp /tmp/servermanagerclient /etc/contrail/
cp /tmp/servermanagerclient /etc/contrail/servermanagerclient
sed -i "s/listen_ip_addr = .*/listen_ip_addr = $HOST_IP/g" /tmp/sm-client-config.ini
sed -i "s/export SMGR_IP=.*/export SMGR_IP=$HOST_IP/g" /etc/contrail/servermanagerclient
source /etc/contrail/servermanagerclient
ln -sbf /opt/contrail/bin/* /usr/bin/
8 changes: 7 additions & 1 deletion src/smgr_cliff_client/smgrcliapp/commandmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ def __init__(self, namespace, convert_underscores=True):
super(CommandManager, self).__init__(namespace, convert_underscores)

def load_commands(self, namespace):
"""Load all the commands from an entrypoint"""
for ep in pkg_resources.iter_entry_points(namespace):
LOG.debug('found command %r', ep.name)
cmd_name = (ep.name.replace('_', ' ')
if self.convert_underscores
else ep.name)
self.commands[cmd_name] = ep
self.group_list.append(namespace)
return super(CommandManager, self).load_commands(namespace)

def add_command_group(self, group=None):
"""Adds another group of command entrypoints"""
Expand Down
16 changes: 14 additions & 2 deletions src/smgr_cliff_client/smgrcliapp/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ def __init__(self, parent_app, command_manager, stdin, stdout):
stdout=stdout
)

def _complete_prefix(self, prefix):
"""Returns cliff style commands with a specific prefix."""
if not prefix:
return [n for n, v in self.command_manager]
return [n for n, v in self.command_manager if n.startswith(prefix)]

def completenames(self, text, *ignored):
completions = cmd2.Cmd.completenames(self, text, *ignored)
completions += self._complete_prefix(text)
Expand All @@ -36,7 +42,7 @@ def completenames(self, text, *ignored):
#Overriding this class method with custom auto-completion
def completedefault(self, text, line, begidx, endidx):
available_options = dict()
#This dictionary classes all the possbile SM options such that only one can be chosen at a time.
# This dictionary classes all the possbile SM options such that only one can be chosen at a time.
available_options["help"] = ['-h', '--help']
available_options["select"] = ['--select', '--detail']
available_options["force"] = ['--no_confirm', '-F']
Expand Down Expand Up @@ -78,7 +84,7 @@ def completedefault(self, text, line, begidx, endidx):
if (str(line).startswith(n) or str(line) == n)
and n in self.command_manager.get_added_commands()][0]
cmd_factory, cmd_name, sub_argv = self.command_manager.find_command([str(chosen_command)])
cmd = cmd_factory(self.parent_app, self.parent_app.options, {})
cmd = cmd_factory(self.parent_app, self.parent_app.options)
cmd.get_parser(cmd_name)
cmd_dict = cmd.get_command_options()
chosen_sub_command = None
Expand Down Expand Up @@ -228,3 +234,9 @@ def completedefault(self, text, line, begidx, endidx):
if len(return_list) > 0:
return [x[begidx:] for x in return_list]

def cmdloop(self):
try:
self._cmdloop()
except Exception as e:
self.parent_app.print_error_message_and_quit("\nException caught in interactive mode: " + str(e) + "\n")

5 changes: 3 additions & 2 deletions src/smgr_cliff_client/smgrcliapp/sm-client-config.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[SERVER-MANAGER]
; ip address of the server manager
; replace the following with proper server manager address
listen_ip_addr = 10.84.30.189
listen_ip_addr = 1.1.1.1
; server manager listening port
listen_port = 8081
listen_port = 9001

[CLUSTER]
subnet_mask = 255.255.255.0
Expand All @@ -22,3 +22,4 @@ database_token =
analytics_data_ttl = 168
[SERVER]

[TAG]
30 changes: 12 additions & 18 deletions src/smgr_cliff_client/smgrcliapp/smgr_cli_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

class ServerManagerCLI(App):
log = logging.getLogger(__name__)
LOG = log
smgr_port = None
smgr_ip = None
default_config = dict()
Expand Down Expand Up @@ -71,21 +72,13 @@ def build_option_parser(self, description, version,
const=0,
help='suppress output except warnings and errors',
)
if self.deferred_help:
parser.add_argument(
'-h', '--help',
dest='deferred_help',
action='store_true',
help="show this help message and exit",
)
else:
parser.add_argument(
'-h', '--help',
action=HelpAction,
nargs=0,
default=self, # tricky
help="show this help message and exit",
)
parser.add_argument(
'-h', '--help',
action=HelpAction,
nargs=0,
default=self, # tricky
help="show this help message and exit",
)
parser.add_argument(
'--debug',
default=False,
Expand Down Expand Up @@ -152,7 +145,9 @@ def clean_up(self, cmd, result, err):
def interact(self):
# Defer importing .interactive as cmd2 is a slow import
from interactive import SmgrInteractiveApp
self.interpreter = SmgrInteractiveApp(self, self.command_manager, None, None)
self.interpreter = SmgrInteractiveApp(parent_app=self,
command_manager=self.command_manager,
stdout=self.stdout, stdin=self.stdin)
self.interpreter.cmdloop()
return 0

Expand All @@ -176,8 +171,7 @@ def run_subcommand(self, argv):
self.prepare_to_run_command(cmd)
full_name = (cmd_name
if self.interactive_mode
else ' '.join([self.NAME, cmd_name])
)
else ' '.join([self.NAME, cmd_name]))
cmd_parser = cmd.get_parser(full_name)
parsed_args, remainder = cmd_parser.parse_known_args(sub_argv)
if remainder:
Expand Down
4 changes: 4 additions & 0 deletions src/smgr_cliff_client/smgrcliapp/smgr_client_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ def send_REST_request(ip, port, obj=None, rest_api_params=None,
if method == "PUT" or method == "POST" and obj:
url = "http://%s:%s/%s" % (
ip, port, obj)
if match_key and match_value:
args_str += match_key + "=" + match_value
if args_str != '':
url += "?" + args_str
elif method == "GET":
if rest_api_params:
url = "http://%s:%s/%s" % (ip, port, rest_api_params['object'])
Expand Down

0 comments on commit ea0ac96

Please sign in to comment.