summaryrefslogtreecommitdiffstats
path: root/deploy/rename_nics.py
blob: a460e809a1f9546ef21898bd940d5da20a22a419 (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
import os
import sys
import yaml


def exec_cmd(cmd):
    print cmd
    os.system(cmd)


def rename_nics(dha_info, rsa_file, compass_ip, os_version):
    for host in dha_info['hosts']:
        host_name = host['name']
        interfaces = host.get('interfaces')
        if interfaces:
            for interface in interfaces:
                nic_name = interface.keys()[0]
                mac = interface.values()[0]

                if os_version == 'xenial':
                    exec_cmd("ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
                              -i %s root@%s \
                              'cobbler system edit --name=%s --interface=%s --mac=%s --interface_type=static'"   # noqa
                             % (rsa_file, compass_ip, host_name, nic_name, mac))   # noqa
                else:
                    exec_cmd("ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
                              -i %s root@%s \
                              'cobbler system edit --name=%s --interface=%s --mac=%s'"   # noqa
                             % (rsa_file, compass_ip, host_name, nic_name, mac))  # noqa

    exec_cmd("ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
              -i %s root@%s \
              'cobbler sync'" % (rsa_file, compass_ip))

if __name__ == "__main__":
    assert(len(sys.argv) == 5)
    rename_nics(
        yaml.load(
            open(
                sys.argv[1])),
        sys.argv[2],
        sys.argv[3],
        sys.argv[4])