def migrate(request): json_data = request.GET.get('data_to_migrate') data = json.loads(json_data) cfg.parse(['--config-file', '../flyway/etc/flyway.conf']) tenants = data.get('tenants_to_move', None) if data else None flavors = data.get('flavors_to_migrate', None) if data else None images = data.get('images_to_migrate', None) if data else None keypairs = data.get('keypairs_to_move', None) if data else None image_tenants = data.get('tenant_to_process', None) if data else None roles = data.get('roles_to_migrate', None) if data else None users = data.get('users_to_move', None) if data else None refined_data = {'tenants_to_move': tenants, 'flavors_to_migrate': flavors, 'images_to_migrate': images, 'tenant_to_process': keypairs, 'keypairs_to_move': image_tenants, 'roles_to_migrate': roles, 'users_to_move': users} print "data:" print refined_data result = flow.execute(refined_data) return HttpResponse(json.dumps(result, ensure_ascii=False))
def get_roles(request): cfg.parse(['--config-file', '../flyway/etc/flyway.conf']) migration_task = RoleMigrationTask() roles = migration_task.ks_source.roles.list() return_roles = [{'name': role.name, 'id': role.id} for role in roles] return HttpResponse(json.dumps(return_roles, ensure_ascii=False))
def get_images(request): cfg.parse(['--config-file', '../flyway/etc/flyway.conf']) migration_task = ImageMigrationTask('') images = migration_task.gl_source.images.list() return_images = [{'name': image.name, 'id': image.id} for image in images] return HttpResponse(json.dumps(return_images, ensure_ascii=False))
def get_tenants(request): cfg.parse(['--config-file', '../flyway/etc/flyway.conf']) migration_task = TenantMigrationTask('') tenants = migration_task.ks_source.tenants.list() return_tenants = [{'name': tenant.name, 'id': tenant.id} for tenant in tenants] return HttpResponse(json.dumps(return_tenants, ensure_ascii=False))
def get_users(request): cfg.parse(['--config-file', '../flyway/etc/flyway.conf']) migration_task = UserMigrationTask() users = migration_task.ks_source.users.list() return_users = [{'name': user.name, 'id': user.id} for user in users] return HttpResponse(json.dumps(return_users, ensure_ascii=False))
def get_flavors(request): cfg.parse(['--config-file', '../flyway/etc/flyway.conf']) migration_task = FlavorMigrationTask('') flavors = migration_task.nv_source.flavors.list() return_flavors = [{'name': flavor.name, 'id': flavor.id} for flavor in flavors] return HttpResponse(json.dumps(return_flavors, ensure_ascii=False))
def get_vms(request): cfg.parse(['--config-file', '../flyway/etc/flyway.conf']) # TODO: what task ?? migration_task = UserMigrationTask() vms = migration_task.nv_source.vms.list() return_vms = [{'name': vm.name, 'id': vm.id} for vm in vms] return HttpResponse(json.dumps(return_vms, ensure_ascii=False))
def main(): # the configuration will be read into the cfg.CONF global data structure args = ['--config-file'] if len(sys.argv) > 2 and sys.argv[1] == '--config-file': args.append(sys.argv[2]) config.parse(args) config.setup_logging() if not cfg.CONF.config_file: sys.exit("ERROR: Unable to find configuration file via the '--config-file' option!") #Interaction with database and store cloud credentials into source cloud database while True: passwd = getpass.getpass('The source cloud credentials will be stored into mysql database, please type in source cloud mysql database password. If password is equal to admin password, type in Enter directly!\nPassword:\n') if passwd is not '': password = passwd else: password = cfg.CONF.SOURCE.os_password print password ip = re.search('http://(.+?):', cfg.CONF.SOURCE.os_auth_url) DNScredentials = {'host': ip.group(1), 'user': '******', 'passwd':password, 'db': 'keystone'} db = None try: db = connect(**DNScredentials) cursor = getCursor(db) createDNS(db, cursor) insertTargetDNS(db, cursor) insertSourceDNS(db, cursor) db.close() break except: print 'Unable to connect to mysql database!' continue elif len(sys.argv) > 4 and sys.argv[1] == '-src' and sys.argv[3] == '-dst': db = connect(**DNScredentials) cursor = getCursor(db) srcConfig = readDNS(db, cursor, sys.argv[2]) if not srcConfig: print "Cloud " + sys.argv[2] + ' does not exist in the database, please configure flyway.conf!' dstConfig = readDNS(db, cursor, sys.argv[4]) if not dstConfig: sys.exit("Cloud " + sys.argv[4] + ' does not exist in the database, please configure flyway.conf!') writeToFile('etc/flyway.conf', configContent(srcConfig, dstConfig)) args.append('./etc/flyway.conf') config.parse(args) config.setup_logging() db.close() try: flow.execute() except RuntimeError, e: sys.exit("ERROR: %s" % e)
def __init__(self, *args, **kwargs): super(TestBase, self).__init__(*args, **kwargs) config.parse(['--config-file', '../../etc/flyway.conf']) setup_scheduler() db_name = 'flyway' create_database(db_name) release_db_pool() create_db_pool(db_name)
def get_keypairs(request): cfg.parse(['--config-file', '../flyway/etc/flyway.conf']) migration_task = KeypairMigrationTask('') data = get_info_from_openstack_db(table_name="key_pairs", db_name='nova', host=migration_task.s_host, columns=['name', 'fingerprint'], filters={"deleted": '0'}) return_keypairs = [{'name': pair[0], 'fingerprint': pair[1]} for pair in data] return HttpResponse(json.dumps(return_keypairs, ensure_ascii=False))
def main(): # the configuration will be read into the cfg.CONF global data structure args = ['--config-file'] if len(sys.argv) > 2: args.append(sys.argv[2]) config.parse(args) config.setup_logging() if not cfg.CONF.config_file: sys.exit("ERROR: Unable to find configuration file via the " "'--config-file' option!") try: flow.execute() except RuntimeError, e: sys.exit("ERROR: %s" % e)
def main(): # the configuration will be read into the cfg.CONF global data structure args = ['--config-file'] if len(sys.argv) > 2 and sys.argv[1] == '--config-file': args.append(sys.argv[2]) config.parse(args) config.setup_logging() if not cfg.CONF.config_file: sys.exit("ERROR: Unable to find configuration " + "file via the '--config-file' option!") initialize_environment() # store cloud "environment" (connection details) into database update_environment() # else select a pre-stored source-destination clouds pair to # begin the migration between them elif len(sys.argv) > 4 and sys.argv[1] == '-src' and sys.argv[3] == '-dst': src_config = read_environment(sys.argv[2]) print src_config if not src_config: print "Cloud " + sys.argv[2] + \ ' does not exist in the database, ' \ 'please configure flyway.conf!' dst_config = read_environment(sys.argv[4]) if not dst_config: sys.exit("Cloud " + sys.argv[4] + ' does not exist in the database, ' 'please configure flyway.conf!') write_to_file('etc/flyway.conf', config_content(src_config, dst_config)) args.append('./etc/flyway.conf') config.parse(args) config.setup_logging() try: flow.execute() except RuntimeError, e: sys.exit("ERROR: %s" % e)
from utils.db_handlers.environment_config import initialize_environment, update_environment from flow.flavortask import FlavorMigrationTask from flow.imagetask import ImageMigrationTask from flow.keypairtask import KeypairMigrationTask from flow.roletask import RoleMigrationTask from flow.tenanttask import TenantMigrationTask from flow.instancetask import InstanceMigrationTask from utils.db_handlers.keypairs import * from flow import flow from django.shortcuts import render from flow.usertask import UserMigrationTask from common import config as cfg cfg.parse(['--config-file', '../flyway/etc/flyway.conf']) cfg.setup_logging() initialize_environment() update_environment() def index(request): latest_poll_list = [1, 2, 3, 4, 5] context = {'latest_poll_list': latest_poll_list} return render(request, 'flyway_test/index.html', context) def find_users(request): migration_task = UserMigrationTask() users = migration_task.ks_source.users.list() context = {'users': users}
UNIQUE (roleName, src_cloud, dst_cloud) ''' create_table(TABLE_NAME, table_columns, False) s_cloud_name = cfg.CONF.SOURCE.os_cloud_name t_cloud_name = cfg.CONF.TARGET.os_cloud_name for role in name_of_roles_to_move: if not existed(role): record = "null, '"+role+"','"+s_cloud_name+"', '"+t_cloud_name+"', 'unknown'" insert_record(TABLE_NAME, [record], False) def existed(role_name): filters = { "roleName": role_name, "src_cloud": cfg.CONF.SOURCE.os_cloud_name, "dst_cloud": cfg.CONF.TARGET.os_cloud_name } data = read_record(TABLE_NAME, ["0"], filters, True) return data if __name__ == '__main__': print 'empty roles table' LOG.info('make roles table empty') config.parse(['--config-file', '../../etc/flyway.conf']) namelist = [] initialise_roles_mapping(namelist) delete_all_data(TABLE_NAME)
def __init__(self, *args, **kwargs): super(FlavorTaskTest, self).__init__(*args, **kwargs) config.parse(['--config-file', '../../etc/flyway.conf']) self.migration_task = FlavorMigrationTask('flavor_migration_task')
def __init__(self, *args, **kwargs): super(TenantTaskTest, self).__init__(*args, **kwargs) config.parse(['--config-file', '../../etc/flyway.conf']) self.migration_task = TenantMigrationTask('tenant_migration_task')
def __init__(self, *args, **kwargs): super(TestBase, self).__init__(*args, **kwargs) config.parse(['--config-file', '../../etc/flyway.conf'])
insert_record(TABLE_NAME, init_roles, True) def existed(role_name): filters = { "roleName": role_name, "src_cloud": cfg.CONF.SOURCE.os_cloud_name, "dst_cloud": cfg.CONF.TARGET.os_cloud_name } data = read_record(TABLE_NAME, ["0"], filters, True) return data def delete_all_roles_mapping(roles): for role in roles: delete_record( TABLE_NAME, { "src_cloud": cfg.CONF.SOURCE.os_cloud_name, "dst_cloud": cfg.CONF.TARGET.os_cloud_name, "roleName": role.name }) if __name__ == '__main__': print 'empty roles table' LOG.info('make roles table empty') config.parse(['--config-file', '../../etc/flyway.conf']) namelist = [] initialise_roles_mapping(namelist) delete_record(TABLE_NAME, None)
def __init__(self, *args, **kwargs): super(RoleTaskTest, self).__init__(*args, **kwargs) config.parse(['--config-file', '../../etc/flyway.conf']) self.migration_task = RoleMigrationTask()
def __init__(self, *args, **kwargs): super(UserTaskTest, self).__init__(*args, **kwargs) config.parse(['--config-file', '../../etc/flyway.conf']) self.migration_task = UserMigrationTask() self.mox_factory = mox.Mox()
def find_users(request): cfg.parse(['--config-file', '../flyway/etc/flyway.conf']) migration_task = UserMigrationTask() users = migration_task.ks_source.users.list() context = {'users': users} return render(request, 'flyway_test/index.html', context)