Example #1
0
def set_rails_loglevel(level, validate_against_worker='MiqUiWorker'):
    """Sets the logging level for level_rails and detects when change occured."""
    ui_worker_pid = '#{}'.format(get_worker_pid(validate_against_worker))

    logger.info('Setting log level_rails on appliance to {}'.format(level))
    yaml = get_yaml_config('vmdb')
    if not str(yaml['log']['level_rails']).lower() == level.lower():
        logger.info('Opening /var/www/miq/vmdb/log/evm.log for tail')
        evm_tail = SSHTail('/var/www/miq/vmdb/log/evm.log')
        evm_tail.set_initial_file_end()

        yaml['log']['level_rails'] = level
        set_yaml_config("vmdb", yaml)

        attempts = 0
        detected = False
        while (not detected and attempts < 60):
            logger.debug('Attempting to detect log level_rails change: {}'.format(attempts))
            for line in evm_tail:
                if ui_worker_pid in line:
                    if 'Log level for production.log has been changed to' in line:
                        # Detects a log level change but does not validate the log level
                        logger.info('Detected change to log level for production.log')
                        detected = True
                        break
            time.sleep(1)  # Allow more log lines to accumulate
            attempts += 1
        if not (attempts < 60):
            # Note the error in the logger but continue as the appliance could be slow at logging
            # that the log level changed
            logger.error('Could not detect log level_rails change.')
    else:
        logger.info('Log level_rails already set to {}'.format(level))
Example #2
0
    def rename(self, new_name):
        """Changes appliance name

        Args:
            new_name: Name to set

        Note:
            Database must be up and running and evm service must be (re)started afterwards
            for the name change to take effect.
        """
        vmdb_config = db.get_yaml_config('vmdb', self.db)
        vmdb_config['server']['name'] = new_name
        db.set_yaml_config('vmdb', vmdb_config, self.address)
        self.name = new_name
Example #3
0
    def rename(self, new_name):
        """Changes appliance name

        Args:
            new_name: Name to set

        Note:
            Database must be up and running and evm service must be (re)started afterwards
            for the name change to take effect.
        """
        vmdb_config = db.get_yaml_config('vmdb', self.db)
        vmdb_config['server']['name'] = new_name
        db.set_yaml_config('vmdb', vmdb_config, self.address)
        self.name = new_name
Example #4
0
def set_rails_loglevel(level, validate_against_worker='MiqUiWorker'):
    """Sets the logging level for level_rails and detects when change occured."""
    ui_worker_pid = '#{}'.format(get_worker_pid(validate_against_worker))

    logger.info('Setting log level_rails on appliance to {}'.format(level))
    yaml = get_yaml_config('vmdb')
    if not str(yaml['log']['level_rails']).lower() == level.lower():
        logger.info('Opening /var/www/miq/vmdb/log/evm.log for tail')
        evm_tail = SSHTail('/var/www/miq/vmdb/log/evm.log')
        evm_tail.set_initial_file_end()

        yaml['log']['level_rails'] = level
        set_yaml_config("vmdb", yaml)

        attempts = 0
        detected = False
        while (not detected and attempts < 60):
            logger.debug(
                'Attempting to detect log level_rails change: {}'.format(
                    attempts))
            for line in evm_tail:
                if ui_worker_pid in line:
                    if 'Log level for production.log has been changed to' in line:
                        # Detects a log level change but does not validate the log level
                        logger.info(
                            'Detected change to log level for production.log')
                        detected = True
                        break
            time.sleep(1)  # Allow more log lines to accumulate
            attempts += 1
        if not (attempts < 60):
            # Note the error in the logger but continue as the appliance could be slow at logging
            # that the log level changed
            logger.error('Could not detect log level_rails change.')
    else:
        logger.info('Log level_rails already set to {}'.format(level))
Example #5
0
def main():
    parser = argparse.ArgumentParser(
        epilog=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('--address',
                        help='hostname or ip address of target appliance',
                        default=parse_if_not_none(env.get("base_url", None)))
    parser.add_argument('--sdk_url',
                        help='url to download sdk pkg',
                        default=cfme_data.get("basic_info",
                                              {}).get("netapp_sdk_url", None))
    parser.add_argument('--restart',
                        help='restart evmserverd after installation ' +
                        '(required for proper operation)',
                        action="store_true")

    args = parser.parse_args()

    ssh_kwargs = {
        'username': credentials['ssh']['username'],
        'password': credentials['ssh']['password'],
        'hostname': args.address
    }

    # Init SSH client
    client = SSHClient(**ssh_kwargs)

    # start
    filename = args.sdk_url.split('/')[-1]
    foldername = os.path.splitext(filename)[0]

    # download
    print 'Downloading sdk'
    status, out = client.run_command(
        'wget {url} -O {file} > /root/unzip.out 2>&1'.format(url=args.sdk_url,
                                                             file=filename))

    # extract
    print 'Extracting sdk ({})'.format(filename)
    status, out = client.run_command(
        'unzip -o -d /var/www/miq/vmdb/lib/ {}'.format(filename))
    if status != 0:
        print out
        sys.exit(1)

    # install
    print 'Installing sdk ({})'.format(foldername)
    path = "/var/www/miq/vmdb/lib/{}/lib/linux-64".format(foldername)
    # Check if we haven't already added this line
    if client.run_command(
            "grep -F '{}' /etc/default/evm".format(path))[0] != 0:
        status, out = client.run_command(
            'echo "export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:{}" >> /etc/default/evm'
            .format(path))
        if status != 0:
            print 'SDK installation failure (rc: {})'.format(out)
            print out
            sys.exit(1)
    else:
        print "Not needed to install, already done"

    print "Running ldconfig"
    client.run_command("ldconfig")

    print "Modifying YAML configuration"
    yaml = get_yaml_config("vmdb")
    yaml["product"]["storage"] = True
    set_yaml_config("vmdb", yaml)

    client.run_command("touch /var/www/miq/vmdb/HAS_NETAPP"
                       )  # To mark that we installed netapp

    # service evmserverd restart
    if args.restart:
        print 'Appliance restart'
        status, out = client.run_command('reboot &')
        time.sleep(30)  # To prevent clobbing with appliance shutting down
        print 'evmserverd restarted, the UI should start shortly.'
    else:
        print 'evmserverd must be restarted before netapp sdk can be used'
def main():
    parser = argparse.ArgumentParser(epilog=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument(
        '--address',
        help='hostname or ip address of target appliance',
        default=parse_if_not_none(env.get("base_url", None)))
    parser.add_argument(
        '--sdk_url',
        help='url to download sdk pkg',
        default=cfme_data.get("basic_info", {}).get("netapp_sdk_url", None))
    parser.add_argument('--restart', help='restart evmserverd after installation ' +
        '(required for proper operation)', action="store_true")

    args = parser.parse_args()

    ssh_kwargs = {
        'username': credentials['ssh']['username'],
        'password': credentials['ssh']['password'],
        'hostname': args.address
    }

    # Init SSH client
    client = SSHClient(**ssh_kwargs)

    # start
    filename = args.sdk_url.split('/')[-1]
    foldername = os.path.splitext(filename)[0]

    # download
    print 'Downloading sdk'
    status, out = client.run_command('wget {url} -O {file} > /root/unzip.out 2>&1'.format(
        url=args.sdk_url, file=filename))

    # extract
    print 'Extracting sdk ({})'.format(filename)
    status, out = client.run_command('unzip -o -d /var/www/miq/vmdb/lib/ {}'.format(filename))
    if status != 0:
        print out
        sys.exit(1)

    # install
    print 'Installing sdk ({})'.format(foldername)
    path = "/var/www/miq/vmdb/lib/{}/lib/linux-64".format(foldername)
    # Check if we haven't already added this line
    if client.run_command("grep -F '{}' /etc/default/evm".format(path))[0] != 0:
        status, out = client.run_command(
            'echo "export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:{}" >> /etc/default/evm'.format(path))
        if status != 0:
            print 'SDK installation failure (rc: {})'.format(out)
            print out
            sys.exit(1)
    else:
        print "Not needed to install, already done"

    print "Running ldconfig"
    client.run_command("ldconfig")

    print "Modifying YAML configuration"
    yaml = get_yaml_config("vmdb")
    yaml["product"]["storage"] = True
    set_yaml_config("vmdb", yaml)

    client.run_command("touch /var/www/miq/vmdb/HAS_NETAPP")  # To mark that we installed netapp

    # service evmserverd restart
    if args.restart:
        print 'Appliance restart'
        status, out = client.run_command('reboot &')
        time.sleep(30)  # To prevent clobbing with appliance shutting down
        print 'evmserverd restarted, the UI should start shortly.'
    else:
        print 'evmserverd must be restarted before netapp sdk can be used'