Skip to content
Snippets Groups Projects
Commit 7b2b241a authored by Stéphane Diemer's avatar Stéphane Diemer
Browse files

Use dirs for sections.

parent 5557dba6
No related branches found
No related tags found
No related merge requests found
Showing
with 88 additions and 126 deletions
#!/usr/bin/python3
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import utils
......
#!/usr/bin/python3
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import utils
......
File moved
File moved
File moved
File moved
File moved
......@@ -4,9 +4,9 @@
# Put your local configuration in conf.sh
# -- Constants --
CYAN='\033[0;36m'
GREEN='\033[0;32m'
RED='\033[0;31m'
CYAN='\033[0;36m'
NC='\033[0m'
# -- System --
......@@ -17,8 +17,6 @@ SKYREACH_API_KEY=
NTP_SERVER1='ntp.ubuntu.com'
NTP_SERVER2=
NTP_SERVER3=
# hosts
ETC_HOSTNAME='mediaserver'
# SSL certificate
SSL_CERTIFICATE='/etc/ssl/certs/ssl-cert-snakeoil.pem'
SSL_CERTIFICATE_KEY='/etc/ssl/private/ssl-cert-snakeoil.key'
......
......@@ -32,32 +32,12 @@ class EnvSetup():
root_dir = utils.get_dir(__file__)
if root_dir != '':
os.chdir(root_dir)
self.root_dir = root_dir
# Add to python path
if root_dir not in sys.path:
sys.path.append(root_dir)
# Get available actions
self.root_dir = root_dir
names = os.listdir(root_dir)
self.actions = list()
for name in names:
path = os.path.join(root_dir, name)
if os.path.isdir(path):
try:
index = int(name.split('.')[0])
except ValueError:
continue
label = name[len(str(index)) + 1:].strip()
if not label:
log('No label found for dir %s.' % name)
continue
if os.path.isfile(os.path.join(path, self.PY_SETUP_NAME)):
setup_module = imp.load_source('setup_%s' % name, os.path.join(path, self.PY_SETUP_NAME))
self.actions.append(dict(index=index, label=label, path=path, fct=setup_module.setup))
elif os.path.isfile(os.path.join(path, self.BASH_SETUP_NAME)):
self.actions.append(dict(index=index, label=label, path=path, fct='bash -e "%s"' % os.path.join(path, self.BASH_SETUP_NAME)))
else:
self.actions.append(dict(index=index, label=label, path=path, fct=None))
self.actions.sort(key=lambda a: a['index'])
self.actions = self.discover_actions()
if not self.actions:
log('No action available.')
sys.exit(1)
......@@ -87,6 +67,43 @@ class EnvSetup():
log('\033[96m- Environment setup for MediaServer -\033[0m')
log('\033[96m-------------------------------------\033[0m')
def discover_actions(self):
actions = list()
for section_name in os.listdir(self.root_dir):
section_path = os.path.join(self.root_dir, section_name)
if not os.path.isdir(section_path):
continue
try:
section_index = int(section_name.split('.')[0])
except ValueError:
continue
section_label = section_name[len(str(section_index)) + 1:].strip().replace('_', ' ')
if not section_label:
log('No label found for dir %s.' % section_name)
continue
actions.append(dict(index=int(str(section_index) + '0'), label=section_label, path=section_path, fct=None))
for name in os.listdir(section_path):
path = os.path.join(section_path, name)
if not os.path.isdir(path):
continue
try:
index = int(str(section_index) + name.split('.')[0])
except ValueError:
continue
label = name[len(str(index)) + 1 - len(str(section_index)):].strip().replace('_', ' ')
if not label:
log('No label found for dir %s.' % name)
continue
if os.path.isfile(os.path.join(path, self.PY_SETUP_NAME)):
setup_module = imp.load_source('setup_%s' % name, os.path.join(path, self.PY_SETUP_NAME))
actions.append(dict(index=index, label=label, path=path, fct=setup_module.setup))
elif os.path.isfile(os.path.join(path, self.BASH_SETUP_NAME)):
actions.append(dict(index=index, label=label, path=path, fct='bash -e "%s"' % os.path.join(path, self.BASH_SETUP_NAME)))
actions.sort(key=lambda a: a['index'])
return actions
def menu(self):
# Show main menu
log('Actions:')
......
......@@ -18,140 +18,87 @@ exec > >(tee -i ${LOGFILE})
## envsetup integration
init() {
python3 /root/envsetup/envsetup.py 1
python3 /root/envsetup/envsetup.py 2
python3 /root/envsetup/envsetup.py 11
python3 /root/envsetup/envsetup.py 12
python3 /root/envsetup/envsetup.py 13
python3 /root/envsetup/envsetup.py 31
python3 /root/envsetup/envsetup.py 32
python3 /root/envsetup/envsetup.py 33
python3 /root/envsetup/envsetup.py 34
python3 /root/envsetup/envsetup.py 21
python3 /root/envsetup/envsetup.py 22
python3 /root/envsetup/envsetup.py 23
python3 /root/envsetup/envsetup.py 24
python3 /root/envsetup/envsetup.py 4
}
monitor() {
python3 /root/envsetup/envsetup.py 3
python3 /root/envsetup/envsetup.py 6
python3 /root/envsetup/envsetup.py 7
python3 /root/envsetup/envsetup.py 31
python3 /root/envsetup/envsetup.py 23
python3 /root/envsetup/envsetup.py 25
python3 /root/envsetup/envsetup.py 26
python3 /root/envsetup/envsetup.py 41
}
mediaserver() {
python3 /root/envsetup/envsetup.py 3
python3 /root/envsetup/envsetup.py 5
python3 /root/envsetup/envsetup.py 8
python3 /root/envsetup/envsetup.py 61
python3 /root/envsetup/envsetup.py 6
python3 /root/envsetup/envsetup.py 41
python3 /root/envsetup/envsetup.py 42
python3 /root/envsetup/envsetup.py 6
python3 /root/envsetup/envsetup.py 23
python3 /root/envsetup/envsetup.py 24
python3 /root/envsetup/envsetup.py 71
python3 /root/envsetup/envsetup.py 25
python3 /root/envsetup/envsetup.py 51
python3 /root/envsetup/envsetup.py 52
python3 /root/envsetup/envsetup.py 25
}
worker() {
python3 /root/envsetup/envsetup.py 62
python3 /root/envsetup/envsetup.py 72
}
campusmanager() {
python3 /root/envsetup/envsetup.py 3
python3 /root/envsetup/envsetup.py 6
python3 /root/envsetup/envsetup.py 51
python3 /root/envsetup/envsetup.py 6
python3 /root/envsetup/envsetup.py 23
python3 /root/envsetup/envsetup.py 25
python3 /root/envsetup/envsetup.py 61
python3 /root/envsetup/envsetup.py 25
}
cache() {
python3 /root/envsetup/envsetup.py 71
python3 /root/envsetup/envsetup.py 72
python3 /root/envsetup/envsetup.py 73
python3 /root/envsetup/envsetup.py 42
python3 /root/envsetup/envsetup.py 81
python3 /root/envsetup/envsetup.py 82
python3 /root/envsetup/envsetup.py 83
}
tests() {
python3 /root/envsetup/envsetup.py t
python3 /root/envsetup/tester.py
}
backup_server() {
python3 /root/envsetup/envsetup.py 81
}
reconf_default() {
python3 /root/envsetup/envsetup.py 104
python3 /root/envsetup/envsetup.py 91
}
reconf_client() {
python3 /root/envsetup/envsetup.py 101
python3 /root/envsetup/envsetup.py 201
}
reconf_recette() {
python3 /root/envsetup/envsetup.py 102
reconf_dump_config() {
python3 /root/envsetup/envsetup.py 202
}
reconf_smtp() {
python3 /root/envsetup/envsetup.py 103
python3 /root/envsetup/envsetup.py 203
}
reconf_default() {
python3 /root/envsetup/envsetup.py 204
}
WOWZA_LICENSE() {
python3 /root/envsetup/envsetup.py 105
python3 /root/envsetup/envsetup.py 205
}
exportvm() {
KEY=~/.ssh/ubicast_support
VM_HYPER=$(grep VM_HYPER ${CONF} | awk -F "=" '{print$2}')
VM_STORE=$(grep VM_STORE ${CONF} | head -1 | awk -F "=" '{print$2}')
VM_STORE_LOCAL=$(grep VM_STORE_LOCAL ${CONF} | awk -F "=" '{print$2}')
if ( test -z $VM_NAME ); then
VM_NAME=$(cat ${CONF} | egrep ^ETC_HOSTNAME | head -1 | awk -F "=" '{print$2}')
else
VM_NAME=$(grep VM ${CONF} | awk -F "=" '{print$2}')
fi
ssh -i ${KEY} -o User=root ${VM_HYPER} "VBoxManage export ${VM_NAME} -o ${VM_STORE}/${VM_NAME}.ovf --ovf10"
# vbox conf file created
# generating vmware conf file
cp ${VM_STORE_LOCAL}/${VM_NAME}.ovf ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
sed -i "s@<vssd:VirtualSystemType>virtualbox-2.2</vssd:VirtualSystemType>@<vssd:VirtualSystemType>vmx-07</vssd:VirtualSystemType>@" ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
sed -i "s@<rasd:Caption>sataController0</rasd:Caption>@<rasd:Caption>SCSIController</rasd:Caption>@" ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
sed -i "s@<rasd:Description>SATA Controller</rasd:Description>@<rasd:Description>SCSIController</rasd:Description>@" ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
sed -i "s@<rasd:ElementName>sataController0</rasd:ElementName>@<rasd:ElementName>SCSIController</rasd:ElementName>@" ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
sed -i "s@<rasd:ResourceSubType>AHCI</rasd:ResourceSubType>@<rasd:ResourceSubType>lsilogic</rasd:ResourceSubType>@" ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
sed -i "s@<rasd:ResourceType>20</rasd:ResourceType>@<rasd:ResourceType>6</rasd:ResourceType>@" ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
# recherche n° ligne paragraphe à supp.
LIG=$(grep -n '<rasd:AddressOnParent>3</rasd:AddressOnParent>' ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf | awk -F ":" '{print$1}')
LIG0=$(( $LIG - 1 ))
LIG1=$(( $LIG0 + 9 ))
sed -i "${LIG0},${LIG1}d" ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
# converting disk to qemu image
qemu-img convert -c -O qcow2 ${VM_STORE_LOCAL}/${VM_NAME}-disk1.vmdk ${VM_STORE_LOCAL}/${VM_NAME}.qcow2
echo -e "${CYAN}Files are available at ${VM_STORE_LOCAL}${NC}"
python3 /root/envsetup/envsetup.py 101
}
exportvm_local(){
VM_STORE=/home/jallary/ubicast/TMP/ENVOI
VM_STORE_LOCAL=/home/jallary/ubicast/TMP/ENVOI
# depuis poste local
VBoxManage export ${VM_NAME} -o ${VM_STORE}/${VM_NAME}.ovf --ovf10
# generating vmware conf file
cp ${VM_STORE_LOCAL}/${VM_NAME}.ovf ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
sed -i "s@<vssd:VirtualSystemType>virtualbox-2.2</vssd:VirtualSystemType>@<vssd:VirtualSystemType>vmx-07</vssd:VirtualSystemType>@" ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
sed -i "s@<rasd:Caption>sataController0</rasd:Caption>@<rasd:Caption>SCSIController</rasd:Caption>@" ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
sed -i "s@<rasd:Description>SATA Controller</rasd:Description>@<rasd:Description>SCSIController</rasd:Description>@" ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
sed -i "s@<rasd:ElementName>sataController0</rasd:ElementName>@<rasd:ElementName>SCSIController</rasd:ElementName>@" ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
sed -i "s@<rasd:ResourceSubType>AHCI</rasd:ResourceSubType>@<rasd:ResourceSubType>lsilogic</rasd:ResourceSubType>@" ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
sed -i "s@<rasd:ResourceType>20</rasd:ResourceType>@<rasd:ResourceType>6</rasd:ResourceType>@" ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
# recherche n° ligne paragraphe à supp.
LIG=$(grep -n '<rasd:AddressOnParent>3</rasd:AddressOnParent>' ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf | awk -F ":" '{print$1}')
LIG0=$(( $LIG - 1 ))
LIG1=$(( $LIG0 + 9 ))
sed -i "${LIG0},${LIG1}d" ${VM_STORE_LOCAL}/${VM_NAME}_vmware.ovf
# converting disk to qemu image
qemu-img convert -c -O qcow2 ${VM_STORE_LOCAL}/${VM_NAME}-disk1.vmdk ${VM_STORE_LOCAL}/${VM_NAME}.qcow2
echo -e "${CYAN}Files are available at ${VM_STORE_LOCAL}${NC}"
python3 /root/envsetup/envsetup.py 102
}
case "$1" in
......@@ -192,17 +139,17 @@ case "$1" in
"client")
reconf_client
reconf_recette
reconf_dump_config
reconf_smtp
;;
"recette")
reconf_recette
reconf_dump_config
;;
"wrecette")
WOWZA_LICENSE
reconf_recette
reconf_dump_config
;;
"exportvm")
......
#!/usr/bin/python3
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from collections import OrderedDict
import os
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment