summaryrefslogtreecommitdiffstats
path: root/ci/deploy.py
blob: 0ca0b778ea784964189b54676efa17b7e92e3068 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .ow { color: #f92672 } /* Operator.Word */
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
.highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
.highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
.highlight .sa { color: #e6db74 } /* Literal.String.Affix */
.highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
.highlight .sc { color: #e6db74 } /* Literal.String.Char */
.highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */
.highlight .sd { color: #e6db74 } /* Literal.String.Doc */
.highlight .s2 { color: #e6db74 } /* Literal.String.Double */
.highlight .se { color: #ae81ff } /* Literal.String.Escape */
.highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */
.highlight .si { color: #e6db74 } /* Literal.String.Interpol */
.highlight .sx { color: #e6db74 } /* Literal.String.Other */
.highlight .sr { color: #e6db74 } /* Literal.String.Regex */
.highlight .s1 { color: #e6db74 } /* Literal.String.Single */
.highlight .ss { color: #e6db74 } /* Literal.String.Symbol */
.highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #a6e22e } /* Name.Function.Magic */
.highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */
.highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */
.highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */
.highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */
.highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */
}
@media (prefers-color-scheme: light) {
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
}
---
# Sample benchmark task config file
# measure network latency using ping

schema: "yardstick:task:0.1"

scenarios:
-
  type: Ping
  options:
    packetsize: 200
  host: athena.demo
  target:
@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .ow { color: #f92672 } /* Operator.Word */
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
.highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
.highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
.highlight .sa { color: #e6db74 } /* Literal.String.Affix */
.highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
.highlight .sc { color: #e6db74 } /* Literal.String.Char */
.highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */
.highlight .sd { color: #e6db74 } /* Literal.String.Doc */
.highlight .s2 { color: #e6db74 } /* Literal.String.Double */
.highlight .se { color: #ae81ff } /* Literal.String.Escape */
.highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */
.highlight .si { color: #e6db74 } /* Literal.String.Interpol */
.highlight .sx { color: #e6db74 } /* Literal.String.Other */
.highlight .sr { color: #e6db74 } /* Literal.String.Regex */
.highlight .s1 { color: #e6db74 } /* Literal.String.Single */
.highlight .ss { color: #e6db74 } /* Literal.String.Symbol */
.highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #a6e22e } /* Name.Function.Magic */
.highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */
.highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */
.highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */
.highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */
.highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */
}
@media (prefers-color-scheme: light) {
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
}
#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
Deploy JOID
"""

import yaml
import socket
import fcntl
import struct
import getpass


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', ifname[:15])
    )[20:24])

with open('labconfig.yaml', 'r') as labf:
    try:
        labcfg = yaml.load(labf)
    except yaml.YAMLError as exc:
        print(exc)


opnfvcfg = {}
opnfvlabcfg = {}


def get_from_dict(dataDict, mapList):
    return reduce(lambda d, k: d[k], mapList, dataDict)

# lets define the bootstrap section
opnfvcfg['demo-maas'] = {'juju-bootstrap': {'memory': 4096,
                                            'name': "bootstrap",
                                            'pool': "default",
                                            'vcpus': 4,
                                            'disk_size': "60G",
                                            'arch': "amd64",
                                            'interfaces': []},
                         'maas': {'memory': 4096,
                                  'pool': "default",
                                  'vcpus': 4,
                                  'disk_size': "160G",
                                  'arch': "amd64",
                                  'interfaces': [],
                                  'name': "",
                                  'network_config': [],
                                  'node_group_ifaces': [],
                                  'nodes': [],
                                  'password': 'ubuntu',
                                  'user': 'ubuntu',
                                  'release': 'trusty',
                                  'apt_sources': [],
                                  'ip_address': '',
                                  'boot_source': {
                                        'keyring_filename': "/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg",
                                        'url': "http://maas.ubuntu.com/images/ephemeral-v2/releases/",
                                        'selections': {
                                            '1': {
                                                'arches': 'amd64',
                                                'labels': 'release',
                                                'os': 'ubuntu',
                                                'release': 'xenial',
                                                'subarches': '*'
                                             }
                                         }
                                     },
                                  'settings': {'maas_name': '',
                                               'upstream_dns': '',
                                               'main_archive': "http://archive.ubuntu.com/ubuntu"
                                               },
                                  'virsh': {'rsa_priv_key': '/home/ubuntu/.ssh/id_rsa',
                                            'rsa_pub_key': '/home/ubuntu/.ssh/id_rsa.pub',
                                            'uri': ''
                                            }
                                  }
                         }

opnfvlabcfg['opnfv'] = {'ext-port': '',
                        'floating-ip-range': '',
                        'dataNetwork': '',
                        'ceph-disk': '/srv/',
                        'storageNetwork': '',
                        'interface-enable': '',
                        'publicNetwork': '',
                        'os-domain-name': '',
                        'vip': {'rabbitmq': '',
                                'dashboard': '',
                                'glance': '',
                                'keystone': '',
                                'ceilometer': '',
                                'mysql': '',
                                'nova': '',
                                'neutron': '',
                                'heat': '',
                                'cinder': ''}
                        }


opnfvcfg['demo-maas']['maas']['apt_sources'].append("ppa:maas/stable")
opnfvcfg['demo-maas']['maas']['apt_sources'].append("ppa:juju/stable")

# lets modify the maas general settings:

updns = get_from_dict(labcfg, ["lab", "racks", 0, "dns"])
opnfvcfg["demo-maas"]["maas"]["settings"]["upstream_dns"] = updns

location = get_from_dict(labcfg, ["lab", "location"])
rack = get_from_dict(labcfg, ["lab", "racks", 0, "rack"])
value = location+rack

opnfvcfg["demo-maas"]["maas"]["settings"]["maas_name"] = value
opnfvcfg["demo-maas"]["maas"]["name"] = "opnfv-"+value

ethbrAdm = ""
ethbrAdmin = ""

c = 0
y = 0
# z = 0

while c < len(labcfg["opnfv"]["spaces"]):
    brtype = get_from_dict(labcfg, ["opnfv", "spaces", c, "type"])
    brname = get_from_dict(labcfg, ["opnfv", "spaces", c, "bridge"])
    brcidr = get_from_dict(labcfg, ["opnfv", "spaces", c, "cidr"])
#
    if brtype == "admin":
        ethbrAdmin = get_from_dict(labcfg, ["opnfv", "spaces", c, "bridge"])
        brgway = get_from_dict(labcfg, ["opnfv", "spaces", c, "gateway"])
        tmpcidr = brcidr[:-4]
        opnfvlabcfg["opnfv"]["admNetwork"] = tmpcidr+"2"
        opnfvlabcfg["opnfv"]["admNetgway"] = brgway

        nodegroup = {"device": "eth"+str(y),
                     "ip": tmpcidr+"5",
                     "subnet_mask": "255.255.255.0",
                     "broadcast_ip": tmpcidr+"255",
                     "router_ip": brgway,
                     "static_range": {"high": tmpcidr+"80",
                                      "low": tmpcidr+"50"},
                     "dynamic_range": {"high": tmpcidr+"250",
                                       "low": tmpcidr+"81"}}

        ethbrAdm = ('auto lo\n'
                    '    iface lo inet loopback\n\n'
                    'auto eth'+str(y)+'\n'
                    '    iface eth'+str(y)+' inet static\n'
                    '    address '+tmpcidr+'5\n'
                    '    netmask 255.255.255.0\n'
                    '    gateway '+brgway+'\n'
                    '    dns-nameservers '+updns+' '+tmpcidr+'5 127.0.0.1\n')

        opnfvcfg['demo-maas']['maas']['ip_address'] = tmpcidr+"5"
        opnfvcfg['demo-maas']['maas']['interfaces'].append(
            "bridge="+brname+",model=virtio")
        opnfvcfg['demo-maas']['juju-bootstrap']['interfaces'].append(
            "bridge="+brname+",model=virtio")
        opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"].append(nodegroup)
        y = y+1
    elif brtype:
        opnfvcfg["demo-maas"]["maas"]["interfaces"].append(
            "bridge="+brname+",model=virtio")
        brgway = get_from_dict(labcfg, ["opnfv", "spaces", c, "gateway"])
        if brtype != "external":
            tmpcidr = brcidr[:-4]
            if brgway:
                nodegroup = {"device": "eth"+str(y),
                             "ip": tmpcidr+"5",
                             "subnet_mask": "255.255.255.0",
                             "broadcast_ip": tmpcidr+"255",
                             "management": 1,
                             "router_ip": brgway,
                             "static_range": {"high": tmpcidr+"80",
                                              "low": tmpcidr+"50"},
                             "dynamic_range": {"high": tmpcidr+"250",
                                               "low": tmpcidr+"81"}}
            else:
                nodegroup = {"device": "eth"+str(y),
                             "ip": tmpcidr+"5",
                             "subnet_mask": "255.255.255.0",
                             "broadcast_ip": tmpcidr+"255",
                             "management": 1,
                             "static_range": {"high": tmpcidr+"80",
                                              "low": tmpcidr+"50"},
                             "dynamic_range": {"high": tmpcidr+"250",
                                               "low": tmpcidr+"81"}}
            opnfvcfg["demo-maas"]["maas"]["node_group_ifaces"].append(
                nodegroup)
            ethbrAdm = (ethbrAdm+'\n'
                        'auto eth'+str(y)+'\n'
                        '    iface eth'+str(y)+' inet static\n'
                        '    address '+tmpcidr+'5\n'
                        '    netmask 255.255.255.0\n')
            y = y+1
        if brtype == "public":
            opnfvcfg["demo-maas"]["juju-bootstrap"]["interfaces"].append(
                "bridge="+brname+",model=virtio")
            opnfvlabcfg["opnfv"]["publicNetwork"] = brcidr
        if brtype == "external":
            ipaddress = get_from_dict(labcfg, ["opnfv", "spaces",
                                               c, "ipaddress"])
            ethbrAdm = (ethbrAdm+'\n'
                        'auto eth'+str(y)+'\n'
                        '    iface eth'+str(y)+' inet static\n'
                        '    address '+ipaddress+'\n'
                        '    netmask 255.255.255.0\n')
            opnfvcfg["demo-maas"]["juju-bootstrap"]["interfaces"].append(
                "bridge="+brname+",model=virtio")
        if brtype == "data":
            opnfvlabcfg["opnfv"]["dataNetwork"] = brcidr
        if brtype == "storage":
            opnfvlabcfg["opnfv"]["storageNetwork"] = brcidr

    c = c+1

# lets modify the maas general settings:
value = get_ip_address(ethbrAdmin)
value = "qemu+ssh://"+getpass.getuser()+"@"+value+"/system"
opnfvcfg['demo-maas']['maas']['virsh']['uri'] = value
opnfvcfg['demo-maas']['maas']['network_config'] = ethbrAdm

if len(labcfg["lab"]["racks"][0]["nodes"]) < 1:
    print("looks like virtual deployment where nodes were not defined")
    opnfvcfg["demo-maas"]["maas"]["nodes"].remove()
    exit()

# lets insert the node details here:
c = 0
ifnamelist = []
#
while c < len(labcfg["lab"]["racks"][0]["nodes"]):
    valuemac = []
    y = 0
    # setup value of name and tags accordigly
    noderoleslist = labcfg["lab"]["racks"][0]["nodes"][c]["roles"]
    noderoles = " ".join(noderoleslist)

    valuetype = get_from_dict(labcfg, ["lab", "racks", 0, "nodes",
                                       c, "power", "type"])
    namevalue = labcfg["lab"]["racks"][0]["nodes"][c]["name"]
    valuearc = get_from_dict(labcfg, ["lab", "racks", 0,
                                      "nodes", c, "architecture"])
    # setup value of architecture
    if valuearc == "x86_64":
        valuearc = "amd64/generic"

    if valuetype == "wakeonlan":
        macvalue = get_from_dict(labcfg, ["lab", "racks", 0, "nodes",
                                          c, "power", "mac_address"])
        power = {"type": "ether_wake", "mac_address": macvalue}
    if valuetype == "ipmi":
        valueaddr = get_from_dict(labcfg, ["lab", "racks", 0, "nodes", c,
                                           "power", "address"])
        valueuser = get_from_dict(labcfg, ["lab", "racks", 0, "nodes", c,
                                           "power", "user"])
        valuepass = get_from_dict(labcfg, ["lab", "racks", 0, "nodes", c,
                                           "power", "pass"])
        valuedriver = "LAN_2_0"
        power = {"type": valuetype, "address": valueaddr, "user": valueuser,
                 "pass": valuepass, "driver": valuedriver}

    opnfvcfg["demo-maas"]["maas"]["nodes"].append(
            {"name": namevalue,
             "architecture": valuearc,
             "interfaces": [],
             "mac_addresses": [],
             "power": power,
             'tags': noderoles})

    y = 0
    while y < len(labcfg["lab"]["racks"][0]["nodes"][c]["nics"]):
        valuespaces = labcfg["lab"]["racks"][0]["nodes"][c][
                        "nics"][y]["spaces"]
        valueifname = labcfg["lab"]["racks"][0]["nodes"][c][
                        "nics"][y]["ifname"]
        if "admin" not in valuespaces:
            ifnamelist += [valueifname]
        valueifmac = labcfg["lab"]["racks"][0]["nodes"][c]["nics"][y]["mac"][0]
        valuemac += labcfg["lab"]["racks"][0]["nodes"][c]["nics"][y]["mac"]
        opnfvcfg["demo-maas"]["maas"]["nodes"][c]["interfaces"].append(
                {"name": valueifname,
                 "mac_address": valueifmac,
                 "mode": "auto"})
        y = y+1

    if valueifmac:
        opnfvcfg["demo-maas"]["maas"]["nodes"][c]['mac_addresses'] = valuemac

    c = c+1

opnfvlabcfg["opnfv"]["floating-ip-range"] =\
    labcfg["lab"]["racks"][0]["floating-ip-range"]
opnfvlabcfg["opnfv"]["ext-port"] =\
    labcfg["lab"]["racks"][0]["ext-port"]
opnfvlabcfg["opnfv"]["ceph-disk"] =\
    labcfg["opnfv"]["storage"][0]["disk"]
opnfvlabcfg["opnfv"]["interface-enable"] =\
    ",".join(list(set(ifnamelist)))

# setup vip addresss for HA
opnfvlabcfg["opnfv"]["vip"]["rabbitmq"] =\
    opnfvlabcfg["opnfv"]["admNetwork"]+"0"
opnfvlabcfg["opnfv"]["vip"]["dashboard"] =\
    opnfvlabcfg["opnfv"]["admNetwork"]+"1"
opnfvlabcfg["opnfv"]["vip"]["glance"] = opnfvlabcfg["opnfv"]["admNetwork"]+"2"
opnfvlabcfg["opnfv"]["vip"]["keystone"] =\
    opnfvlabcfg["opnfv"]["admNetwork"]+"3"
opnfvlabcfg["opnfv"]["vip"]["ceilometer"] =\
    opnfvlabcfg["opnfv"]["admNetwork"]+"4"
opnfvlabcfg["opnfv"]["vip"]["mysql"] = opnfvlabcfg["opnfv"]["admNetwork"]+"5"
opnfvlabcfg["opnfv"]["vip"]["nova"] = opnfvlabcfg["opnfv"]["admNetwork"]+"6"
opnfvlabcfg["opnfv"]["vip"]["neutron"] = opnfvlabcfg["opnfv"]["admNetwork"]+"7"
opnfvlabcfg["opnfv"]["vip"]["heat"] = opnfvlabcfg["opnfv"]["admNetwork"]+"8"
opnfvlabcfg["opnfv"]["vip"]["cinder"] = opnfvlabcfg["opnfv"]["admNetwork"]+"9"

osdomname = labcfg["lab"]["racks"][0]["osdomainname"]

if osdomname:
    opnfvlabcfg["opnfv"]["os-domain-name"] =\
        labcfg["lab"]["racks"][0]["osdomainname"]
    opnfvlabcfg["opnfv"]["domain"] = labcfg["lab"]["racks"][0]["osdomainname"]

opnfvlabcfg["opnfv"]["ext_port"] = labcfg["lab"]["racks"][0]["ext-port"]
opnfvlabcfg["opnfv"]["units"] = len(labcfg["lab"]["racks"][0]["nodes"])
opnfvlabcfg["opnfv"]["admin_password"] = "openstack"
opnfvlabcfg["opnfv"]["storage"] = labcfg["opnfv"]["storage"]
opnfvlabcfg["opnfv"]["spaces"] = labcfg["opnfv"]["spaces"]

with open('deployment.yaml', 'wa') as opnfvf:
    yaml.dump(opnfvcfg, opnfvf, default_flow_style=False)

with open('deployconfig.yaml', 'wa') as opnfvf:
    yaml.dump(opnfvlabcfg, opnfvf, default_flow_style=False)