Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions VMBackup/main/Utils/HandlerUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,20 @@ def get_dist_info(self):
distinfo[0] = distinfo[0].strip()
return distinfo[0]+"-"+distinfo[1],platform.release()
else:
distinfo = platform.dist()
return distinfo[0]+"-"+distinfo[1],platform.release()
# platform.dist() removed in Python 3.8; parse /etc/os-release instead
try:
with open("/etc/os-release", "r") as f:
os_name, os_version = "Unknown", "Unknown"
for line in f:
k, _, v = line.strip().partition("=")
v = v.strip('"')
if k == "NAME":
os_name = v
elif k == "VERSION":
os_version = v
return os_name + "-" + os_version, platform.release()
except Exception:
return "Unknown", "Unknown"
except Exception as e:
errMsg = 'Failed to retrieve the distinfo with error: %s, stack trace: %s' % (str(e), traceback.format_exc())
self.log(errMsg)
Expand Down Expand Up @@ -715,7 +727,7 @@ def do_status_report(self, operation, status, status_code, message, taskId = Non
stat_rept.timestampUTC = date_place_holder
date_string = r'\/Date(' + str((int)(time_span)) + r')\/'
stat_rept = "[" + json.dumps(stat_rept, cls = ComplexEncoder) + "]"
stat_rept = stat_rept.replace('\\\/', '\/') # To fix the datetime format of CreationTime to be consumed by C# DateTimeOffset
stat_rept = stat_rept.replace('\\/', '/') # To fix the datetime format of CreationTime to be consumed by C# DateTimeOffset
stat_rept = stat_rept.replace(date_place_holder,date_string)

# Add Status as sub-status for Status to be written on Status-File
Expand Down
9 changes: 5 additions & 4 deletions VMBackup/main/Utils/WAAgentUtil.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ def searchWAAgentOld():
spec.loader.exec_module(waagent)
except ImportError:
# For Python 3.4 and earlier, use imp module
import imp
waagent = imp.load_source('waagent', agentPath)
except Exception:
raise Exception("Can't load waagent.")
try:
import imp
waagent = imp.load_source('waagent', agentPath)
except ImportError:
raise Exception("Can't load waagent: importlib.util and imp both unavailable.")
else:
raise Exception("Can't load new or old waagent. Agent path not found.")
except Exception as e:
Expand Down
60 changes: 59 additions & 1 deletion VMBackup/main/WaagentLib.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,48 @@
import json
import datetime
import xml.sax.saxutils
from distutils.version import LooseVersion
try:
from distutils.version import LooseVersion
except ImportError:
# distutils removed in Python 3.12; minimal shim for version comparisons
import re as _re
class LooseVersion(object):
def __init__(self, vstring):
self.vstring = str(vstring)
self._cmp_key = self._parse(self.vstring)
@staticmethod
def _parse(s):
parts = []
for tok in _re.split(r'(\d+)', s):
if tok.isdigit():
parts.append(int(tok))
elif tok:
parts.append(tok)
return parts
def __str__(self):
return self.vstring
def __repr__(self):
return 'LooseVersion(%r)' % self.vstring
def _cmp(self, other):
if not isinstance(other, LooseVersion):
other = LooseVersion(other)
a, b = self._cmp_key, other._cmp_key
for i in range(max(len(a), len(b))):
ai = a[i] if i < len(a) else 0
bi = b[i] if i < len(b) else 0
if type(ai) != type(bi):
ai, bi = str(ai), str(bi)
if ai < bi:
return -1
if ai > bi:
return 1
return 0
def __lt__(self, other): return self._cmp(other) < 0
def __le__(self, other): return self._cmp(other) <= 0
def __eq__(self, other): return self._cmp(other) == 0
def __ge__(self, other): return self._cmp(other) >= 0
def __gt__(self, other): return self._cmp(other) > 0
def __ne__(self, other): return self._cmp(other) != 0

if not hasattr(subprocess, 'check_output'):
def check_output(*popenargs, **kwargs):
Expand Down Expand Up @@ -4514,6 +4555,8 @@ def GetMyDistro(dist_class_name=''):
Distro = 'oracle'
elif ('redhat'.lower() in Distro.lower()):
Distro = 'redhat'
elif ('azurelinux' in Distro.lower()):
Distro = 'fedora'
elif ('Kali'.lower() in Distro.lower()):
Distro = 'Kali'
elif ('FreeBSD'.lower() in Distro.lower() or 'gaia'.lower() in Distro.lower() or 'panos'.lower() in Distro.lower()):
Expand Down Expand Up @@ -4555,6 +4598,21 @@ def DistInfo(fullname=0):
return distinfo
if 'Linux' in platform.system():
distinfo = ["Default"]
# On Python 3.8+ linux_distribution is removed; detect via /etc/os-release
try:
with open("/etc/os-release", "r") as f:
os_id, os_version = "", ""
for line in f:
k, _, v = line.strip().partition("=")
v = v.strip('"')
if k == "ID":
os_id = v
elif k == "VERSION_ID":
os_version = v
if os_id == "azurelinux":
return ["azurelinux", os_version]
except Exception:
pass
if "ubuntu" in platform.version().lower():
distinfo[0] = "Ubuntu"
elif 'suse' in platform.version().lower():
Expand Down
49 changes: 49 additions & 0 deletions VMBackup/main/patch/AzureLinuxPatching.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/python
#
# Copyright 2015 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.


import subprocess
from patch.AbstractPatching import AbstractPatching
from common import *


class AzureLinuxPatching(AbstractPatching):
def __init__(self,logger,distro_info):
super(AzureLinuxPatching,self).__init__(distro_info)
self.logger = logger
self.base64_path = '/usr/bin/base64'
self.bash_path = '/usr/bin/bash'
self.blkid_path = '/usr/bin/blkid'
self.cat_path = '/usr/bin/cat'
self.cryptsetup_path = '/usr/bin/cryptsetup'
self.dd_path = '/usr/bin/dd'
self.e2fsck_path = '/usr/bin/e2fsck'
self.echo_path = '/usr/bin/echo'
self.getenforce_path = '/usr/bin/getenforce'
self.setenforce_path = '/usr/bin/setenforce'
self.lsblk_path = '/usr/bin/lsblk'
self.usr_flag = 1
self.lsscsi_path = '/usr/bin/lsscsi'
self.mkdir_path = '/usr/bin/mkdir'
self.mount_path = '/usr/bin/mount'
self.openssl_path = '/usr/bin/openssl'
self.resize2fs_path = '/usr/bin/resize2fs'
self.umount_path = '/usr/bin/umount'

def install_extras(self):
common_extras = ['cryptsetup','lsscsi']
for extra in common_extras:
self.logger.log("installation for " + extra + ' result is ' + str(subprocess.call(['dnf', 'install','-y', extra])))
18 changes: 18 additions & 0 deletions VMBackup/main/patch/__init__.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from patch.DefaultPatching import DefaultPatching
from patch.FreeBSDPatching import FreeBSDPatching
from patch.NSBSDPatching import NSBSDPatching
from patch.AzureLinuxPatching import AzureLinuxPatching

# Define the function in case waagent(<2.0.4) doesn't have DistInfo()
def DistInfo():
Expand Down Expand Up @@ -60,6 +61,21 @@ def DistInfo():
return distinfo
if 'Linux' in platform.system():
distinfo = ["Default"]
# On Python 3.8+ linux_distribution is removed; detect via /etc/os-release
try:
with open("/etc/os-release", "r") as f:
os_id, os_version = "", ""
for line in f:
k, _, v = line.strip().partition("=")
v = v.strip('"')
if k == "ID":
os_id = v
elif k == "VERSION_ID":
os_version = v
if os_id == "azurelinux":
return ["azurelinux", os_version]
except Exception:
pass
if "ubuntu" in platform.version().lower():
distinfo[0] = "Ubuntu"
elif 'suse' in platform.version().lower():
Expand Down Expand Up @@ -114,6 +130,8 @@ def GetMyPatching(logger):
Distro = 'oracle'
elif ('redhat'.lower() in Distro.lower()):
Distro = 'redhat'
elif ('azurelinux' in Distro.lower()):
Distro = 'AzureLinux'
elif ("Kali".lower() in Distro.lower()):
Distro = 'Kali'
elif ('FreeBSD'.lower() in Distro.lower() or 'gaia'.lower() in Distro.lower() or 'panos'.lower() in Distro.lower()):
Expand Down