-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Related-Bug: #1463208 - Moving Server Manager Client CLI to Cliff Fra…
…mework This check-in: - Added main Cliff framework files - Added Server Manager commands - Added setup.py for cliff client pip installable package - Packaging scripts in separate checkin Patch 2: - Changed bash completion to new path Patch 3: - Implemented review comments - Add command substantially changed - Discarded bash autocompletion - Env variable smgr_ip and port can be sourced from /etc/contrail/servermanagerclient Patch 4: - Added edit command - Multiple bug fixes - Tested all commands except upload_image - Moved common functions to smgr_client_utils from smgr_client_def Change-Id: I5b9fac1474fba58feb08588a549eec40f77542c9
- Loading branch information
root
authored and
nitishkrishna
committed
Sep 14, 2015
1 parent
dd20ff1
commit 2154a3a
Showing
24 changed files
with
3,336 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
include requirements.txt | ||
include setup_server_manager_client.sh | ||
include smgrcliapp/sm-client-config.ini | ||
include contrail_sku.txt | ||
include contrail_version.txt | ||
include servermanagerclient |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pbr>=0.11 | ||
cliff>=1.10.0 | ||
configparser>=3.3 | ||
pyparsing>=2 | ||
#argcomplete>=0.8.9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export SMGR_IP=10.84.30.2 | ||
export SMGR_PORT=9001 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[entry_points] | ||
console_scripts = | ||
server-manager-client = smgrcliapp.smgr_cli_main:main | ||
|
||
smgr.cli.common = | ||
display = smgrcliapp.smgr_show:Show | ||
reimage = smgrcliapp.smgr_reimage_server:Reimage | ||
restart = smgrcliapp.smgr_restart_server:Restart | ||
provision = smgrcliapp.smgr_provision_server:Provision | ||
status = smgrcliapp.smgr_status:Status | ||
add = smgrcliapp.smgr_add:Add | ||
update = smgrcliapp.smgr_edit:Edit | ||
delete = smgrcliapp.smgr_delete:Delete | ||
upload-image = smgrcliapp.smgr_upload_image:UploadImage | ||
run-inventory = smgrcliapp.smgr_run_inventory:RunInventory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/usr/bin/env python | ||
|
||
PROJECT = 'servermanagercli' | ||
|
||
|
||
def get_version(): | ||
version = None | ||
with open('contrail_version.txt') as f: | ||
version = f.read() | ||
version = version.strip() | ||
if version: | ||
return version | ||
else: | ||
return "1.0" | ||
|
||
|
||
def get_contrail_sku(): | ||
sku = None | ||
with open('contrail_sku.txt') as f: | ||
sku = f.read() | ||
sku = sku.strip() | ||
if sku: | ||
return sku | ||
else: | ||
return "havana" | ||
|
||
CONTRAIL_VERSION = get_version() | ||
CONTRAIL_SKU = 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] | ||
config = ConfigParser.ConfigParser() | ||
config.read('setup.cfg') | ||
|
||
config_dict = dict(config._sections) | ||
for k in config_dict: | ||
config_dict[k] = dict(config._defaults, **config_dict[k]) | ||
config_dict[k].pop('__name__', None) | ||
|
||
console_script_list = [str(x) for x in (config_dict['entry_points']['console_scripts']).splitlines() if x and x[0] != "#"] | ||
entry_points_dict = dict() | ||
entry_points_dict['console_scripts'] = console_script_list | ||
|
||
entry_points = [key for key in (config_dict['entry_points']) if key != "console_scripts"] | ||
for entry_point in entry_points: | ||
command_list = [str(x) for x in (config_dict['entry_points'][str(entry_point)]).splitlines() if x and x[0] != "#"] | ||
entry_points_dict[str(entry_point)] = command_list | ||
|
||
|
||
setuptools.setup( | ||
name=PROJECT, | ||
version=VERSION, | ||
setup_requires=['configparser'], | ||
description='Server Manager Command Line Interface', | ||
package_data={'': ['*.ini', '*.txt', '*.sh']}, | ||
packages=setuptools.find_packages(), | ||
include_package_data=True, | ||
install_requires=reqs, | ||
platforms=['Any'], | ||
entry_points=entry_points_dict, | ||
scripts=['setup_server_manager_client.sh'], | ||
data_files=[ | ||
('/tmp', ['smgrcliapp/sm-client-config.ini']), | ||
('/tmp', ['servermanagerclient']) | ||
], | ||
zip_safe=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
mkdir -p /etc/contrail/ | ||
cp /tmp/servermanagerclient /etc/contrail/ | ||
ln -sbf /opt/contrail/bin/* /usr/bin/ |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Copyright 2012-2013 OpenStack Foundation | ||
# | ||
# 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. | ||
# | ||
|
||
"""Modify cliff.CommandManager""" | ||
|
||
import logging | ||
import pkg_resources | ||
|
||
import cliff.commandmanager | ||
|
||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class CommandManager(cliff.commandmanager.CommandManager): | ||
"""Add additional functionality to cliff.CommandManager | ||
Load additional command groups after initialization | ||
Add _command_group() methods | ||
""" | ||
|
||
def __init__(self, namespace, convert_underscores=True): | ||
self.group_list = [] | ||
super(CommandManager, self).__init__(namespace, convert_underscores) | ||
|
||
def load_commands(self, namespace): | ||
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""" | ||
if group: | ||
self.load_commands(group) | ||
|
||
def get_command_groups(self): | ||
"""Returns a list of the loaded command groups""" | ||
return self.group_list | ||
|
||
def get_added_commands(self): | ||
command_list = [] | ||
group_list = self.get_command_groups() | ||
for ns in group_list: | ||
for ep in pkg_resources.iter_entry_points(ns): | ||
cmd_name = (ep.name.replace('_', ' ') | ||
if self.convert_underscores | ||
else ep.name) | ||
command_list.append(cmd_name) | ||
return command_list | ||
|
||
|
Oops, something went wrong.