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)
Ejemplo n.º 2
0
    def test_migrate_instance(self):
        server_name = "instance_name"
        vm_migrated = None

        images = self.gl_source.images.list()
        for one_image in images:
            if one_image.name.find(self.image_name) > -1:
                print one_image.name
                image = self.nv_source.images.find(name=one_image.name)
                self.image_source = image
                flavor = self.nv_source.flavors.find(name="m1.micro")
                vm_migrated = self.nv_source_tenant.servers.create(
                    name=server_name, image=image, flavor=flavor)

        status = vm_migrated.status
        while status == 'BUILD':
            time.sleep(5)
            instance = self.nv_source.servers.get(vm_migrated.id)
            if instance.status == 'ERROR' or 'ACTIVE':
                break
            print instance.status
        # migrate tenant, flavor, image and key pair at first
        values = {
            'users_to_move': [],
            'tenants_to_move': [self.tenant_name],
            'flavors_to_migrate': ['m1.micro'],
            'images_to_migrate': [self.image_source.id],
            'tenant_to_process': [],
            'keypairs_to_move': [],
            'roles_to_migrate': [],
            'tenant_vm_dicts': {
                self.tenant_name: [vm_migrated.id]
            }
        }

        server_target = None
        flavor_target = None
        key_target = None
        image_target = None
        tenant_target = None
        try:
            flow.execute(values)

            self.nv_target_tenant = get_nova_target(self.tenant_name)

            server_target = self.nv_target_tenant.servers.\
                find(name=server_name)
            self.assertIsNot(None, server_target)

            tenant_target = self.ks_target.tenants.find(name=self.tenant_name)

        except Exception, e:
            self.fail(e)
    def test_migrate_instance(self):
        server_name = "instance_name"
        vm_migrated = None

        images = self.gl_source.images.list()
        for one_image in images:
            if one_image.name.find(self.image_name) > -1:
                print one_image.name
                image = self.nv_source.images.find(name=one_image.name)
                self.image_source = image
                flavor = self.nv_source.flavors.find(name="m1.micro")
                vm_migrated = self.nv_source_tenant.servers.create(
                    name=server_name, image=image, flavor=flavor)

        status = vm_migrated.status
        while status == 'BUILD':
            time.sleep(5)
            instance = self.nv_source.servers.get(vm_migrated.id)
            if instance.status == 'ERROR' or 'ACTIVE':
                break
            print instance.status
        # migrate tenant, flavor, image and key pair at first
        values = {'users_to_move': [],
                  'tenants_to_move': [self.tenant_name],
                  'flavors_to_migrate': ['m1.micro'],
                  'images_to_migrate': [self.image_source.id],
                  'tenant_to_process': [],
                  'keypairs_to_move': [],
                  'roles_to_migrate': [],
                  'tenant_vm_dicts': {self.tenant_name: [vm_migrated.id]}}

        server_target = None
        flavor_target = None
        key_target = None
        image_target = None
        tenant_target = None
        try:
            flow.execute(values)

            self.nv_target_tenant = get_nova_target(self.tenant_name)

            server_target = self.nv_target_tenant.servers.\
                find(name=server_name)
            self.assertIsNot(None, server_target)

            tenant_target = self.ks_target.tenants.find(name=self.tenant_name)

        except Exception, e:
            self.fail(e)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
def migrate(request):
    json_data = request.GET.get('data_to_migrate')
    data = json.loads(json_data)

    tenants = data.get('tenant')
    flavors = data.get('flavor')
    images = data.get('image')
    keypairs = data.get('keypair')
    roles = data.get('role')
    users = data.get('user')
    vms = data.get('vm')

    refined_data = {
        'tenants_to_move': tenants,
        'flavors_to_migrate': flavors,
        'images_to_migrate': images,
        'keypairs_to_move': keypairs,
        'roles_to_migrate': roles,
        'users_to_move': users,
        'tenant_vm_dicts': vms,
        'tenant_to_process': []
    }

    print refined_data

    result = flow.execute(refined_data)
    return HttpResponse(json.dumps(result, ensure_ascii=False))
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 migrate(request):
    json_data = request.GET.get('data_to_migrate')
    data = json.loads(json_data)

    tenants = data.get('tenant')
    flavors = data.get('flavor')
    images = data.get('image')
    keypairs = data.get('keypair')
    roles = data.get('role')
    users = data.get('user')
    vms = data.get('vm')

    refined_data = {'tenants_to_move': tenants,
                    'flavors_to_migrate': flavors,
                    'images_to_migrate': images,
                    'keypairs_to_move': keypairs,
                    'roles_to_migrate': roles,
                    'users_to_move': users,
                    'tenant_vm_dicts': vms,
                    'tenant_to_process': []}

    print refined_data

    result = flow.execute(refined_data)
    return HttpResponse(json.dumps(result, 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!")

        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)
Ejemplo n.º 9
0
def migrate_all(request):
    result = flow.execute(None)
    return HttpResponse(json.dumps(result, ensure_ascii=False))
def migrate_all(request):
    result = flow.execute(None)
    return HttpResponse(json.dumps(result, ensure_ascii=False))