Skip to content

Commit

Permalink
Split agent changes (#1145)
Browse files Browse the repository at this point in the history
* Split agent changes

* Define iosxe distro

* Remove TAGS file

* Move get_instance_id

* Repair unintentional white space changes.

* Fix syntax errors
  • Loading branch information
richawil authored and hglkrijger committed Aug 2, 2018
1 parent 8b3e115 commit d30174d
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 9 deletions.
9 changes: 9 additions & 0 deletions azurelinuxagent/common/dhcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ def _send_dhcp_req(self, request):
return None

def send_dhcp_req(self):
"""
Check if DHCP is available
"""
(dhcp_available, endpoint) = self.osutil.is_dhcp_available()
if not dhcp_available:
logger.info("send_dhcp_req: DHCP not available")
self.endpoint = endpoint
return

"""
Build dhcp request with mac addr
Configure route to allow dhcp traffic
Expand Down
7 changes: 5 additions & 2 deletions azurelinuxagent/common/osutil/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,12 @@ def get_instance_id(self):
'''
if os.path.isfile(PRODUCT_ID_FILE):
s = fileutil.read_file(PRODUCT_ID_FILE).strip()

else:
rc, s = shellutil.run_get_output(DMIDECODE_CMD)
if rc != 0 or UUID_PATTERN.match(s) is None:
return ""

return self._correct_instance_id(s.strip())

def get_userentry(self, username):
Expand Down Expand Up @@ -1012,6 +1012,9 @@ def remove_route_for_dhcp_broadcast(self, ifname):
shellutil.run("route del 255.255.255.255 dev {0}".format(ifname),
chk_err=False)

def is_dhcp_available(self):
return (True, '')

def is_dhcp_enabled(self):
return False

Expand Down
3 changes: 3 additions & 0 deletions azurelinuxagent/common/osutil/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ def get_osutil(distro_name=DISTRO_NAME,
elif distro_name == "gaia":
return GaiaOSUtil()

if distro_name == "iosxe":
return IosxeOSUtil()

else:
logger.warn("Unable to load distro implementation for {0}. Using "
"default distro implementation instead.",
Expand Down
84 changes: 84 additions & 0 deletions azurelinuxagent/common/osutil/iosxe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Microsoft Azure Linux Agent
#
# Copyright 2018 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.6+ and Openssl 1.0+
#

import azurelinuxagent.common.logger as logger
import azurelinuxagent.common.utils.shellutil as shellutil
from azurelinuxagent.common.osutil.default import DefaultOSUtil
from azurelinuxagent.common.osutil.redhat import Redhat6xOSUtil

'''
The IOSXE distribution is a variant of the Centos distribution,
version 7.1.
The primary difference is that IOSXE makes some assumptions about
the waagent environment:
- only the waagent daemon is executed
- no provisioning is performed
- no DHCP-based services are available
'''
class IosxeOSUtil(DefaultOSUtil):
def __init__(self):
super(IosxeOSUtil, self).__init__()

def set_hostname(self, hostname):
"""
Unlike redhat 6.x, redhat 7.x will set hostname via hostnamectl
Due to a bug in systemd in Centos-7.0, if this call fails, fallback
to hostname.
"""
hostnamectl_cmd = "hostnamectl set-hostname {0} --static".format(hostname)
if shellutil.run(hostnamectl_cmd, chk_err=False) != 0:
logger.warn("[{0}] failed, attempting fallback".format(hostnamectl_cmd))
DefaultOSUtil.set_hostname(self, hostname)

def publish_hostname(self, hostname):
"""
Restart NetworkManager first before publishing hostname
"""
shellutil.run("service NetworkManager restart")
super(RedhatOSUtil, self).publish_hostname(hostname)

def register_agent_service(self):
return shellutil.run("systemctl enable waagent", chk_err=False)

def unregister_agent_service(self):
return shellutil.run("systemctl disable waagent", chk_err=False)

def openssl_to_openssh(self, input_file, output_file):
DefaultOSUtil.openssl_to_openssh(self, input_file, output_file)

def is_dhcp_available(self):
return (False, '168.63.129.16')

def get_instance_id(self):
'''
Azure records a UUID as the instance ID
First check /sys/class/dmi/id/product_uuid.
If that is missing, then extracts from dmidecode
If nothing works (for old VMs), return the empty string
'''
if os.path.isfile(PRODUCT_ID_FILE):
try:
s = fileutil.read_file(PRODUCT_ID_FILE).strip()
return self._correct_instance_id(s.strip())
except IOError:
pass
rc, s = shellutil.run_get_output(DMIDECODE_CMD)
if rc != 0 or UUID_PATTERN.match(s) is None:
return ""
return self._correct_instance_id(s.strip())
27 changes: 20 additions & 7 deletions azurelinuxagent/common/protocol/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,26 @@ def _set_wireserver_endpoint(self, endpoint):
def _detect_wire_protocol(self):
endpoint = self.dhcp_handler.endpoint
if endpoint is None:
logger.info("WireServer endpoint is not found. Rerun dhcp handler")
try:
self.dhcp_handler.run()
except DhcpError as e:
raise ProtocolError(ustr(e))
endpoint = self.dhcp_handler.endpoint

'''
Check if DHCP can be used to get the wire protocol endpoint
'''
(dhcp_available, conf_endpoint) = self.osutil.is_dhcp_available()
if dhcp_available:
logger.info("WireServer endpoint is not found. Rerun dhcp handler")
try:
self.dhcp_handler.run()
except DhcpError as e:
raise ProtocolError(ustr(e))
endpoint = self.dhcp_handler.endpoint
else:
logger.info("_detect_wire_protocol: DHCP not available")
endpoint = self._get_wireserver_endpoint()
if endpoint == None:
endpoint = conf_endpoint
logger.info("Using hardcoded WireServer endpoint {0}", endpoint)
else:
logger.info("WireServer endpoint {0} read from file", endpoint)

try:
protocol = WireProtocol(endpoint)
protocol.detect()
Expand Down
3 changes: 3 additions & 0 deletions azurelinuxagent/common/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ def get_distro():
if os.path.exists("/etc/cp-release"):
osinfo = get_checkpoint_platform()

if os.path.exists("/home/guestshell/azure"):
osinfo = ['iosxe', 'csr1000v', '', 'Cisco IOSXE Linux']

# Remove trailing whitespace and quote in distro name
osinfo[0] = osinfo[0].strip('"').strip(' ').lower()
return osinfo
Expand Down
119 changes: 119 additions & 0 deletions config/iosxe/waagent.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#
# Microsoft Azure Linux Agent Configuration
#

# Enable instance creation
Provisioning.Enabled=n

# Rely on cloud-init to provision
Provisioning.UseCloudInit=n

# Password authentication for root account will be unavailable.
Provisioning.DeleteRootPassword=y

# Generate fresh host key pair.
Provisioning.RegenerateSshHostKeyPair=n

# Supported values are "rsa", "dsa", "ecdsa", "ed25519", and "auto".
# The "auto" option is supported on OpenSSH 5.9 (2011) and later.
Provisioning.SshHostKeyPairType=rsa

# Monitor host name changes and publish changes via DHCP requests.
Provisioning.MonitorHostName=n

# Decode CustomData from Base64.
Provisioning.DecodeCustomData=n

# Execute CustomData after provisioning.
Provisioning.ExecuteCustomData=n

# Algorithm used by crypt when generating password hash.
#Provisioning.PasswordCryptId=6

# Length of random salt used when generating password hash.
#Provisioning.PasswordCryptSaltLength=10

# Allow reset password of sys user
Provisioning.AllowResetSysUser=n

# Format if unformatted. If 'n', resource disk will not be mounted.
ResourceDisk.Format=n

# File system on the resource disk
# Typically ext3 or ext4. FreeBSD images should use 'ufs2' here.
ResourceDisk.Filesystem=ext4

# Mount point for the resource disk
ResourceDisk.MountPoint=/mnt/resource

# Create and use swapfile on resource disk.
ResourceDisk.EnableSwap=n

# Size of the swapfile.
ResourceDisk.SwapSizeMB=0

# Comma-seperated list of mount options. See man(8) for valid options.
ResourceDisk.MountOptions=None

# Enable verbose logging (y|n)
Logs.Verbose=n

# Is FIPS enabled
OS.EnableFIPS=n

# Root device timeout in seconds.
OS.RootDeviceScsiTimeout=300

# If "None", the system default version is used.
OS.OpensslPath=None

# Set the SSH ClientAliveInterval
# OS.SshClientAliveInterval=180

# Set the path to SSH keys and configuration files
OS.SshDir=/etc/ssh

# If set, agent will use proxy server to access internet
#HttpProxy.Host=None
#HttpProxy.Port=None

# Detect Scvmm environment, default is n
# DetectScvmmEnv=n

#
# Lib.Dir=/var/lib/waagent

#
# DVD.MountPoint=/mnt/cdrom/secure

#
# Pid.File=/var/run/waagent.pid

#
# Extension.LogDir=/var/log/azure

#
# Home.Dir=/home

# Enable RDMA management and set up, should only be used in HPC images
# OS.EnableRDMA=y

# Enable or disable goal state processing auto-update, default is enabled
AutoUpdate.Enabled=y

# Determine the update family, this should not be changed
# AutoUpdate.GAFamily=Prod

# Determine if the overprovisioning feature is enabled. If yes, hold extension
# handling until inVMArtifactsProfile.OnHold is false.
# Default is enabled
# EnableOverProvisioning=y

# Allow fallback to HTTP if HTTPS is unavailable
# Note: Allowing HTTP (vs. HTTPS) may cause security risks
# OS.AllowHTTP=n

# Add firewall rules to protect access to Azure host node services
# Note:
# - The default is false to protect the state of existing VMs
OS.EnableFirewall=y
9 changes: 9 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ def get_data_files(name, version, fullname):
set_conf_files(data_files, src=["config/debian/waagent.conf"])
set_logrotate_files(data_files)
set_udev_files(data_files, dest="/lib/udev/rules.d")
elif name == 'iosxe':
set_bin_files(data_files)
set_conf_files(data_files, src=["config/iosxe/waagent.conf"])
set_logrotate_files(data_files)
set_udev_files(data_files)
set_systemd_files(data_files, dest="/usr/lib/systemd/system")
if version.startswith("7.1"):
# TODO this is a mitigation to systemctl bug on 7.1
set_sysv_files(data_files)
else:
# Use default setting
set_bin_files(data_files)
Expand Down

0 comments on commit d30174d

Please sign in to comment.