def __call__(self, filename, replacements=None): if filename.startswith('/'): complete_path = data_path_for_filename(filename.strip('/'), self.base_path) else: complete_path = data_path_for_filename(filename, self.base_path, self.testmod_path) seen_data_files.add(complete_path) return load_data_file(complete_path, replacements)
def __call__(self, filename, replacements=None): if filename.startswith('/'): complete_path = data_path_for_filename( filename.strip('/'), self.base_path) else: complete_path = data_path_for_filename( filename, self.base_path, self.testmod_path) seen_data_files.add(complete_path) return load_data_file(complete_path, replacements)
def main(): parser = argparse.ArgumentParser( epilog=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('address', help='hostname or ip address of target appliance') parser.add_argument('db_address', help='hostname or ip address of external database') parser.add_argument('--database', default='vmdb_production', help='name of the external database') parser.add_argument('--region', default=0, type=int, help='region to assign to the new DB') parser.add_argument('--username', default=credentials['database']['username'], help='username for external database') parser.add_argument('--password', default=credentials['database']['password'], help='password for external database') args = parser.parse_args() ssh_kwargs = { 'username': credentials['ssh']['username'], 'password': credentials['ssh']['password'], 'hostname': args.address } rbt_repl = { 'miq_lib': '/var/www/miq/lib', 'host': args.db_address, 'database': args.database, 'region': args.region, 'username': args.username, 'password': args.password } # Find and load our rb template with replacements base_path = os.path.dirname(__file__) rbt = datafile.data_path_for_filename('enable-external-db.rbt', base_path) rb = datafile.load_data_file(rbt, rbt_repl) # Init SSH client and sent rb file over to /tmp remote_file = '/tmp/%s' % generate_random_string() client = SSHClient(**ssh_kwargs) client.put_file(rb.name, remote_file) # Run the rb script, clean it up when done print 'Initializing Appliance External DB' status, out = client.run_command('ruby %s' % remote_file) client.run_command('rm %s' % remote_file) if status != 0: print 'Enabling DB failed with error:' print out sys.exit(1) else: print 'DB Enabled, evm watchdog should start the UI shortly.'
def enable_internal(self, region=0, key_address=None, db_password=None, ssh_password=None): """Enables internal database Args: region: Region number of the CFME appliance. key_address: Address of CFME appliance where key can be fetched. Note: If key_address is None, a new encryption key is generated for the appliance. """ self.logger.info('Enabling internal DB (region {}) on {}.'.format( region, self.address)) self.address = self.appliance.address clear_property_cache(self, 'client') client = self.ssh_client # Defaults db_password = db_password or conf.credentials['database']['password'] ssh_password = ssh_password or conf.credentials['ssh']['password'] if self.appliance.has_cli: # use the cli if key_address: status, out = client.run_command( 'appliance_console_cli --region {0} --internal --fetch-key {1} -p {2} -a {3}' .format(region, key_address, db_password, ssh_password)) else: status, out = client.run_command( 'appliance_console_cli --region {} --internal --force-key -p {}' .format(region, db_password)) else: # no cli, use the enable internal db script rbt_repl = { 'miq_lib': '/var/www/miq/lib', 'region': region, 'postgres_version': self.postgres_version } # Find and load our rb template with replacements rbt = datafile.data_path_for_filename('enable-internal-db.rbt', scripts_path.strpath) rb = datafile.load_data_file(rbt, rbt_repl) # sent rb file over to /tmp remote_file = '/tmp/{}'.format(fauxfactory.gen_alphanumeric()) client.put_file(rb.name, remote_file) # Run the rb script, clean it up when done status, out = client.run_command('ruby {}'.format(remote_file)) client.run_command('rm {}'.format(remote_file)) return status, out
def main(): parser = argparse.ArgumentParser(epilog=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('address', help='hostname or ip address of target appliance') parser.add_argument('db_address', help='hostname or ip address of external database') parser.add_argument('--database', default='vmdb_production', help='name of the external database') parser.add_argument('--region', default=0, type=int, help='region to assign to the new DB') parser.add_argument('--username', default=credentials['database']['username'], help='username for external database') parser.add_argument('--password', default=credentials['database']['password'], help='password for external database') args = parser.parse_args() ssh_kwargs = { 'username': credentials['ssh']['username'], 'password': credentials['ssh']['password'], 'hostname': args.address } rbt_repl = { 'miq_lib': '/var/www/miq/lib', 'host': args.db_address, 'database': args.database, 'region': args.region, 'username': args.username, 'password': args.password } # Find and load our rb template with replacements base_path = os.path.dirname(__file__) rbt = datafile.data_path_for_filename( 'enable-external-db.rbt', base_path) rb = datafile.load_data_file(rbt, rbt_repl) # Init SSH client and sent rb file over to /tmp remote_file = '/tmp/%s' % generate_random_string() client = SSHClient(**ssh_kwargs) client.put_file(rb.name, remote_file) # Run the rb script, clean it up when done print 'Initializing Appliance External DB' status, out = client.run_command('ruby %s' % remote_file) client.run_command('rm %s' % remote_file) if status != 0: print 'Enabling DB failed with error:' print out sys.exit(1) else: print 'DB Enabled, evm watchdog should start the UI shortly.'
def enable_internal(self, region=0, key_address=None, db_password=None, ssh_password=None): """Enables internal database Args: region: Region number of the CFME appliance. key_address: Address of CFME appliance where key can be fetched. Note: If key_address is None, a new encryption key is generated for the appliance. """ self.logger.info('Enabling internal DB (region {}) on {}.'.format(region, self.address)) self.address = self.appliance.address clear_property_cache(self, 'client') client = self.ssh_client # Defaults db_password = db_password or conf.credentials['database']['password'] ssh_password = ssh_password or conf.credentials['ssh']['password'] if self.appliance.has_cli: # use the cli if key_address: status, out = client.run_command( 'appliance_console_cli --region {0} --internal --fetch-key {1} -p {2} -a {3}' .format(region, key_address, db_password, ssh_password) ) else: status, out = client.run_command( 'appliance_console_cli --region {} --internal --force-key -p {}' .format(region, db_password) ) else: # no cli, use the enable internal db script rbt_repl = { 'miq_lib': '/var/www/miq/lib', 'region': region, 'postgres_version': self.postgres_version } # Find and load our rb template with replacements rbt = datafile.data_path_for_filename('enable-internal-db.rbt', scripts_path.strpath) rb = datafile.load_data_file(rbt, rbt_repl) # sent rb file over to /tmp remote_file = '/tmp/{}'.format(fauxfactory.gen_alphanumeric()) client.put_file(rb.name, remote_file) # Run the rb script, clean it up when done status, out = client.run_command('ruby {}'.format(remote_file)) client.run_command('rm {}'.format(remote_file)) return status, out
def main(): parser = argparse.ArgumentParser( epilog=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('address', help='hostname or ip address of target appliance') parser.add_argument('-R', '--reverse', help='flag to indicate the patch should be undone', action='store_true', default=False, dest='reverse') args = parser.parse_args() # Find the patch file patch_file_name = data_path_for_filename('ajax_wait.diff', scripts_path.strpath) # Set up temp dir tmpdir = mkdtemp() atexit.register(shutil.rmtree, tmpdir) source = '/var/www/miq/vmdb/public/javascripts/application.js' target = os.path.join(tmpdir, 'application.js') # Init SSH client ssh_kwargs = { 'username': credentials['ssh']['username'], 'password': credentials['ssh']['password'], 'hostname': args.address } client = SSHClient(**ssh_kwargs) print 'retriving appliance.js from appliance' client.get_file(source, target) os.chdir(tmpdir) # patch, level 4, patch direction (default forward), ignore whitespace, don't output rejects direction = '-N -R' if args.reverse else '-N' exitcode = subprocess.call('patch -p4 %s -l -r- < %s' % (direction, patch_file_name), shell=True) if exitcode == 0: # Put it back after successful patching. print 'replacing appliance.js on appliance' client.put_file(target, source) else: print 'not changing appliance' return exitcode
def main(): parser = argparse.ArgumentParser(epilog=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('address', help='hostname or ip address of target appliance') parser.add_argument('-R', '--reverse', help='flag to indicate the patch should be undone', action='store_true', default=False, dest='reverse') args = parser.parse_args() # Find the patch file patch_file_name = data_path_for_filename('ajax_wait.diff', scripts_path.strpath) # Set up temp dir tmpdir = mkdtemp() atexit.register(shutil.rmtree, tmpdir) source = '/var/www/miq/vmdb/public/javascripts/application.js' target = os.path.join(tmpdir, 'application.js') # Init SSH client ssh_kwargs = { 'username': credentials['ssh']['username'], 'password': credentials['ssh']['password'], 'hostname': args.address } client = SSHClient(**ssh_kwargs) print 'retriving appliance.js from appliance' client.get_file(source, target) os.chdir(tmpdir) # patch, level 4, patch direction (default forward), ignore whitespace, don't output rejects direction = '-N -R' if args.reverse else '-N' exitcode = subprocess.call('patch -p4 %s -l -r- < %s' % (direction, patch_file_name), shell=True) if exitcode == 0: # Put it back after successful patching. print 'replacing appliance.js on appliance' client.put_file(target, source) else: print 'not changing appliance' return exitcode
def enable_external(self, db_address, region=0, db_name=None, db_username=None, db_password=None): """Enables external database Args: db_address: Address of the external database region: Number of region to join db_name: Name of the external DB db_username: Username to access the external DB db_password: Password to access the external DB Returns a tuple of (exitstatus, script_output) for reporting, if desired """ self.logger.info('Enabling external DB (db_address {}, region {}) on {}.' .format(db_address, region, self.address)) # reset the db address and clear the cached db object if we have one self.address = db_address clear_property_cache(self, 'client') # default db_name = db_name or 'vmdb_production' db_username = db_username or conf.credentials['database']['username'] db_password = db_password or conf.credentials['database']['password'] client = self.ssh_client if self.appliance.has_cli: # copy v2 key master_client = client(hostname=self.address) rand_filename = "/tmp/v2_key_{}".format(fauxfactory.gen_alphanumeric()) master_client.get_file("/var/www/miq/vmdb/certs/v2_key", rand_filename) client.put_file(rand_filename, "/var/www/miq/vmdb/certs/v2_key") # enable external DB with cli status, out = client.run_command( 'appliance_console_cli ' '--hostname {0} --region {1} --dbname {2} --username {3} --password {4}'.format( self.address, region, db_name, db_username, db_password ) ) else: # no cli, use the enable external db script rbt_repl = { 'miq_lib': '/var/www/miq/lib', 'host': self.address, 'region': region, 'database': db_name, 'username': db_username, 'password': db_password } # Find and load our rb template with replacements rbt = datafile.data_path_for_filename('enable-internal-db.rbt', scripts_path.strpath) rb = datafile.load_data_file(rbt, rbt_repl) # Init SSH client and sent rb file over to /tmp remote_file = '/tmp/{}'.format(fauxfactory.gen_alphanumeric()) client.put_file(rb.name, remote_file) # Run the rb script, clean it up when done status, out = client.run_command('ruby {}'.format(remote_file)) client.run_command('rm {}'.format(remote_file)) if status != 0: self.logger.error('error enabling external db') self.logger.error(out) msg = ('Appliance {} failed to enable external DB running on {}' .format(self.appliance.address, db_address)) self.logger.error(msg) from . import ApplianceException raise ApplianceException(msg) return status, out