diff options
Diffstat (limited to 'azurelinuxagent/distro/ubuntu')
-rw-r--r-- | azurelinuxagent/distro/ubuntu/__init__.py | 19 | ||||
-rw-r--r-- | azurelinuxagent/distro/ubuntu/deprovision.py | 43 | ||||
-rw-r--r-- | azurelinuxagent/distro/ubuntu/handlerFactory.py | 29 | ||||
-rw-r--r-- | azurelinuxagent/distro/ubuntu/loader.py | 36 | ||||
-rw-r--r-- | azurelinuxagent/distro/ubuntu/osutil.py | 65 | ||||
-rw-r--r-- | azurelinuxagent/distro/ubuntu/provision.py | 72 |
6 files changed, 264 insertions, 0 deletions
diff --git a/azurelinuxagent/distro/ubuntu/__init__.py b/azurelinuxagent/distro/ubuntu/__init__.py new file mode 100644 index 0000000..4b2b9e1 --- /dev/null +++ b/azurelinuxagent/distro/ubuntu/__init__.py @@ -0,0 +1,19 @@ +# 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+ +# + diff --git a/azurelinuxagent/distro/ubuntu/deprovision.py b/azurelinuxagent/distro/ubuntu/deprovision.py new file mode 100644 index 0000000..10fa123 --- /dev/null +++ b/azurelinuxagent/distro/ubuntu/deprovision.py @@ -0,0 +1,43 @@ +# 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 azurelinuxagent.logger as logger +import azurelinuxagent.utils.fileutil as fileutil +from azurelinuxagent.distro.default.deprovision import DeprovisionHandler, DeprovisionAction + +def del_resolv(): + if os.path.realpath('/etc/resolv.conf') != '/run/resolvconf/resolv.conf': + logger.info("resolvconf is not configured. Removing /etc/resolv.conf") + fileutil.rm_files('/etc/resolv.conf') + else: + logger.info("resolvconf is enabled; leaving /etc/resolv.conf intact") + fileutil.rm_files('/etc/resolvconf/resolv.conf.d/tail', + '/etc/resolvconf/resolv.conf.d/originial') + + +class UbuntuDeprovisionHandler(DeprovisionHandler): + def setup(self, deluser): + warnings, actions = super(UbuntuDeprovisionHandler, self).setup(deluser) + warnings.append("WARNING! Nameserver configuration in " + "/etc/resolvconf/resolv.conf.d/{tail,originial} " + "will be deleted.") + actions.append(DeprovisionAction(del_resolv)) + return warnings, actions + diff --git a/azurelinuxagent/distro/ubuntu/handlerFactory.py b/azurelinuxagent/distro/ubuntu/handlerFactory.py new file mode 100644 index 0000000..c8d0906 --- /dev/null +++ b/azurelinuxagent/distro/ubuntu/handlerFactory.py @@ -0,0 +1,29 @@ +# 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+ +# + +from azurelinuxagent.distro.ubuntu.provision import UbuntuProvisionHandler +from azurelinuxagent.distro.ubuntu.deprovision import UbuntuDeprovisionHandler +from azurelinuxagent.distro.default.handlerFactory import DefaultHandlerFactory + +class UbuntuHandlerFactory(DefaultHandlerFactory): + def __init__(self): + super(UbuntuHandlerFactory, self).__init__() + self.provision_handler = UbuntuProvisionHandler() + self.deprovision_handler = UbuntuDeprovisionHandler() + diff --git a/azurelinuxagent/distro/ubuntu/loader.py b/azurelinuxagent/distro/ubuntu/loader.py new file mode 100644 index 0000000..26db4fa --- /dev/null +++ b/azurelinuxagent/distro/ubuntu/loader.py @@ -0,0 +1,36 @@ +# 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+ +# + +from azurelinuxagent.metadata import DISTRO_NAME, DISTRO_VERSION + +def get_osutil(): + from azurelinuxagent.distro.ubuntu.osutil import Ubuntu1204OSUtil, \ + UbuntuOSUtil, \ + Ubuntu14xOSUtil + if DISTRO_VERSION == "12.04": + return Ubuntu1204OSUtil() + elif DISTRO_VERSION == "14.04" or DISTRO_VERSION == "14.10": + return Ubuntu14xOSUtil() + else: + return UbuntuOSUtil() + +def get_handlers(): + from azurelinuxagent.distro.ubuntu.handlerFactory import UbuntuHandlerFactory + return UbuntuHandlerFactory() + diff --git a/azurelinuxagent/distro/ubuntu/osutil.py b/azurelinuxagent/distro/ubuntu/osutil.py new file mode 100644 index 0000000..1e51c2a --- /dev/null +++ b/azurelinuxagent/distro/ubuntu/osutil.py @@ -0,0 +1,65 @@ +# +# 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 re +import pwd +import shutil +import socket +import array +import struct +import fcntl +import time +import azurelinuxagent.logger as logger +import azurelinuxagent.utils.fileutil as fileutil +import azurelinuxagent.utils.shellutil as shellutil +import azurelinuxagent.utils.textutil as textutil +from azurelinuxagent.distro.default.osutil import DefaultOSUtil + +class Ubuntu14xOSUtil(DefaultOSUtil): + def __init__(self): + super(Ubuntu14xOSUtil, self).__init__() + + def start_network(self): + return shellutil.run("service networking start", chk_err=False) + + def stop_agent_service(self): + return shellutil.run("service walinuxagent stop", chk_err=False) + + def start_agent_service(self): + return shellutil.run("service walinuxagent start", chk_err=False) + +class Ubuntu1204OSUtil(Ubuntu14xOSUtil): + def __init__(self): + super(Ubuntu1204OSUtil, self).__init__() + + #Override + def get_dhcp_pid(self): + ret= shellutil.run_get_output("pidof dhclient3") + return ret[1] if ret[0] == 0 else None + +class UbuntuOSUtil(Ubuntu14xOSUtil): + def __init__(self): + super(UbuntuOSUtil, self).__init__() + + def register_agent_service(self): + return shellutil.run("systemctl unmask walinuxagent", chk_err=False) + + def unregister_agent_service(self): + return shellutil.run("systemctl mask walinuxagent", chk_err=False) + 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.") |