Ubuntu Pastebin

Paste from smoser at Tue, 7 Mar 2017 19:45:59 +0000

Download as text
 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
diff --git a/cloudinit/cmd/main.py b/cloudinit/cmd/main.py
index 6ff4e1c..a0db27d 100644
--- a/cloudinit/cmd/main.py
+++ b/cloudinit/cmd/main.py
@@ -330,6 +330,14 @@ def main_init(name, args):
     # Stage 5
     try:
         init.fetch(existing=existing)
+        ## Here it seems like we should centrally control updating of
+        ## the hostname.  We'd set it if this is a new instance.
+        ## Unfortunately, 'init.is_new_instance' is not usable 
+        ## until after 'instancify' has been called below.... hm...
+        ## somehow we'd want to update /etc/hostname and set the system
+        ## host name only if this is a new instance.
+        init.set_hostname()
+
         # if in network mode, and the datasource is local
         # then work was done at that stage.
         if mode == sources.DSMODE_NETWORK and init.datasource.dsmode != mode:
@@ -357,6 +365,15 @@ def main_init(name, args):
             LOG.debug("[%s] barreling on in force mode without datasource",
                       mode)
 
+    ## It seems something here should call on the datasource to say:
+    ##    "network is up now, you can collect the rest of your data"
+    ## This is because azure will have had 'get_data' called at a point
+    ## in which there is no network.  'activate' is called too late.
+    ##
+    ## init.get_remaining_data would call the datasources's
+    ##   get_remaining_data (if it has that attribute)
+    init.get_remaining_data()
+
     # Stage 6
     iid = init.instancify()
     LOG.debug("[%s] %s will now be targeting instance id: %s. new=%s",
diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py
index c5af8b8..a563740 100644
--- a/cloudinit/sources/DataSourceAzure.py
+++ b/cloudinit/sources/DataSourceAzure.py
@@ -162,6 +162,23 @@ class DataSourceAzureNet(sources.DataSource):
         metadata['public-keys'] = key_value or pubkeys_from_crt_files(fp_files)
         return metadata
 
+    def get_remaining_data(self):
+        if self.ds_cfg['agent_command'] == AGENT_START_BUILTIN:
+            metadata_func = partial(get_metadata_from_fabric,
+                                    fallback_lease_file=self.
+                                    dhclient_lease_file)
+        else:
+            metadata_func = self.get_metadata_from_agent
+
+        try:
+            fabric_data = metadata_func()
+        except Exception as exc:
+            LOG.info("Error communicating with Azure fabric; assume we aren't"
+                     " on Azure.", exc_info=True)
+            return False
+        self.metadata.update(fabric_data)
+
+
     def get_data(self):
         # azure removes/ejects the cdrom containing the ovf-env.xml
         # file on reboot.  So, in order to successfully reboot we
@@ -219,22 +236,7 @@ class DataSourceAzureNet(sources.DataSource):
         # the directory to be protected.
         write_files(ddir, files, dirmode=0o700)
 
-        if self.ds_cfg['agent_command'] == AGENT_START_BUILTIN:
-            metadata_func = partial(get_metadata_from_fabric,
-                                    fallback_lease_file=self.
-                                    dhclient_lease_file)
-        else:
-            metadata_func = self.get_metadata_from_agent
-
-        try:
-            fabric_data = metadata_func()
-        except Exception as exc:
-            LOG.info("Error communicating with Azure fabric; assume we aren't"
-                     " on Azure.", exc_info=True)
-            return False
         self.metadata['instance-id'] = util.read_dmi_data('system-uuid')
-        self.metadata.update(fabric_data)
-
         return True
 
     def device_name_to_device(self, name):
@@ -648,8 +650,10 @@ class NonAzureDataSource(Exception):
 
 
 # Used to match classes to dependencies
+# Azure does require network for configuration, but needs to run
+# before networking comes up to apply the hostname.
 datasources = [
-    (DataSourceAzureNet, (sources.DEP_FILESYSTEM, sources.DEP_NETWORK)),
+    (DataSourceAzureNet, (sources.DEP_FILESYSTEM)),
 ]
 
 
Download as text