fuel-plugin-mellanox/scripts/create_mellanox_bootstrap

93 lines
3.7 KiB
Python
Executable File

#!/usr/bin/env python
# Copyright 2016 Mellanox Technologies, Ltd
#
# 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.
import yaml
import os
import time
import subprocess
import sys
import argparse
import textwrap
# Load the defaults
DEFAULT_MAX_NUM_VFS = 16
parser = argparse.ArgumentParser(
prog=os.path.basename(sys.argv[0]),
formatter_class=argparse.RawDescriptionHelpFormatter,
description=textwrap.dedent('''\
Available link_type values are:
-------------------------------
- eth for changing link type to Ethernet
- ib for changing link type to Infiniband
- current for leaving link type as is
'''))
parser.add_argument("--link_type", choices=['eth', 'ib', 'current'])
parser.add_argument("--max_num_vfs", type=int, default = DEFAULT_MAX_NUM_VFS,
help='an integer for the maximum number of vfs to be burned in bootstrap')
args = parser.parse_args()
if not args.link_type:
parser.print_help()
sys.exit(1)
else:
if 'current' in args.link_type:
link_type=""
else:
link_type = "_{0}".format(args.link_type)
os.environ['MAX_NUM_VFS'] = '{0}'.format(args.max_num_vfs)
# Set variables
plugin = subprocess.Popen("echo /var/www/nailgun/plugins/mellanox-plugin-*/ " +
"| tr '/' '\n' | grep mellanox-plugin | tr -d '\n' ",
shell=True, stdout=subprocess.PIPE).stdout.read()
plugin_uri = "http://127.0.0.1:8080/plugins/%s/repositories/ubuntu/" % plugin
current_time = time.strftime("%d_%m_%y_%H_%M")
# Set fuel-bootstrap yaml and build image
with open("/etc/fuel-bootstrap-cli/fuel_bootstrap_cli.yaml", 'r') as stream:
fuel_bootstrap_config = yaml.load(stream)
override = False
repos_names = [repo['name'] for repo in fuel_bootstrap_config['repos']]
# Verify Mellanox repo
if 'mlnx' not in repos_names:
fuel_bootstrap_config['repos'].append({'priority': 1100,
'name': 'mlnx',
'suite': '/',
'section': None,
'type': 'deb',
'uri': plugin_uri})
# Override fuel bootstrap yaml
with open("/etc/fuel-bootstrap-cli/fuel_bootstrap_cli.yaml", "w") as f:
yaml.dump(fuel_bootstrap_config, f)
extra_packages = ['mlnx-ofed-fuel', 'python-libxml2', 'lsof', 'curl',
'libgfortran3', 'tk', 'swig', 'm4', 'autoconf',
'tcl8.4', 'flex', 'dpatch', 'gfortran', 'libltdl-dev',
'autotools-dev', 'quilt', 'automake', 'pkg-config',
'chrpath', 'debhelper', 'tk8.4', 'graphviz', 'bison',
'tcl']
packages = ''.join(['--package %s ' % p for p in extra_packages])
extra_dir = "/var/www/nailgun/plugins/%s/bootstrap/sync" % plugin
cmd = "fuel-bootstrap build --debug {0} --extra-dir {1} \
--label 'bootstrap_with_ofed{3}_{2}' \
--output-dir /tmp/ \
--script {1}/opt/mellanox_init{3}.sh \
--activate".format(packages, extra_dir, current_time, link_type)
os.system(cmd)