~ubuntu-branches/ubuntu/saucy/cloud-init/saucy

« back to all changes in this revision

Viewing changes to cloudinit/sources/__init__.py

  • Committer: Scott Moser
  • Date: 2013-09-11 21:04:19 UTC
  • mfrom: (1.4.5)
  • Revision ID: smoser@ubuntu.com-20130911210419-3vt5ze6ph3hu8dz1
* New upstream snapshot.
  * Add OpenNebula datasource.
  * Support reading 'random_seed' from metadata and writing to /dev/urandom
  * fix for bug in log_time.

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
        self.userdata = None
54
54
        self.metadata = None
55
55
        self.userdata_raw = None
 
56
 
 
57
        # find the datasource config name.
 
58
        # remove 'DataSource' from classname on front, and remove 'Net' on end.
 
59
        # Both Foo and FooNet sources expect config in cfg['sources']['Foo']
56
60
        name = type_utils.obj_name(self)
57
61
        if name.startswith(DS_PREFIX):
58
62
            name = name[len(DS_PREFIX):]
 
63
        if name.endswith('Net'):
 
64
            name = name[0:-3]
 
65
 
59
66
        self.ds_cfg = util.get_cfg_by_path(self.sys_cfg,
60
67
                                          ("datasource", name), {})
61
68
        if not ud_proc:
144
151
            return "iid-datasource"
145
152
        return str(self.metadata['instance-id'])
146
153
 
147
 
    def get_hostname(self, fqdn=False):
 
154
    def get_hostname(self, fqdn=False, resolve_ip=False):
148
155
        defdomain = "localdomain"
149
156
        defhost = "localhost"
150
157
        domain = defdomain
168
175
            # make up a hostname (LP: #475354) in format ip-xx.xx.xx.xx
169
176
            lhost = self.metadata['local-hostname']
170
177
            if util.is_ipv4(lhost):
171
 
                toks = ["ip-%s" % lhost.replace(".", "-")]
 
178
                toks = []
 
179
                if resolve_ip:
 
180
                    toks = util.gethostbyaddr(lhost)
 
181
 
 
182
                if toks:
 
183
                    toks = str(toks).split('.')
 
184
                else:
 
185
                    toks = ["ip-%s" % lhost.replace(".", "-")]
172
186
            else:
173
187
                toks = lhost.split(".")
174
188