summaryrefslogtreecommitdiff
path: root/cloudinit/sources/helpers/vmware/imc/config.py
blob: ea0873fb17737df079aee3326ddcaf7d72fedab9 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
from cloudinit.sources.helpers.vmware.imc.nic import Nic


class Config:
    DNS = 'DNS|NAMESERVER|'
    SUFFIX = 'DNS|SUFFIX|'
    PASS = 'PASSWORD|-PASS'
    TIMEZONE = 'DATETIME|TIMEZONE'
    UTC = 'DATETIME|UTC'
    HOSTNAME = 'NETWORK|HOSTNAME'
    OMAINNAME = 'NETWORK|DOMAINNAME'

    def __init__(self, configFile):
        self._configFile = configFile

    # Retrieves hostname.
    #
    # Args:
    #   None
    # Results:
    #   string: hostname
    # Throws:
    #   None
    @property
    def hostName(self):
        return self._configFile.get(Config.HOSTNAME, None)

    # Retrieves domainName.
    #
    # Args:
    #   None
    # Results:
    #   string: domainName
    # Throws:
    #   None
    @property
    def domainName(self):
        return self._configFile.get(Config.DOMAINNAME, None)

    # Retrieves timezone.
    #
    # Args:
    #   None
    # Results:
    #   string: timezone
    # Throws:
    #   None
    @property
    def timeZone(self):
        return self._configFile.get(Config.TIMEZONE, None)

    # Retrieves whether to set time to UTC or Local.
    #
    # Args:
    #   None
    # Results:
    #   boolean: True for yes/YES, True for no/NO, otherwise - None
    # Throws:
    #   None
    @property
    def utc(self):
        return self._configFile.get(Config.UTC, None)

    # Retrieves root password to be set.
    #
    # Args:
    #   None
    # Results:
    #   string: base64-encoded root password or None
    # Throws:
    #   None
    @property
    def adminPassword(self):
        return self._configFile.get(Config.PASS, None)

    # Retrieves DNS Servers.
    #
    # Args:
    #   None
    # Results:
    #   integer: count or 0
    # Throws:
    #   None
    @property
    def nameServers(self):
        res = []
        for i in range(1, self._configFile.getCnt(Config.DNS) + 1):
            key = Config.DNS + str(i)
            res.append(self._configFile[key])

        return res

    # Retrieves DNS Suffixes.
    #
    # Args:
    #   None
    # Results:
    #   integer: count or 0
    # Throws:
    #   None
    @property
    def dnsSuffixes(self):
        res = []
        for i in range(1, self._configFile.getCnt(Config.SUFFIX) + 1):
            key = Config.SUFFIX + str(i)
            res.append(self._configFile[key])

        return res

    # Retrieves NICs.
    #
    # Args:
    #   None
    # Results:
    #   integer: count
    # Throws:
    #   None
    @property
    def nics(self):
        res = []
        nics = self._configFile['NIC-CONFIG|NICS']
        for nic in nics.split(','):
            res.append(Nic(nic, self._configFile))

        return res