Skip to content

Commit

Permalink
Bug #1366210
Browse files Browse the repository at this point in the history
1. Provision storage webui pkgs in all nodes defined in webui role
2. Added storage webui related files
3. Decoupled storage webui provision from ceph installation provision.
4. Removed Extra white space characters
5. fixed alignment for variables
Change-Id: I4ba5e9dabd3ce0d6664dd52fb75e5a304dea72ff
  • Loading branch information
surakula committed Sep 25, 2014
1 parent e1e296a commit 5c67bf9
Show file tree
Hide file tree
Showing 4 changed files with 286 additions and 71 deletions.
69 changes: 42 additions & 27 deletions contrail_setup_utils/setup.py
Expand Up @@ -325,6 +325,9 @@ def _parse_args(self, args_str):
parser.add_argument("--nfs-livem-image", help = "Image for NFS for Live migration VM", nargs="+", type=str)
parser.add_argument("--nfs-livem-host", help = "Image for NFS for Live migration VM", nargs="+", type=str)
parser.add_argument("--add-storage-node", help = "Dynamic addition of storage node")
parser.add_argument("--storage-webui-ip", help = "IP Address of storage webui node")
parser.add_argument("--storage-webui-mode", help = "Config mode Storage WebUI Status")
parser.add_argument("--storage-master-ip", help = "IP Address of storage master node")
parser.add_argument("--storage-setup-mode", help = "Storage configuration mode")
parser.add_argument("--vmware", help = "Vmware ESXI IP", type=str)
parser.add_argument("--vmware_username", help = "Vmware ESXI Username", type=str)
Expand Down Expand Up @@ -1792,36 +1795,48 @@ def run_services(self):
run("python /opt/contrail/contrail_installer/contrail_setup_utils/livemnfs-ceph-setup.py %s" %(storage_setup_args))
else:
# Storage Configurations
# Setup Ceph services
storage_setup_args = " --storage-master %s" %(self._args.storage_master)
storage_setup_args = storage_setup_args + " --storage-setup-mode %s" % (self._args.storage_setup_mode)
if self._args.add_storage_node:
storage_setup_args = storage_setup_args + " --add-storage-node %s" % (self._args.add_storage_node)
storage_setup_args = storage_setup_args + " --storage-hostnames %s" %(' '.join(self._args.storage_hostnames))
storage_setup_args = storage_setup_args + " --storage-hosts %s" %(' '.join(self._args.storage_hosts))
storage_setup_args = storage_setup_args + " --storage-host-tokens %s" %(' '.join(self._args.storage_host_tokens))
storage_setup_args = storage_setup_args + " --storage-disk-config %s" %(' '.join(self._args.storage_disk_config))
storage_setup_args = storage_setup_args + " --storage-ssd-disk-config %s" %(' '.join(self._args.storage_ssd_disk_config))
storage_setup_args = storage_setup_args + " --storage-journal-config %s" %(' '.join(self._args.storage_journal_config))
storage_setup_args = storage_setup_args + " --storage-local-disk-config %s" %(' '.join(self._args.storage_local_disk_config))
storage_setup_args = storage_setup_args + " --storage-local-ssd-disk-config %s" %(' '.join(self._args.storage_local_ssd_disk_config))
storage_setup_args = storage_setup_args + " --storage-nfs-disk-config %s" %(' '.join(self._args.storage_nfs_disk_config))
storage_setup_args = storage_setup_args + " --storage-directory-config %s" %(' '.join(self._args.storage_directory_config))
with settings(host_string=self._args.storage_master):
run("python /opt/contrail/contrail_installer/contrail_setup_utils/storage-ceph-setup.py %s" %(storage_setup_args))

# Setup Live migration services
live_migration_status = self._args.live_migration
if live_migration_status == 'enabled':
# Storage WebUI
storage_webui_mode = self._args.storage_webui_mode
if storage_webui_mode == 'enabled':
storage_setup_args = " --storage-webui-ip %s" %(self._args.storage_webui_ip)
storage_setup_args = storage_setup_args + " --storage-setup-mode %s" % (self._args.storage_setup_mode)
with settings(host_string=self._args.storage_webui_ip):
storage_master_ip = self._args.storage_master_ip
# Configuring the ceph rest server ip to storage webui config
local("sudo sed \"s/config.ceph.server_ip.*/config.ceph.server_ip = '%s';/g\" /usr/src/contrail/contrail-web-storage/webroot/common/config/storage.config.global.js > storage.config.global.js.new" %(storage_master_ip))
local("sudo mv storage.config.global.js.new /usr/src/contrail/contrail-web-storage/webroot/common/config/storage.config.global.js")
run("python /opt/contrail/contrail_installer/contrail_setup_utils/storage-webui-setup.py %s" %(storage_setup_args))
else:
# Setup Ceph services
storage_setup_args = " --storage-master %s" %(self._args.storage_master)
storage_setup_args = storage_setup_args + " --storage-setup-mode %s" % (self._args.storage_setup_mode)
storage_setup_args = storage_setup_args + " --storage-hostnames %s" %(' '.join(self._args.storage_hostnames))
storage_setup_args = storage_setup_args + " --storage-hosts %s" %(' '.join(self._args.storage_hosts))
storage_setup_args = storage_setup_args + " --storage-host-tokens %s" %(' '.join(self._args.storage_host_tokens))
storage_setup_args = storage_setup_args + " --storage-setup-mode %s" % (self._args.storage_setup_mode)
if self._args.add_storage_node:
storage_setup_args = storage_setup_args + " --add-storage-node %s" % (self._args.add_storage_node)
storage_setup_args = storage_setup_args + " --add-storage-node %s" % (self._args.add_storage_node)
storage_setup_args = storage_setup_args + " --storage-hostnames %s" %(' '.join(self._args.storage_hostnames))
storage_setup_args = storage_setup_args + " --storage-hosts %s" %(' '.join(self._args.storage_hosts))
storage_setup_args = storage_setup_args + " --storage-host-tokens %s" %(' '.join(self._args.storage_host_tokens))
storage_setup_args = storage_setup_args + " --storage-disk-config %s" %(' '.join(self._args.storage_disk_config))
storage_setup_args = storage_setup_args + " --storage-ssd-disk-config %s" %(' '.join(self._args.storage_ssd_disk_config))
storage_setup_args = storage_setup_args + " --storage-journal-config %s" %(' '.join(self._args.storage_journal_config))
storage_setup_args = storage_setup_args + " --storage-local-disk-config %s" %(' '.join(self._args.storage_local_disk_config))
storage_setup_args = storage_setup_args + " --storage-local-ssd-disk-config %s" %(' '.join(self._args.storage_local_ssd_disk_config))
storage_setup_args = storage_setup_args + " --storage-nfs-disk-config %s" %(' '.join(self._args.storage_nfs_disk_config))
storage_setup_args = storage_setup_args + " --storage-directory-config %s" %(' '.join(self._args.storage_directory_config))
with settings(host_string=self._args.storage_master):
run("python /opt/contrail/contrail_installer/contrail_setup_utils/compute-live-migration-setup.py %s" %(storage_setup_args))
run("python /opt/contrail/contrail_installer/contrail_setup_utils/storage-ceph-setup.py %s" %(storage_setup_args))

# Setup Live migration services
live_migration_status = self._args.live_migration
if live_migration_status == 'enabled':
storage_setup_args = " --storage-master %s" %(self._args.storage_master)
storage_setup_args = storage_setup_args + " --storage-setup-mode %s" % (self._args.storage_setup_mode)
storage_setup_args = storage_setup_args + " --storage-hostnames %s" %(' '.join(self._args.storage_hostnames))
storage_setup_args = storage_setup_args + " --storage-hosts %s" %(' '.join(self._args.storage_hosts))
storage_setup_args = storage_setup_args + " --storage-host-tokens %s" %(' '.join(self._args.storage_host_tokens))
if self._args.add_storage_node:
storage_setup_args = storage_setup_args + " --add-storage-node %s" % (self._args.add_storage_node)
with settings(host_string=self._args.storage_master):
run("python /opt/contrail/contrail_installer/contrail_setup_utils/compute-live-migration-setup.py %s" %(storage_setup_args))


#end run_services
Expand Down
46 changes: 2 additions & 44 deletions contrail_setup_utils/storage-ceph-setup.py
Expand Up @@ -101,40 +101,6 @@ def reset_osd_remote_list(self):
run('chmod a+x /tmp/osd_local_list.sh')
run('/tmp/osd_local_list.sh')

def contrail_storage_ui_add(self):
if self._args.storage_disk_config[0] != 'none' or self._args.storage_ssd_disk_config[0] != 'none':
# enable Contrail Web Storage feature
with settings(warn_only=True):
storage_enable_variable = local('cat /etc/contrail/config.global.js | grep config.featurePkg.webStorage', capture=True);
if storage_enable_variable:
print 'Re-enable Contrail Web Storage feature'
local('sudo sed "s/config.featurePkg.webStorage.enable = *;/config.featurePkg.webStorage.enable = true;/g" /etc/contrail/config.global.js > config.global.js.new')
local('sudo cp config.global.js.new /etc/contrail/config.global.js')
else:
print 'Enable Contrail Web Storage feature'
local('sudo cp /etc/contrail/config.global.js /usr/src/contrail/contrail-web-storage/config.global.js.org')
local('sudo sed "/config.featurePkg.webController.enable/ a config.featurePkg.webStorage = {};\\nconfig.featurePkg.webStorage.path=\'\/usr\/src\/contrail\/contrail-web-storage\';\\nconfig.featurePkg.webStorage.enable = true;" /etc/contrail/config.global.js > config.global.js.new')
local('sudo cp config.global.js.new /etc/contrail/config.global.js')

#restart the webui server
time.sleep(5);
print 'restarting... supervisor-webui service'
local('sudo service supervisor-webui restart')

def contrail_storage_ui_remove(self):
if self._args.storage_disk_config[0] != 'none' or self._args.storage_ssd_disk_config[0] != 'none':
#disable Contrail Web Storage feature
with settings(warn_only=True):
storage_enable_variable = local('cat /etc/contrail/config.global.js | grep config.featurePkg.webStorage', capture=True);
if storage_enable_variable:
print 'Disable Contrail Web Storage feature'
local('sudo sed "/config.featurePkg.webStorage = {}/,/config.featurePkg.webStorage.enable = true;/d" /etc/contrail/config.global.js > config.global.js.new')
local('sudo cp config.global.js.new /etc/contrail/config.global.js')
#restart the webui server
time.sleep(5);
print 'restarting... supervisor-webui service'
local('sudo service supervisor-webui restart')

def ceph_rest_api_service_add(self):
# check for ceph-rest-api.conf
# write /etc/init conf for service upstrart
Expand Down Expand Up @@ -1140,14 +1106,8 @@ def __init__(self, args_str = None):
time.sleep(2)
local('sudo ceph-deploy purgedata %s <<< \"y\"' % (ceph_mon_hosts), capture=False, shell='/bin/bash')

# Whenever Storage setup mode is reconfigure or unconfigure needs to remove below service and a feature
# 1. remove the ceph-rest-api service
# 2. remove the Storage UI feature
if self._args.storage_setup_mode == 'reconfigure' or self._args.storage_setup_mode == 'unconfigure':
if pdist == 'Ubuntu':
self.contrail_storage_ui_remove()
time.sleep(5)
self.ceph_rest_api_service_remove()
if pdist == 'Ubuntu':
self.ceph_rest_api_service_remove()

if self._args.storage_setup_mode == 'unconfigure':
print 'Storage configuration removed'
Expand Down Expand Up @@ -1770,8 +1730,6 @@ def __init__(self, args_str = None):

if pdist == 'Ubuntu':
self.ceph_rest_api_service_add()
time.sleep(5)
self.contrail_storage_ui_add()

#end __init__

Expand Down
147 changes: 147 additions & 0 deletions contrail_setup_utils/storage-webui-setup.py
@@ -0,0 +1,147 @@
#!/usr/bin/python

import argparse
import ConfigParser

import platform
import os
import sys
import time
import re
import string
import socket
import netifaces, netaddr
import subprocess
import fnmatch
import struct
import shutil
import json
from pprint import pformat
import xml.etree.ElementTree as ET
import platform
import pdb

import tempfile
from fabric.api import local, env, run, settings
from fabric.operations import get, put
from fabric.context_managers import lcd, settings
from fabric.api import local, env, run
from fabric.operations import get, put
from fabric.context_managers import lcd, settings
sys.path.insert(0, os.getcwd())

class SetupStorageWebUI(object):
# Enable the Storage feature to Contrail WebUI
def contrail_storage_ui_add(self):
print 'stopping... supervisor-webui service'
local('sudo service supervisor-webui stop')
time.sleep(5);
# enable Contrail Web Storage feature
with settings(warn_only=True):
storage_enable_variable = local('cat /etc/contrail/config.global.js | grep config.featurePkg.webStorage', capture=True);
if storage_enable_variable:
print 'Re-enable Contrail Web Storage feature'
local('sudo sed "s/config.featurePkg.webStorage.enable = *;/config.featurePkg.webStorage.enable = true;/g" /etc/contrail/config.global.js > config.global.js.new')
local('sudo cp config.global.js.new /etc/contrail/config.global.js')
else:
print 'Enable Contrail Web Storage feature'
local('sudo cp /etc/contrail/config.global.js /usr/src/contrail/contrail-web-storage/config.global.js.org')
local('sudo sed "/config.featurePkg.webController.enable/ a config.featurePkg.webStorage = {};\\nconfig.featurePkg.webStorage.path=\'\/usr\/src\/contrail\/contrail-web-storage\';\\nconfig.featurePkg.webStorage.enable = true;" /etc/contrail/config.global.js > config.global.js.new')
local('sudo cp config.global.js.new /etc/contrail/config.global.js')

#restart the webui server
time.sleep(5);
print 'starting... supervisor-webui service'
local('sudo service supervisor-webui start')

# Disable the Storage feature to Contrail WebUI
def contrail_storage_ui_remove(self):
#disable Contrail Web Storage feature
with settings(warn_only=True):
storage_enable_variable = local('cat /etc/contrail/config.global.js | grep config.featurePkg.webStorage', capture=True);
if storage_enable_variable:
print 'stopping... supervisor-webui service'
local('sudo service supervisor-webui stop')
print 'Disable Contrail Web Storage feature'
local('sudo sed "/config.featurePkg.webStorage = {}/,/config.featurePkg.webStorage.enable = true;/d" /etc/contrail/config.global.js > config.global.js.new')
local('sudo cp config.global.js.new /etc/contrail/config.global.js')
#restart the webui server
time.sleep(5);
print 'starting... supervisor-webui service'
local('sudo service supervisor-webui start')

def __init__(self, args_str = None):
#print sys.argv[1:]
self._args = None
if not args_str:
args_str = ' '.join(sys.argv[1:])
self._parse_args(args_str)

pdist = platform.dist()[0]

# Whenever Storage setup mode is reconfigure or unconfigure needs to remove below service and a feature
# remove the Storage UI feature
if self._args.storage_setup_mode == 'reconfigure' or self._args.storage_setup_mode == 'unconfigure':
if pdist == 'Ubuntu':
self.contrail_storage_ui_remove()
print 'Storage WebUI configuration removed'

if self._args.storage_setup_mode == 'unconfigure':
return

# Enable the Storage feature to Contrail WebUI
if pdist == 'Ubuntu':
self.contrail_storage_ui_add()

#end __init__

def _parse_args(self, args_str):
'''
Eg. python storage-webui-setup.py --storage-webui-ip 10.157.43.171 --storage-setup-mode setup
'''

# Source any specified config/ini file
# Turn off help, so we print all options in response to -h
conf_parser = argparse.ArgumentParser(add_help = False)

conf_parser.add_argument("-c", "--conf_file",
help="Specify config file", metavar="FILE")
args, remaining_argv = conf_parser.parse_known_args(args_str.split())

global_defaults = {
'storage-webui-ip': '127.0.0.1',
}

if args.conf_file:
config = ConfigParser.SafeConfigParser()
config.read([args.conf_file])
global_defaults.update(dict(config.items("GLOBAL")))

# Override with CLI options
# Don't surpress add_help here so it will handle -h
parser = argparse.ArgumentParser(
# Inherit options from config_parser
parents = [conf_parser],
# print script description with -h/--help
description =__doc__,
# Don't mess with format of description
formatter_class = argparse.RawDescriptionHelpFormatter,
)

all_defaults = {'global': global_defaults}
parser.set_defaults(**all_defaults)
parser.add_argument("--storage-webui-ip", help = "IP Address of storage webui node")
parser.add_argument("--storage-setup-mode", help = "Configuration mode")

self._args = parser.parse_args(remaining_argv)

#end _parse_args

#end class SetupStorageWebUI

def main(args_str = None):
SetupStorageWebUI(args_str)
#end main

if __name__ == "__main__":
main()

0 comments on commit 5c67bf9

Please sign in to comment.