~springfield-team/charms/trusty/vem/next

« back to all changes in this revision

Viewing changes to hooks/config_changed.py

  • Committer: Shiva Prasad Rao
  • Date: 2014-08-27 23:27:48 UTC
  • Revision ID: shivrao@cisco.com-20140827232748-4hr02ge6vtbrep8y
Addressing review comments

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
2
 
# config-changed occurs everytime a new configuration value is updated (juju set)
 
2
# config-changed occurs everytime a new configuration
 
3
# value is updated (juju set)
3
4
 
4
5
import subprocess
5
6
import socket
15
16
    host_conf = common.get_host_specific_config(hostname)
16
17
    with open('data.yaml', 'r') as f:
17
18
        temp = f.read()
18
 
        n1kv_conf_data = yaml.load(temp, Loader=yaml.loader.BaseLoader)
19
 
        if (config('n1kv-source') != n1kv_conf_data["n1kv_conf"]["n1kv-source"]) or (config('n1kv-version') != n1kv_conf_data["n1kv_conf"]["n1kv-version"]):
 
19
        data = yaml.load(temp, Loader=yaml.loader.BaseLoader)
 
20
        if ((config('n1kv-source') != data["n1kv_conf"]["n1kv-source"]) or
 
21
            (config('n1kv-version') != data["n1kv_conf"]["n1kv-version"])):
20
22
            subprocess.call("hooks/install")
21
 
        n1kv_conf_data["n1kv_conf"]["n1kv-source"] = config('n1kv-source')
22
 
        n1kv_conf_data["n1kv_conf"]["n1kv-version"] = config('n1kv-version')
23
 
        if (n1kv_conf_data["n1kv_conf"]["vsm_conf_from_rel"] == "false"):
24
 
            n1kv_conf_data["n1kv_conf"]["n1kv-vsm-ip"] = host_conf['n1kv-vsm-ip']
25
 
            n1kv_conf_data["n1kv_conf"]["n1kv-vsm-domain-id"] = host_conf['n1kv-vsm-domain-id']
26
 
        n1kv_conf_data["n1kv_conf"]["host_mgmt_intf"] = host_conf['host_mgmt_intf']
27
 
        n1kv_conf_data["n1kv_conf"]["uplink_profile"] = host_conf['uplink_profile']
28
 
        n1kv_conf_data["n1kv_conf"]["node_type"] = host_conf['node_type']
29
 
        n1kv_conf_data["n1kv_conf"]["vtep_in_same_subnet"] = host_conf['vtep_in_same_subnet']
 
23
        data["n1kv_conf"]["n1kv-source"] = config('n1kv-source')
 
24
        data["n1kv_conf"]["n1kv-version"] = config('n1kv-version')
 
25
        if (data["n1kv_conf"]["vsm_conf_from_rel"] == "false"):
 
26
            data["n1kv_conf"]["n1kv-vsm-ip"] = host_conf['n1kv-vsm-ip']
 
27
            data["n1kv_conf"]["n1kv-vsm-domain-id"] = \
 
28
                host_conf['n1kv-vsm-domain-id']
 
29
        data["n1kv_conf"]["host_mgmt_intf"] = host_conf['host_mgmt_intf']
 
30
        data["n1kv_conf"]["uplink_profile"] = host_conf['uplink_profile']
 
31
        data["n1kv_conf"]["node_type"] = host_conf['node_type']
 
32
        data["n1kv_conf"]["vtep_in_same_subnet"] = \
 
33
            host_conf['vtep_in_same_subnet']
30
34
        if 'vtep_config' in host_conf:
31
 
            n1kv_conf_data["n1kv_conf"]["vtep_config"] = host_conf['vtep_config']
 
35
            data["n1kv_conf"]["vtep_config"] = host_conf['vtep_config']
32
36
    with open('data.yaml', 'w') as f:
33
 
        f.write(yaml.dump(n1kv_conf_data, default_flow_style=True))
 
37
        f.write(yaml.dump(data, default_flow_style=True))
34
38
 
35
 
    if n1kv_conf_data["n1kv_conf"]["vtep_in_same_subnet"] == "yes":
36
 
        #if not os.path.isfile("/etc/sysctl.d/60-n1kv.conf"):
 
39
    if data["n1kv_conf"]["vtep_in_same_subnet"] == "yes":
37
40
        f = open("/etc/sysctl.d/60-n1kv.conf", 'w')
38
 
        f.writelines(["net.ipv4.conf.default.rp_filter=2\n", "net.ipv4.conf.all.rp_filter=2\n", "net.ipv4.conf.default.arp_ignore=1\n", "net.ipv4.conf.all.arp_ignore=1\n", "net.ipv4.conf.all.arp_announce=2\n", "net.ipv4.conf.default.arp_announce=2\n"])
 
41
        f.writelines(["net.ipv4.conf.default.rp_filter=2\n",
 
42
                      "net.ipv4.conf.all.rp_filter=2\n",
 
43
                      "net.ipv4.conf.default.arp_ignore=1\n",
 
44
                      "net.ipv4.conf.all.arp_ignore=1\n",
 
45
                      "net.ipv4.conf.all.arp_announce=2\n",
 
46
                      "net.ipv4.conf.default.arp_announce=2\n"])
39
47
        f.close()
40
48
        subprocess.call(["sysctl", "-p", "/etc/sysctl.d/60-n1kv.conf"])
41
49
 
42
50
    common.update_n1kv_config()
43
51
    #Enable all required uplink on the host (ifconfig <interface> up)
44
 
    common.enable_uplink(n1kv_conf_data["n1kv_conf"]["uplink_profile"])
45
 
    common.enable_uplink(n1kv_conf_data["n1kv_conf"]["vtep_config"])
 
52
    common.enable_uplink(data["n1kv_conf"]["uplink_profile"])
 
53
    common.enable_uplink(data["n1kv_conf"]["vtep_config"])
46
54
 
47
55
 
48
56
if __name__ == '__main__':