summaryrefslogtreecommitdiff
path: root/azurelinuxagent/distro/ubuntu/provision.py
diff options
context:
space:
mode:
authorBen Howard <ben.howard@ubuntu.com>2015-08-14 16:40:41 -0600
committerusd-importer <ubuntu-server@lists.ubuntu.com>2015-08-15 14:33:21 +0000
commitf78b9650d0e7b008d430673a075aad95dda863be (patch)
treea6749619e78483d45a66d4bad4d6e922391541fc /azurelinuxagent/distro/ubuntu/provision.py
parent0afc048f2a6ff3638ecfa33e7ded5dc8dddf041a (diff)
downloadvyos-walinuxagent-f78b9650d0e7b008d430673a075aad95dda863be.tar.gz
vyos-walinuxagent-f78b9650d0e7b008d430673a075aad95dda863be.zip
Import patches-unapplied version 2.1.1-0ubuntu1 to ubuntu/wily-proposed
Imported using git-ubuntu import. Changelog parent: 0afc048f2a6ff3638ecfa33e7ded5dc8dddf041a New changelog entries: * New upstream release for Ubuntu. - Switch to Python3 - Applies Ubuntu specific patches
Diffstat (limited to 'azurelinuxagent/distro/ubuntu/provision.py')
-rw-r--r--azurelinuxagent/distro/ubuntu/provision.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/azurelinuxagent/distro/ubuntu/provision.py b/azurelinuxagent/distro/ubuntu/provision.py
new file mode 100644
index 0000000..7551074
--- /dev/null
+++ b/azurelinuxagent/distro/ubuntu/provision.py
@@ -0,0 +1,72 @@
+# Windows Azure Linux Agent
+#
+# Copyright 2014 Microsoft Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Requires Python 2.4+ and Openssl 1.0+
+#
+
+import os
+import time
+import azurelinuxagent.logger as logger
+from azurelinuxagent.future import text
+import azurelinuxagent.conf as conf
+import azurelinuxagent.protocol as prot
+from azurelinuxagent.exception import *
+from azurelinuxagent.utils.osutil import OSUTIL
+import azurelinuxagent.utils.shellutil as shellutil
+import azurelinuxagent.utils.fileutil as fileutil
+from azurelinuxagent.distro.default.provision import ProvisionHandler
+
+"""
+On ubuntu image, provision could be disabled.
+"""
+class UbuntuProvisionHandler(ProvisionHandler):
+ def process(self):
+ #If provision is enabled, run default provision handler
+ if conf.get_switch("Provisioning.Enabled", False):
+ super(UbuntuProvisionHandler, self).process()
+ return
+
+ logger.info("run Ubuntu provision handler")
+ provisioned = os.path.join(OSUTIL.get_lib_dir(), "provisioned")
+ if os.path.isfile(provisioned):
+ return
+
+ logger.info("Waiting cloud-init to finish provisioning.")
+ protocol = prot.FACTORY.get_default_protocol()
+ try:
+ logger.info("Wait for ssh host key to be generated.")
+ thumbprint = self.wait_for_ssh_host_key()
+ fileutil.write_file(provisioned, "")
+
+ logger.info("Finished provisioning")
+ status = prot.ProvisionStatus(status="Ready")
+ status.properties.certificateThumbprint = thumbprint
+ protocol.report_provision_status(status)
+
+ except ProvisionError as e:
+ logger.error("Provision failed: {0}", e)
+ protocol.report_provision_status(status="NotReady", subStatus=text(e))
+
+ def wait_for_ssh_host_key(self, max_retry=60):
+ kepair_type = conf.get("Provisioning.SshHostKeyPairType", "rsa")
+ path = '/etc/ssh/ssh_host_{0}_key'.format(kepair_type)
+ for retry in range(0, max_retry):
+ if os.path.isfile(path):
+ return self.get_ssh_host_key_thumbprint(kepair_type)
+ if retry < max_retry - 1:
+ logger.info("Wait for ssh host key be generated: {0}", path)
+ time.sleep(5)
+ raise ProvisionError("Ssh hsot key is not generated.")