diff options
-rw-r--r-- | cxmanage_api/__init__.py | 2 | ||||
-rw-r--r-- | cxmanage_api/firmware_package.py | 16 | ||||
-rw-r--r-- | cxmanage_api/image.py | 12 | ||||
-rw-r--r-- | cxmanage_api/ip_retriever.py | 3 | ||||
-rw-r--r-- | cxmanage_api/node.py | 10 | ||||
-rwxr-xr-x | scripts/cxmanage | 70 |
6 files changed, 61 insertions, 52 deletions
diff --git a/cxmanage_api/__init__.py b/cxmanage_api/__init__.py index 4e7c0e4..2bb8907 100644 --- a/cxmanage_api/__init__.py +++ b/cxmanage_api/__init__.py @@ -39,7 +39,7 @@ import tempfile WORK_DIR = tempfile.mkdtemp(prefix="cxmanage_api-") -atexit.register(lambda: shutil.rmtree(WORK_DIR)) +atexit.register(lambda: shutil.rmtree(WORK_DIR, ignore_errors=True)) def temp_file(): diff --git a/cxmanage_api/firmware_package.py b/cxmanage_api/firmware_package.py index 0be4f07..7145861 100644 --- a/cxmanage_api/firmware_package.py +++ b/cxmanage_api/firmware_package.py @@ -33,6 +33,7 @@ import os +import sys import tarfile import ConfigParser import pkg_resources @@ -83,13 +84,14 @@ class FirmwarePackage(object): if "package" in config.sections(): cxmanage_ver = config.get("package", "required_cxmanage_version") - try: - pkg_resources.require("cxmanage>=%s" % cxmanage_ver) - except pkg_resources.VersionConflict: - # @todo: CxmanageVersionError? - raise ValueError( - "%s requires cxmanage version %s or later." - % (filename, cxmanage_ver)) + if sys.platform != 'win32': + try: + pkg_resources.require("cxmanage>=%s" % cxmanage_ver) + except pkg_resources.VersionConflict: + # @todo: CxmanageVersionError? + raise ValueError( + "%s requires cxmanage version %s or later." + % (filename, cxmanage_ver)) if config.has_option("package", "required_socman_version"): self.required_socman_version = config.get("package", diff --git a/cxmanage_api/image.py b/cxmanage_api/image.py index a6456d4..7be88fb 100644 --- a/cxmanage_api/image.py +++ b/cxmanage_api/image.py @@ -79,7 +79,7 @@ class Image(object): raise ValueError("File %s does not exist" % filename) if (simg == None): - contents = open(filename).read() + contents = open(filename, "rb").read() self.simg = has_simg(contents) else: self.simg = simg @@ -108,7 +108,7 @@ class Image(object): filename = self.filename # Create new image if necessary if (not self.simg): - contents = open(filename).read() + contents = open(filename, "rb").read() # Figure out daddr if (self.daddr != None): daddr = self.daddr @@ -118,11 +118,11 @@ class Image(object): skip_crc32=self.skip_crc32, align=align, version=self.version) filename = temp_file() - with open(filename, "w") as file_: + with open(filename, "wb") as file_: file_.write(simg) # Make sure the simg was built correctly - if (not valid_simg(open(filename).read())): + if (not valid_simg(open(filename, "rb").read())): raise InvalidImageError("%s is not a valid SIMG" % os.path.basename(self.filename)) @@ -141,7 +141,7 @@ class Image(object): if (self.simg): return os.path.getsize(self.filename) else: - contents = open(self.filename).read() + contents = open(self.filename, "rb").read() align = (self.type in ["CDB", "BOOT_LOG"]) simg = create_simg(contents, skip_crc32=True, align=align) return len(simg) @@ -171,7 +171,7 @@ class Image(object): if (self.type in ["CDB", "BOOT_LOG"]): # Look for "CDBH" - contents = open(self.filename).read() + contents = open(self.filename, "rb").read() if (self.simg): contents = get_simg_contents(contents) if (contents[:4] != "CDBH"): diff --git a/cxmanage_api/ip_retriever.py b/cxmanage_api/ip_retriever.py index 39fbb30..d750f12 100644 --- a/cxmanage_api/ip_retriever.py +++ b/cxmanage_api/ip_retriever.py @@ -41,7 +41,8 @@ from time import sleep from cxmanage_api.cx_exceptions import IPDiscoveryError -from pexpect import TIMEOUT, EOF +if sys.platform != 'win32': + from pexpect import TIMEOUT, EOF from pyipmi import make_bmc from pyipmi.server import Server from pyipmi.bmc import LanBMC diff --git a/cxmanage_api/node.py b/cxmanage_api/node.py index f720d28..e4d3e31 100644 --- a/cxmanage_api/node.py +++ b/cxmanage_api/node.py @@ -735,14 +735,14 @@ communication. # Update running ubootenv old_ubootenv_image = self._download_image(running_part) old_ubootenv = self.ubootenv(open( - old_ubootenv_image.filename).read()) + old_ubootenv_image.filename, "rb").read()) logger.info( "Done getting old ubootenv image" ) try: - ubootenv = self.ubootenv(open(image.filename).read()) + ubootenv = self.ubootenv(open(image.filename, "rb").read()) ubootenv.set_boot_order(old_ubootenv.get_boot_order()) ubootenv.set_pxe_interface(old_ubootenv.get_pxe_interface()) @@ -751,7 +751,7 @@ communication. ) filename = temp_file() - with open(filename, "w") as file_: + with open(filename, "wb") as file_: file_.write(ubootenv.get_contents()) ubootenv_image = self.image(filename, image.type, False, @@ -959,7 +959,7 @@ communication. priority = max(int(x.priority, 16) for x in [first_part, active_part]) filename = temp_file() - with open(filename, "w") as file_: + with open(filename, "wb") as file_: file_.write(ubootenv.get_contents()) ubootenv_image = self.image(filename, image.type, False, image.daddr, @@ -1150,7 +1150,7 @@ communication. fwinfo = self.get_firmware_info() partition = self._get_partition(fwinfo, "UBOOTENV", "ACTIVE") image = self._download_image(partition) - return self.ubootenv(open(image.filename).read()) + return self.ubootenv(open(image.filename, "rb").read()) def get_fabric_ipinfo(self): """Gets what ip information THIS node knows about the Fabric. diff --git a/scripts/cxmanage b/scripts/cxmanage index 93518dd..7249fe0 100755 --- a/scripts/cxmanage +++ b/scripts/cxmanage @@ -349,47 +349,53 @@ def validate_args(args): def print_version(): """ Print the current version of cxmanage """ - version = pkg_resources.require('cxmanage')[0].version + if sys.platform == 'win32': + version = "Unknown" + with open('cxmanage_version.txt', "r") as f: + version = f.readline().strip() + else: + version = pkg_resources.require('cxmanage')[0].version print "cxmanage version %s" % version def check_versions(): """Check versions of dependencies""" # Check pyipmi version - try: - pkg_resources.require('pyipmi>=%s' % PYIPMI_VERSION) - except pkg_resources.DistributionNotFound: - print 'ERROR: cxmanage requires pyipmi version %s'\ - % PYIPMI_VERSION - print 'No existing version was found.' - sys.exit(1) - except pkg_resources.VersionConflict: - version = pkg_resources.require('pyipmi')[0].version - print 'ERROR: cxmanage requires pyipmi version %s' % PYIPMI_VERSION - print 'Current pyipmi version is %s' % version - sys.exit(1) - - - # Check ipmitool version - if 'IPMITOOL_PATH' in os.environ: - args = [os.environ['IPMITOOL_PATH'], '-V'] - else: - args = ['ipmitool', '-V'] - - try: - ipmitool_process = subprocess.Popen(args, stdout=subprocess.PIPE) - ipmitool_version = ipmitool_process.communicate()[0].split()[2] - if pkg_resources.parse_version(ipmitool_version) < \ - pkg_resources.parse_version(IPMITOOL_VERSION): + if sys.platform != 'win32': + try: + pkg_resources.require('pyipmi>=%s' % PYIPMI_VERSION) + except pkg_resources.DistributionNotFound: + print 'ERROR: cxmanage requires pyipmi version %s'\ + % PYIPMI_VERSION + print 'No existing version was found.' + sys.exit(1) + except pkg_resources.VersionConflict: + version = pkg_resources.require('pyipmi')[0].version + print 'ERROR: cxmanage requires pyipmi version %s' % PYIPMI_VERSION + print 'Current pyipmi version is %s' % version + sys.exit(1) + + + # Check ipmitool version + if 'IPMITOOL_PATH' in os.environ: + args = [os.environ['IPMITOOL_PATH'], '-V'] + else: + args = ['ipmitool', '-V'] + + try: + ipmitool_process = subprocess.Popen(args, stdout=subprocess.PIPE) + ipmitool_version = ipmitool_process.communicate()[0].split()[2] + if pkg_resources.parse_version(ipmitool_version) < \ + pkg_resources.parse_version(IPMITOOL_VERSION): + print 'ERROR: cxmanage requires IPMItool %s or later' \ + % IPMITOOL_VERSION + print 'Current IPMItool version is %s' % ipmitool_version + sys.exit(1) + except OSError: print 'ERROR: cxmanage requires IPMItool %s or later' \ % IPMITOOL_VERSION - print 'Current IPMItool version is %s' % ipmitool_version + print 'No existing version was found.' sys.exit(1) - except OSError: - print 'ERROR: cxmanage requires IPMItool %s or later' \ - % IPMITOOL_VERSION - print 'No existing version was found.' - sys.exit(1) def main(): |