~cloud-init-dev/cloud-init/trunk

« back to all changes in this revision

Viewing changes to cloudinit/sources/helpers/vmware/imc/config.py

  • Committer: Scott Moser
  • Date: 2016-08-10 15:06:15 UTC
  • Revision ID: smoser@ubuntu.com-20160810150615-ma2fv107w3suy1ma
README: Mention move of revision control to git.

cloud-init development has moved its revision control to git.
It is available at 
  https://code.launchpad.net/cloud-init

Clone with 
  git clone https://git.launchpad.net/cloud-init
or
  git clone git+ssh://git.launchpad.net/cloud-init

For more information see
  https://git.launchpad.net/cloud-init/tree/HACKING.rst

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# vi: ts=4 expandtab
2
 
#
3
 
#    Copyright (C) 2015 Canonical Ltd.
4
 
#    Copyright (C) 2015 VMware Inc.
5
 
#
6
 
#    Author: Sankar Tanguturi <stanguturi@vmware.com>
7
 
#
8
 
#    This program is free software: you can redistribute it and/or modify
9
 
#    it under the terms of the GNU General Public License version 3, as
10
 
#    published by the Free Software Foundation.
11
 
#
12
 
#    This program is distributed in the hope that it will be useful,
13
 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
#    GNU General Public License for more details.
16
 
#
17
 
#    You should have received a copy of the GNU General Public License
18
 
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 
 
20
 
from .nic import Nic
21
 
 
22
 
 
23
 
class Config(object):
24
 
    """
25
 
    Stores the Contents specified in the Customization
26
 
    Specification file.
27
 
    """
28
 
 
29
 
    DNS = 'DNS|NAMESERVER|'
30
 
    SUFFIX = 'DNS|SUFFIX|'
31
 
    PASS = 'PASSWORD|-PASS'
32
 
    TIMEZONE = 'DATETIME|TIMEZONE'
33
 
    UTC = 'DATETIME|UTC'
34
 
    HOSTNAME = 'NETWORK|HOSTNAME'
35
 
    DOMAINNAME = 'NETWORK|DOMAINNAME'
36
 
 
37
 
    def __init__(self, configFile):
38
 
        self._configFile = configFile
39
 
 
40
 
    @property
41
 
    def host_name(self):
42
 
        """Return the hostname."""
43
 
        return self._configFile.get(Config.HOSTNAME, None)
44
 
 
45
 
    @property
46
 
    def domain_name(self):
47
 
        """Return the domain name."""
48
 
        return self._configFile.get(Config.DOMAINNAME, None)
49
 
 
50
 
    @property
51
 
    def timezone(self):
52
 
        """Return the timezone."""
53
 
        return self._configFile.get(Config.TIMEZONE, None)
54
 
 
55
 
    @property
56
 
    def utc(self):
57
 
        """Retrieves whether to set time to UTC or Local."""
58
 
        return self._configFile.get(Config.UTC, None)
59
 
 
60
 
    @property
61
 
    def admin_password(self):
62
 
        """Return the root password to be set."""
63
 
        return self._configFile.get(Config.PASS, None)
64
 
 
65
 
    @property
66
 
    def name_servers(self):
67
 
        """Return the list of DNS servers."""
68
 
        res = []
69
 
        cnt = self._configFile.get_count_with_prefix(Config.DNS)
70
 
        for i in range(1, cnt + 1):
71
 
            key = Config.DNS + str(i)
72
 
            res.append(self._configFile[key])
73
 
 
74
 
        return res
75
 
 
76
 
    @property
77
 
    def dns_suffixes(self):
78
 
        """Return the list of DNS Suffixes."""
79
 
        res = []
80
 
        cnt = self._configFile.get_count_with_prefix(Config.SUFFIX)
81
 
        for i in range(1, cnt + 1):
82
 
            key = Config.SUFFIX + str(i)
83
 
            res.append(self._configFile[key])
84
 
 
85
 
        return res
86
 
 
87
 
    @property
88
 
    def nics(self):
89
 
        """Return the list of associated NICs."""
90
 
        res = []
91
 
        nics = self._configFile['NIC-CONFIG|NICS']
92
 
        for nic in nics.split(','):
93
 
            res.append(Nic(nic, self._configFile))
94
 
 
95
 
        return res