summaryrefslogtreecommitdiffstats
path: root/ci/depMAAS.py
diff options
context:
space:
mode:
authorNarinder Gupta <narinder.gupta@canonical.com>2016-11-22 00:08:26 -0600
committerNarinder Gupta <narinder.gupta@canonical.com>2016-11-22 00:09:07 -0600
commit491d268009938eb6ce21ad4636bdd5130935f011 (patch)
tree79154ba1e6e5b163d2b0951bcfb061c2e03432fd /ci/depMAAS.py
parent28dfad8d1fe46eccea5f3ca108914239e313ae0f (diff)
modified to accomodate the MAAS 2.0
Change-Id: Id17ba35d82103b082136b91a694bf3a6f18d9c8d Signed-off-by: Narinder Gupta <narinder.gupta@canonical.com>
Diffstat (limited to 'ci/depMAAS.py')
-rw-r--r--ci/depMAAS.py102
1 files changed, 102 insertions, 0 deletions
diff --git a/ci/depMAAS.py b/ci/depMAAS.py
new file mode 100644
index 00000000..5592bc46
--- /dev/null
+++ b/ci/depMAAS.py
@@ -0,0 +1,102 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+"""
+This script generates a maas deployer config based on lab config file.
+
+Parameters:
+ -l, --lab : lab config file
+"""
+
+from optparse import OptionParser
+from jinja2 import Environment, FileSystemLoader
+from distutils.version import LooseVersion, StrictVersion
+import os
+import subprocess
+import yaml
+from pprint import pprint as pp
+import socket
+import fcntl
+import struct
+
+#
+# Parse parameters
+#
+
+parser = OptionParser()
+parser.add_option("-l", "--lab", dest="lab", help="lab config file")
+(options, args) = parser.parse_args()
+labconfig_file = options.lab
+
+#
+# Set Path and configs path
+#
+
+# Capture our current directory
+jujuver = subprocess.check_output(["juju", "--version"])
+
+if LooseVersion(jujuver) >= LooseVersion('2'):
+ TPL_DIR = os.path.dirname(os.path.abspath(__file__))+'/config_tpl/maas_tpl'
+else:
+ TPL_DIR = os.path.dirname(os.path.abspath(__file__))+'/config_tpl/maas2/maas_tpl'
+
+HOME = os.environ['HOME']
+USER = os.environ['USER']
+
+#
+# Prepare variables
+#
+
+# Prepare a storage for passwords
+passwords_store = dict()
+
+#
+# Local Functions
+#
+
+
+def load_yaml(filepath):
+ """Load YAML file"""
+ with open(filepath, 'r') as stream:
+ try:
+ return yaml.load(stream)
+ except yaml.YAMLError as exc:
+ print(exc)
+
+
+def get_ip_address(ifname):
+ """Get local IP"""
+ s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+ return socket.inet_ntoa(fcntl.ioctl(
+ s.fileno(),
+ 0x8915, # SIOCGIFADDR
+ struct.pack('256s', bytes(ifname.encode('utf-8')[:15]))
+ )[20:24])
+
+
+#
+# Config import
+#
+
+def installMAAS():
+ subprocess.call(["echo", i], shell=True)
+
+def configMAAS():
+
+
+# Create the jinja2 environment.
+env = Environment(loader=FileSystemLoader(TPL_DIR),
+ trim_blocks=True)
+template = env.get_template('deployment.yaml')
+
+# Render the template
+output = template.render(**config)
+
+# Check output syntax
+try:
+ yaml.load(output)
+except yaml.YAMLError as exc:
+ print(exc)
+
+# print output
+print(output)