Exemple #1
0
def macaddrs_command(args):
    """get mac addresses from a cluster or host"""
    args.all_nodes = False

    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print "Getting MAC addresses..."
    results, errors = run_command(args, nodes, "get_fabric_macaddrs")

    for node in nodes:
        if node in results:
            print "MAC addresses from %s" % node.ip_address
            for node_id in sorted(results[node]):
                for port in results[node][node_id]:
                    for mac_address in results[node][node_id][port]:
                        print "Node %s, Port %i: %s" % (node_id, port,
                                mac_address)
            print

    if not args.quiet and errors:
        print "Some errors occured during the command.\n"

    return len(errors) == 0
Exemple #2
0
def macaddrs_command(args):
    """get mac addresses from a cluster or host"""
    args.all_nodes = False

    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print "Getting MAC addresses..."
    results, errors = run_command(args, nodes, "get_fabric_macaddrs")

    for node in nodes:
        if node in results:
            print "MAC addresses from %s" % node.ip_address
            for node_id in sorted(results[node]):
                for port in results[node][node_id]:
                    for mac_address in results[node][node_id][port]:
                        print "Node %s, Port %i: %s" % (node_id, port,
                                                        mac_address)
            print

    if not args.quiet and errors:
        print "Some errors occured during the command.\n"

    return len(errors) == 0
Exemple #3
0
def ipmitool_command(args):
    """run arbitrary ipmitool command"""
    if args.lanplus:
        ipmitool_args = ['-I', 'lanplus'] + args.ipmitool_args
    else:
        ipmitool_args = args.ipmitool_args

    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print "Running IPMItool command..."
    results, errors = run_command(args, nodes, "ipmitool_command",
                                  ipmitool_args)

    # Print results
    node_strings = get_node_strings(args, results, justify=False)
    for node in nodes:
        if node in results and results[node] != "":
            print "[ IPMItool output from %s ]" % node_strings[node]
            print results[node]
            print

    if not args.quiet and errors:
        print "Some errors occured during the command.\n"

    return len(errors) > 0
Exemple #4
0
def ipmitool_command(args):
    """run arbitrary ipmitool command"""
    if args.lanplus:
        ipmitool_args = ['-I', 'lanplus'] + args.ipmitool_args
    else:
        ipmitool_args = args.ipmitool_args

    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print "Running IPMItool command..."
    results, errors = run_command(args, nodes, "ipmitool_command",
            ipmitool_args)

    # Print results
    node_strings = get_node_strings(args, results, justify=False)
    for node in nodes:
        if node in results and results[node] != "":
            print "[ IPMItool output from %s ]" % node_strings[node]
            print results[node]
            print

    if not args.quiet and errors:
        print "Some errors occured during the command.\n"

    return len(errors) > 0
Exemple #5
0
def fwinfo_command(args):
    """print firmware info"""
    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print "Getting firmware info..."

    results, errors = run_command(args, nodes, "get_firmware_info")

    node_strings = get_node_strings(args, results, justify=False)
    for node in nodes:
        if node in results:
            print "[ Firmware info for %s ]" % node_strings[node]

            for partition in results[node]:
                print "Partition : %s" % partition.partition
                print "Type      : %s" % partition.type
                print "Offset    : %s" % partition.offset
                print "Size      : %s" % partition.size
                print "Priority  : %s" % partition.priority
                print "Daddr     : %s" % partition.daddr
                print "Flags     : %s" % partition.flags
                print "Version   : %s" % partition.version
                print "In Use    : %s" % partition.in_use
                print

    if not args.quiet and errors:
        print "Some errors occured during the command.\n"

    return len(errors) > 0
Exemple #6
0
def info_basic_command(args):
    """Print basic info"""

    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print "Getting info..."
    results, errors = run_command(args, nodes, "get_versions")

    # Print results
    node_strings = get_node_strings(args, results, justify=False)
    for node in nodes:
        if node in results:
            result = results[node]
            # Get mappings between attributes and formatted strings
            components = COMPONENTS

            print "[ Info from %s ]" % node_strings[node]
            print "Hardware version    : %s" % result.hardware_version
            print "Firmware version    : %s" % result.firmware_version
            # var is the variable, string is the printable string of var
            for var, string in components:
                if hasattr(result, var):
                    version = getattr(result, var)
                    print "%s: %s" % (string.ljust(20), version)
            print

    if not args.quiet and errors:
        print "Some errors occured during the command.\n"

    return len(errors) > 0
Exemple #7
0
def fwinfo_command(args):
    """print firmware info"""
    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print "Getting firmware info..."

    results, errors = run_command(args, nodes, "get_firmware_info")

    node_strings = get_node_strings(args, results, justify=False)
    for node in nodes:
        if node in results:
            print "[ Firmware info for %s ]" % node_strings[node]

            for partition in results[node]:
                print "Partition : %s" % partition.partition
                print "Type      : %s" % partition.type
                print "Offset    : %s" % partition.offset
                print "Size      : %s" % partition.size
                print "Priority  : %s" % partition.priority
                print "Daddr     : %s" % partition.daddr
                print "Flags     : %s" % partition.flags
                print "Version   : %s" % partition.version
                print "In Use    : %s" % partition.in_use
                print

    if not args.quiet and errors:
        print "Some errors occured during the command.\n"

    return len(errors) > 0
Exemple #8
0
def info_basic_command(args):
    """Print basic info"""

    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print "Getting info..."
    results, errors = run_command(args, nodes, "get_versions")

    # Print results
    node_strings = get_node_strings(args, results, justify=False)
    for node in nodes:
        if node in results:
            result = results[node]
            # Get mappings between attributes and formatted strings
            components = COMPONENTS

            print "[ Info from %s ]" % node_strings[node]
            print "Hardware version    : %s" % result.hardware_version
            print "Firmware version    : %s" % result.firmware_version
            # var is the variable, string is the printable string of var
            for var, string in components:
                if hasattr(result, var):
                    version = getattr(result, var)
                    print "%s: %s" % (string.ljust(20), version)
            print

    if not args.quiet and errors:
        print "Some errors occured during the command.\n"

    return len(errors) > 0
Exemple #9
0
def sensor_command(args):
    """read sensor values from a cluster or host"""
    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print "Getting sensor readings..."
    results, errors = run_command(args, nodes, "get_sensors",
            args.sensor_name)

    sensors = {}
    for node in nodes:
        if node in results:
            for sensor_name, sensor in results[node].iteritems():
                if not sensor_name in sensors:
                    sensors[sensor_name] = []

                reading = sensor.sensor_reading.replace("(+/- 0) ", "")
                try:
                    value = float(reading.split()[0])
                    suffix = reading.lstrip("%f " % value)
                    sensors[sensor_name].append((node, value, suffix))
                except ValueError:
                    sensors[sensor_name].append((node, reading, ""))

    node_strings = get_node_strings(args, results, justify=True)
    if node_strings:
        jsize = len(node_strings.itervalues().next())
    for sensor_name, readings in sensors.iteritems():
        print sensor_name

        for node, reading, suffix in readings:
            try:
                print "%s: %.2f %s" % (node_strings[node], reading, suffix)
            except TypeError:
                print "%s: %s" % (node_strings[node], reading)

        try:
            if all(suffix == x[2] for x in readings):
                minimum = min(x[1] for x in readings)
                maximum = max(x[1] for x in readings)
                average = sum(x[1] for x in readings) / len(readings)
                print "%s: %.2f %s" % ("Minimum".ljust(jsize), minimum, suffix)
                print "%s: %.2f %s" % ("Maximum".ljust(jsize), maximum, suffix)
                print "%s: %.2f %s" % ("Average".ljust(jsize), average, suffix)
        except TypeError:
            pass

        print

    if not args.quiet and errors:
        print "Some errors occured during the command.\n"

    return len(errors) > 0
Exemple #10
0
def sensor_command(args):
    """read sensor values from a cluster or host"""
    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print "Getting sensor readings..."
    results, errors = run_command(args, nodes, "get_sensors", args.sensor_name)

    sensors = {}
    for node in nodes:
        if node in results:
            for sensor_name, sensor in results[node].iteritems():
                if not sensor_name in sensors:
                    sensors[sensor_name] = []

                reading = sensor.sensor_reading.replace("(+/- 0) ", "")
                try:
                    value = float(reading.split()[0])
                    suffix = reading.lstrip("%f " % value)
                    sensors[sensor_name].append((node, value, suffix))
                except ValueError:
                    sensors[sensor_name].append((node, reading, ""))

    node_strings = get_node_strings(args, results, justify=True)
    if node_strings:
        jsize = len(node_strings.itervalues().next())
    for sensor_name, readings in sensors.iteritems():
        print sensor_name

        for node, reading, suffix in readings:
            try:
                print "%s: %.2f %s" % (node_strings[node], reading, suffix)
            except TypeError:
                print "%s: %s" % (node_strings[node], reading)

        try:
            if all(suffix == x[2] for x in readings):
                minimum = min(x[1] for x in readings)
                maximum = max(x[1] for x in readings)
                average = sum(x[1] for x in readings) / len(readings)
                print "%s: %.2f %s" % ("Minimum".ljust(jsize), minimum, suffix)
                print "%s: %.2f %s" % ("Maximum".ljust(jsize), maximum, suffix)
                print "%s: %.2f %s" % ("Average".ljust(jsize), average, suffix)
        except TypeError:
            pass

        print

    if not args.quiet and errors:
        print "Some errors occured during the command.\n"

    return len(errors) > 0
Exemple #11
0
def mcreset_command(args):
    """reset the management controllers of a cluster or host"""
    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print 'Sending MC reset command...'

    _, errors = run_command(args, nodes, 'mc_reset')

    if not args.quiet and not errors:
        print 'Command completed successfully.\n'

    return len(errors) > 0
Exemple #12
0
def power_command(args):
    """change the power state of a cluster or host"""
    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print 'Sending power %s command...' % args.power_mode

    _, errors = run_command(args, nodes, 'set_power', args.power_mode)

    if not args.quiet and not errors:
        print 'Command completed successfully.\n'

    return len(errors) > 0
Exemple #13
0
def power_policy_command(args):
    """Executes power policy command with args."""
    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print 'Setting power policy to %s...' % args.policy

    _, errors = run_command(args, nodes, 'set_power_policy', args.policy)

    if not args.quiet and not errors:
        print 'Command completed successfully.\n'

    return len(errors) > 0
Exemple #14
0
def mcreset_command(args):
    """reset the management controllers of a cluster or host"""
    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print 'Sending MC reset command...'

    _, errors = run_command(args, nodes, 'mc_reset')

    if not args.quiet and not errors:
        print 'Command completed successfully.\n'

    return len(errors) > 0
Exemple #15
0
def config_reset_command(args):
    """reset to factory default settings"""
    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp, verify_prompt=True)

    if not args.quiet:
        print "Sending config reset command..."

    _, errors = run_command(args, nodes, "config_reset")

    if not args.quiet and not errors:
        print "Command completed successfully.\n"

    return len(errors) > 0
Exemple #16
0
def power_command(args):
    """change the power state of a cluster or host"""
    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print 'Sending power %s command...' % args.power_mode

    _, errors = run_command(args, nodes, 'set_power', args.power_mode)

    if not args.quiet and not errors:
        print 'Command completed successfully.\n'

    return len(errors) > 0
Exemple #17
0
def power_policy_command(args):
    """Executes power policy command with args."""
    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print 'Setting power policy to %s...' % args.policy

    _, errors = run_command(args, nodes, 'set_power_policy',
            args.policy)

    if not args.quiet and not errors:
        print 'Command completed successfully.\n'

    return len(errors) > 0
Exemple #18
0
def config_boot_command(args):
    """set A9 boot order"""
    if args.boot_order == ['status']:
        return config_boot_status_command(args)

    validate_boot_args(args.boot_order)

    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print "Setting boot order..."

    _, errors = run_command(args, nodes, "set_boot_order",
            args.boot_order)

    if not args.quiet and not errors:
        print "Command completed successfully.\n"

    return len(errors) > 0
Exemple #19
0
def config_pxe_command(args):
    """set the PXE boot interface"""
    if args.interface == "status":
        return config_pxe_status_command(args)

    validate_pxe_interface(args.interface)

    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print "Setting pxe interface..."

    _, errors = run_command(args, nodes, "set_pxe_interface",
            args.interface)

    if not args.quiet and not errors:
        print "Command completed successfully.\n"

    return len(errors) > 0
Exemple #20
0
def ipinfo_command(args):
    """get ip info from a cluster or host"""
    args.all_nodes = False

    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print "Getting IP addresses..."

    results, _ = run_command(args, nodes, "get_fabric_ipinfo")

    for node in nodes:
        if node in results:
            print 'IP info from %s' % node.ip_address
            for node_id, node_address in sorted(results[node].items()):
                print 'Node %s: %s' % (node_id, node_address)
            print

    return 0
Exemple #21
0
def ipinfo_command(args):
    """get ip info from a cluster or host"""
    args.all_nodes = False

    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print "Getting IP addresses..."

    results, _ = run_command(args, nodes, "get_fabric_ipinfo")

    for node in nodes:
        if node in results:
            print 'IP info from %s' % node.ip_address
            for node_id, node_address in sorted(results[node].items()):
                print 'Node %s: %s' % (node_id, node_address)
            print

    return 0
Exemple #22
0
def config_boot_status_command(args):
    """Get boot status command."""
    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print "Getting boot order..."
    results, errors = run_command(args, nodes, "get_boot_order")

    # Print results
    if results:
        node_strings = get_node_strings(args, results, justify=True)
        print "Boot order"
        for node in nodes:
            if node in results:
                print "%s: %s" % (node_strings[node], ",".join(results[node]))
        print

    if not args.quiet and errors:
        print "Some errors occured during the command.\n"

    return len(errors) > 0
Exemple #23
0
def config_pxe_status_command(args):
    """Gets pxe status."""
    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print "Getting pxe interface..."
    results, errors = run_command(args, nodes, "get_pxe_interface")

    # Print results
    if results:
        node_strings = get_node_strings(args, results, justify=True)
        print "PXE interface"
        for node in nodes:
            if node in results:
                print "%s: %s" % (node_strings[node], results[node])
        print

    if not args.quiet and errors:
        print "Some errors occured during the command.\n"

    return len(errors) > 0
Exemple #24
0
def partition_config_command(args):
    """get partition config from nodes"""
    args.all_nodes = False

    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print "Getting partition config..."
    results, errors = run_command(args, nodes, "run_fabric_tftp_command",
                                  "fabric_info_partition_config")

    for node in nodes:
        if node in results:
            print "[ Partition config from %s ]" % node.ip_address
            print results[node].strip()
            print

    if not args.quiet and errors:
        print "Some errors occured during the command.\n"

    return len(errors) == 0
Exemple #25
0
def ipdiscover_command(args):
    """discover server IP addresses"""
    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print "Getting server-side IP addresses..."

    results, errors = run_command(args, nodes, "get_server_ip", args.interface, args.ipv6, args.aggressive)

    if results:
        node_strings = get_node_strings(args, results, justify=True)
        print "IP addresses (ECME, Server)"
        for node in nodes:
            if node in results:
                print "%s: %s" % (node_strings[node], results[node])
        print

    if not args.quiet and errors:
        print "Some errors occurred during the command."

    return len(errors) > 0
Exemple #26
0
def power_policy_status_command(args):
    """Executes the power policy status command with args."""
    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print 'Getting power policy status...'
    results, errors = run_command(args, nodes, 'get_power_policy')

    # Print results
    if results:
        node_strings = get_node_strings(args, results, justify=True)
        print 'Power policy status'
        for node in nodes:
            if node in results:
                print '%s: %s' % (node_strings[node], results[node])
        print

    if not args.quiet and errors:
        print 'Some errors occured during the command.\n'

    return len(errors) > 0
Exemple #27
0
def power_policy_status_command(args):
    """Executes the power policy status command with args."""
    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print 'Getting power policy status...'
    results, errors = run_command(args, nodes, 'get_power_policy')

    # Print results
    if results:
        node_strings = get_node_strings(args, results, justify=True)
        print 'Power policy status'
        for node in nodes:
            if node in results:
                print '%s: %s' % (node_strings[node], results[node])
        print

    if not args.quiet and errors:
        print 'Some errors occured during the command.\n'

    return len(errors) > 0
Exemple #28
0
def info_ubootenv_command(args):
    """Print uboot info"""
    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print "Getting u-boot environment..."
    results, errors = run_command(args, nodes, "get_ubootenv")

    # Print results
    node_strings = get_node_strings(args, results, justify=False)
    for node in nodes:
        if node in results:
            ubootenv = results[node]
            print "[ U-Boot Environment from %s ]" % node_strings[node]
            for variable in ubootenv.variables:
                print "%s=%s" % (variable, ubootenv.variables[variable])
            print

    if not args.quiet and errors:
        print "Some errors occured during the command.\n"

    return len(errors) > 0
Exemple #29
0
def partition_config_command(args):
    """get partition config from nodes"""
    args.all_nodes = False

    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print "Getting partition config..."
    results, errors = run_command(
        args, nodes, "run_fabric_tftp_command", "fabric_info_partition_config"
    )

    for node in nodes:
        if node in results:
            print "[ Partition config from %s ]" % node.ip_address
            print results[node].strip()
            print

    if not args.quiet and errors:
        print "Some errors occured during the command.\n"

    return len(errors) == 0
Exemple #30
0
def info_ubootenv_command(args):
    """Print uboot info"""
    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print "Getting u-boot environment..."
    results, errors = run_command(args, nodes, "get_ubootenv")

    # Print results
    node_strings = get_node_strings(args, results, justify=False)
    for node in nodes:
        if node in results:
            ubootenv = results[node]
            print "[ U-Boot Environment from %s ]" % node_strings[node]
            for variable in ubootenv.variables:
                print "%s=%s" % (variable, ubootenv.variables[variable])
            print

    if not args.quiet and errors:
        print "Some errors occured during the command.\n"

    return len(errors) > 0
Exemple #31
0
def ipdiscover_command(args):
    """discover server IP addresses"""
    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    if not args.quiet:
        print 'Getting server-side IP addresses...'

    results, errors = run_command(args, nodes, 'get_server_ip', args.interface,
                                  args.ipv6, args.aggressive)

    if results:
        node_strings = get_node_strings(args, results, justify=True)
        print 'IP addresses (ECME, Server)'
        for node in nodes:
            if node in results:
                print '%s: %s' % (node_strings[node], results[node])
        print

    if not args.quiet and errors:
        print 'Some errors occurred during the command.'

    return len(errors) > 0
Exemple #32
0
def fwupdate_command(args):
    """update firmware on a cluster or host"""
    def do_update():
        """ Do a single firmware check+update. Returns True on failure. """
        if not args.force:
            if not args.quiet:
                print "Checking hosts..."

            _, errors = run_command(args, nodes, "_check_firmware",
                    package, args.partition, args.priority)
            if errors:
                print "ERROR: Firmware update aborted."
                return True

        if not args.quiet:
            print "Updating firmware..."

        _, errors = run_command(args, nodes, "update_firmware", package,
            args.partition, args.priority)
        if errors:
            print "ERROR: Firmware update failed."
            return True

        return False

    def do_reset():
        """ Reset and wait. Returns True on failure. """
        if not args.quiet:
            print "Checking ECME versions..."

        results, errors = run_command(args, nodes, "get_versions")
        if errors:
            print "ERROR: MC reset aborted. Backup partitions not updated."
            return True

        for result in results.values():
            version = result.ecme_version.lstrip("v")
            if parse_version(version) < parse_version("1.2.0"):
                print "ERROR: MC reset is unsafe on ECME version v%s" % version
                print "Please power cycle the system and start a new fwupdate."
                return True

        if not args.quiet:
            print "Resetting nodes..."

        results, errors = run_command(args, nodes, "mc_reset", True)
        if errors:
            print "ERROR: MC reset failed. Backup partitions not updated."
            return True

        return False

    if args.image_type == "PACKAGE":
        package = FirmwarePackage(args.filename)
    else:
        try:
            simg = None
            if args.force_simg:
                simg = False
            elif args.skip_simg:
                simg = True

            image = Image(args.filename, args.image_type, simg, args.daddr,
                    args.skip_crc32, args.fw_version)
            package = FirmwarePackage()
            package.images.append(image)
        except ValueError as err:
            print "ERROR: %s" % err
            return True

    if not args.all_nodes:
        if args.force:
            print(
                'WARNING: Updating firmware without --all-nodes' +
                ' is dangerous.'
            )
        else:
            if not prompt_yes(
                'WARNING: Updating firmware without ' +
                '--all-nodes is dangerous. Continue?'
                ):
                return 1

    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp, verify_prompt=True)

    errors = do_update()

    if args.full and not errors:
        errors = do_reset()
        if not errors:
            errors = do_update()

    if not args.quiet and not errors:
        print "Command completed successfully.\n"

    return errors
Exemple #33
0
def tspackage_command(args):
    """Get information pertaining to each node.
    This includes:
    Version info (like cxmanage info)
    MAC addresses
    Sensor readings
    Sensor data records
    Firmware info
    Boot order
    SELs (System Event Logs),
    Depth charts
    Routing Tables

    This data will be written to a set of files. Each node will get its own
    file. All of these files will be archived and saved to the user's current
    directory.

    Internally, this command is called from:
    ~/virtual_testenv/workspace/cx_manage_util/scripts/cxmanage

    """
    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    # Make a temporary directory to store the node information files
    original_dir = os.getcwd()
    temp_dir = tempfile.mkdtemp()
    os.chdir(temp_dir)
    tspackage_dir = "tspackage.%s" % time.strftime("%Y%m%d%H%M%S")
    os.mkdir(tspackage_dir)
    os.chdir(tspackage_dir)

    quiet = args.quiet

    write_client_info()

    if not quiet:
        print("Getting version information...")
    write_version_info(args, nodes)

    if not quit:
        print("Getting LAN information...")
    write_lan_info(args, nodes)

    if not quiet:
        print("Getting boot order...")
    write_boot_order(args, nodes)

    if not quiet:
        print("Getting MAC addresses...")
    write_mac_addrs(args, nodes)

    if not quiet:
        print("Getting sensor information...")
    write_sensor_info(args, nodes)

    if not quiet:
        print("Getting firmware information...")
    write_fwinfo(args, nodes)

    if not quiet:
        print("Getting system event logs...")
    write_sel(args, nodes)

    if not quiet:
        print("Getting depth charts...")
    write_depth_chart(args, nodes)

    if not quiet:
        print("Getting routing tables...")
    write_routing_table(args, nodes)

    if not quiet:
        print("Getting serial log...")
    write_serial_log(args, nodes)

    if not quiet:
        print("Getting crash log...")
    write_crash_log(args, nodes)

    # Archive the files
    archive(os.getcwd(), original_dir)

    # The original files are already archived, so we can delete them.
    shutil.rmtree(temp_dir)
Exemple #34
0
def eepromupdate_command(args):
    """Updates the EEPROM's on a cluster or host"""
    def validate_config():
        """Makes sure the system type is applicable to EEPROM updates"""
        for node in  nodes:
            if('Dual Node' not in node.get_versions().hardware_version):
                print 'ERROR: eepromupdate is only valid on TerraNova systems'
                return True

        return False

    def validate_images():
        """Makes sure all the necessary images have been provided"""
        if(args.eeprom_location == 'node'):
            for node in nodes:
                node_hw_ver = node.get_versions().hardware_version
                if('Uplink' in node_hw_ver):
                    image = 'dual_uplink_node_%s' % (node.node_id % 4)
                else:
                    image = 'dual_node_%s' % (node.node_id % 4)
                if(not [img for img in args.images if image in img]):
                    print 'ERROR: no valid image for node %s' % node.node_id
                    return True

        else:
            image = args.images[0]
            if('tn_storage.single_slot' not in image):
                print 'ERROR: %s is an invalid image for slot EEPROM' % image
                return True

        return False

    def do_update():
        """Updates the EEPROM images"""
        if(args.eeprom_location == 'node'):
            for node in nodes:
                node_hw_ver = node.get_versions().hardware_version
                if('Uplink' in node_hw_ver):
                    needed_image = 'dual_uplink_node_%s' % (node.node_id % 4)
                else:
                    needed_image = 'dual_node_%s' % (node.node_id % 4)
                image = [img for img in args.images if needed_image in img][0]
                print 'Updating node EEPROM on node %s' % node.node_id
                if(args.verbose):
                    print '    %s' % image
                try:
                    node.update_node_eeprom(image)
                except Exception as err:
                    print 'ERROR: %s' % str(err)
                    return True

            print ''  # for readability
        else:
            image = args.images[0]
            # First node in every slot gets the slot image
            slot_nodes = [node for node in nodes if node.node_id % 4 == 0]
            _, errors = run_command(
                args, slot_nodes, "update_slot_eeprom", image
            )
            if(errors):
                print 'ERROR: EEPROM update failed'
                return True

        return False

    if not args.all_nodes:
        if args.force:
            print(
                'WARNING: Updating EEPROM without --all-nodes' +
                ' is dangerous.'
            )
        else:
            if not prompt_yes(
                'WARNING: Updating EEPROM without ' +
                '--all-nodes is dangerous. Continue?'
                ):
                return 1

    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp, verify_prompt=True)

    errors = validate_config()

    if(not errors):
        errors = validate_images()

    if(not errors):
        errors = do_update()

    if not args.quiet and not errors:
        print "Command completed successfully."
        print "A power cycle is required for the update to take effect.\n"

    return errors
Exemple #35
0
def tspackage_command(args):
    """Get information pertaining to each node.
    This includes:
    Version info (like cxmanage info)
    MAC addresses
    Sensor readings
    Sensor data records
    Firmware info
    Boot order
    SELs (System Event Logs),
    Depth charts
    Routing Tables

    This data will be written to a set of files. Each node will get its own
    file. All of these files will be archived and saved to the user's current
    directory.

    Internally, this command is called from:
    ~/virtual_testenv/workspace/cx_manage_util/scripts/cxmanage

    """
    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp)

    # Make a temporary directory to store the node information files
    original_dir = os.getcwd()
    temp_dir = tempfile.mkdtemp()
    os.chdir(temp_dir)
    tspackage_dir = "tspackage.%s" % time.strftime("%Y%m%d%H%M%S")
    os.mkdir(tspackage_dir)
    os.chdir(tspackage_dir)

    quiet = args.quiet

    write_client_info()

    if not quiet:
        print("Getting version information...")
    write_version_info(args, nodes)

    if not quit:
        print("Getting LAN information...")
    write_lan_info(args, nodes)

    if not quiet:
        print("Getting boot order...")
    write_boot_order(args, nodes)

    if not quiet:
        print("Getting MAC addresses...")
    write_mac_addrs(args, nodes)

    if not quiet:
        print("Getting sensor information...")
    write_sensor_info(args, nodes)

    if not quiet:
        print("Getting firmware information...")
    write_fwinfo(args, nodes)

    if not quiet:
        print("Getting system event logs...")
    write_sel(args, nodes)

    if not quiet:
        print("Getting depth charts...")
    write_depth_chart(args, nodes)

    if not quiet:
        print("Getting routing tables...")
    write_routing_table(args, nodes)

    if not quiet:
        print("Getting serial log...")
    write_serial_log(args, nodes)

    if not quiet:
        print("Getting crash log...")
    write_crash_log(args, nodes)

    # Archive the files
    archive(os.getcwd(), original_dir)

    # The original files are already archived, so we can delete them.
    shutil.rmtree(temp_dir)
Exemple #36
0
def fwupdate_command(args):
    """update firmware on a cluster or host"""
    def do_update():
        """ Do a single firmware check+update. Returns True on failure. """
        if not args.force:
            if not args.quiet:
                print "Checking hosts..."

            _, errors = run_command(args, nodes, "_check_firmware", package,
                                    args.partition, args.priority)
            if errors:
                print "ERROR: Firmware update aborted."
                return True

        if not args.quiet:
            print "Updating firmware..."

        _, errors = run_command(args, nodes, "update_firmware", package,
                                args.partition, args.priority)
        if errors:
            print "ERROR: Firmware update failed."
            return True

        return False

    def do_reset():
        """ Reset and wait. Returns True on failure. """
        if not args.quiet:
            print "Checking ECME versions..."

        results, errors = run_command(args, nodes, "get_versions")
        if errors:
            print "ERROR: MC reset aborted. Backup partitions not updated."
            return True

        for result in results.values():
            version = result.ecme_version.lstrip("v")
            if parse_version(version) < parse_version("1.2.0"):
                print "ERROR: MC reset is unsafe on ECME version v%s" % version
                print "Please power cycle the system and start a new fwupdate."
                return True

        if not args.quiet:
            print "Resetting nodes..."

        results, errors = run_command(args, nodes, "mc_reset", True)
        if errors:
            print "ERROR: MC reset failed. Backup partitions not updated."
            return True

        return False

    if args.image_type == "PACKAGE":
        package = FirmwarePackage(args.filename)
    else:
        try:
            simg = None
            if args.force_simg:
                simg = False
            elif args.skip_simg:
                simg = True

            image = Image(args.filename, args.image_type, simg, args.daddr,
                          args.skip_crc32, args.fw_version)
            package = FirmwarePackage()
            package.images.append(image)
        except ValueError as err:
            print "ERROR: %s" % err
            return True

    if not args.all_nodes:
        if args.force:
            print('WARNING: Updating firmware without --all-nodes' +
                  ' is dangerous.')
        else:
            if not prompt_yes('WARNING: Updating firmware without ' +
                              '--all-nodes is dangerous. Continue?'):
                return 1

    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp, verify_prompt=True)

    errors = do_update()

    if args.full and not errors:
        errors = do_reset()
        if not errors:
            errors = do_update()

    if not args.quiet and not errors:
        print "Command completed successfully.\n"

    return errors