def get_ips_for_vms(destination, id_file): nova = nova_common.get_nova(destination) vms = utils.read_ids_from_file(id_file) ips = [] for vm in vms: interfaces = nova.servers.interface_list(vm) for interface in interfaces: for ip in interface.fixed_ips: # print ip['ip_address'] ips.append(ip['ip_address']) return ips
def create_volume(destination, volume): cinder = get_cinder(destination) from_tenant = volume.__dict__['os-vol-tenant-attr:tenant_id'] tenant = keystone_common.find_opposite_tenant_id(from_tenant) if volume.volume_type == 'None': myvol = cinder.volumes.create(size=volume.size, snapshot_id=volume.snapshot_id, name=volume.name, description=volume.description, #volume_type=volume.volume_type, #user_id=volume.user_id, todo:fixthis project_id=tenant, availability_zone=volume.availability_zone, metadata=volume.metadata, #imageRef=volume.imageRef, source_volid=volume.source_volid ) else: myvol = cinder.volumes.create(size=volume.size, snapshot_id=volume.snapshot_id, name=volume.name, description=volume.description, volume_type=volume.volume_type, #user_id=volume.user_id, todo:fixthis project_id=tenant, availability_zone=volume.availability_zone, metadata=volume.metadata, #imageRef=volume.imageRef, source_volid=volume.source_volid ) print "Volume", myvol.name, "created" if volume.attachments: for att in volume.attachments: print att print att['server_id'] device = att['device'] print device vm = nova_common.get_vm_by_original_id('to', att['server_id']) if vm: #myvol.attach(vm.id, device) # Followed this advice: http://www.florentflament.com/blog/openstack-volume-in-use-although-vm-doesnt-exist.html nova = nova_common.get_nova(destination) nova.volumes.create_server_volume(vm.id, myvol.id, device) print "Volume", myvol.name, "attached to VM", vm.name else: print "Original Volume", volume.name, "was attached to a VM with ID", att['server_id'], \ "but this VM was not found in the current VM list" return myvol
time.sleep(5) else: break if volume.attachments: for att in volume.attachments: print att print att['server_id'] device = att['device'] print device vm = nova_common.get_vm_by_original_id('to', att['server_id']) if vm: #myvol.attach(vm.id, device) # Followed this advice: http://www.florentflament.com/blog/openstack-volume-in-use-although-vm-doesnt-exist.html nova = nova_common.get_nova(destination) nova.volumes.create_server_volume(vm.id, myvol.id, device) print "Volume", myvol.name, "attached to VM", vm.name else: print "Original Volume", volume.name, "was attached to a VM with ID", att['server_id'], \ "but this VM was not found in the current VM list" return myvol else: print "Image", image_name, "for volume migration not found. Did you skip a step?" def create_volume_from_image_by_vm_ids(id_file): ready = nova_common.check_vm_are_on('to', id_file) if ready: volume_ids = nova_common.get_volume_id_list_for_vm_ids('from', id_file) from_volumes = get_volume_list('from')