def _fix_new_machine_forked(machine_request, provider, new_machine): app_uuid = _generate_app_uuid(new_machine.identifier) if not machine_request.new_version_forked: return False if Application.objects.filter(uuid=app_uuid).count(): return False print "OK: This MachineRequest: %s has a BAD Application." \ "\tUUID should be %s." % (machine_request, app_uuid) old_application = new_machine.application current_application = _create_new_application( machine_request, new_machine.identifier) remaining_machines = old_application._current_machines() for machine in remaining_machines: if machine.identifier == new_machine.identifier: new_machine.application = current_application new_machine.save() current_application.save() # Pass #2 - If remaining, unmatched ids: remaining_machines = old_application._current_machines() acct_provider = machine_request.new_machine_provider accounts = get_account_driver(acct_provider) if remaining_machines: print "Warn: These machines likely point to the wrong application.:%s" % remaining_machines for machine in remaining_machines: glance_image = accounts.image_manager.get_image(machine.identifier) if glance_image: original_request = MachineRequest.objects.filter( new_application_name=glance_image.name) print "Hint: Image_ID:%s Named:%s MachineRequest:%s" % (glance_image.id, glance_image.name, original_request) return True
def _apply_fix(accounts, provider, pm): image_id = pm.identifier uuid = _generate_app_uuid(image_id) g_img = get_image(accounts, image_id) name = g_img.name apps = Application.objects.filter(uuid=uuid) if not apps.count(): app = create_application( provider.uuid, image_id, name, private=( not g_img.is_public), uuid=uuid) else: app = apps[0] pm.application = app pm.save() if NO_META: print "Fixed: %s Now points to %s" % (pm.identifier, app) return app.update_images() g_img = get_image(accounts, image_id) print "Updated: %s Now points to %s" % (pm.identifier, app)
def _identify_problem_apps(provider, accounts, print_log=True): """ """ name_match = [] new_apps = [] not_real_apps = [] correct_apps = [] incorrect_apps = [] for pm in ProviderMachine.objects.filter( instance_source__provider=provider): uuid = _generate_app_uuid(pm.identifier) #if print_log: # print "ProviderMachine: %s == UUID: %s" % (pm.identifier, uuid) apps = Application.objects.filter(uuid=uuid) if not apps.count(): # NO UUID Match on providermachine's identifier g_img = get_image(accounts, pm.identifier) if not g_img: if print_log: print "DELETE: Image <%s> DoesNotExist" % pm.identifier not_real_apps.append(pm) continue #Lookup by name name = g_img.name if Application.objects.filter(name=name).count(): #Application name matches original image name apps_2 = Application.objects.filter(name=name) if apps_2[0] == pm.application: #Matched name is ProviderMachines application #if print_log: # print "OKAY: %s points to correct application by NAME: %s" % (pm.identifier, name) name_match.append(pm) else: #Matched name is NOT ProviderMachines application if print_log or True: print "ProviderMachine: %s points to %s , doesnt match Image Name:%s OR UUID:%s" % ( pm, pm.application, name, uuid) incorrect_apps.append(pm) else: # No matching named application.. Print original machine and application if print_log: print "CREATE: ProviderMachine: %s points to %s, Creating new application-%s and assigning to %s. Named %s based on glance image." % ( pm.identifier, pm.application, uuid, pm.identifier, name) new_apps.append(pm) else: # UUID Match on providermachine's identifier if apps[0] == pm.application: #if print_log: # print "OKAY: %s points to correct application." % pm.identifier correct_apps.append(pm) else: if print_log or True: print "Application for UUID:%s - %s exists but PM points to %s" % ( uuid, apps[0], pm.application) incorrect_apps.append(pm) return (not_real_apps, incorrect_apps, new_apps, name_match, correct_apps)
def _identify_problem_apps(provider, accounts, print_log=True): """ """ name_match=[] new_apps = [] not_real_apps = [] correct_apps = [] incorrect_apps = [] for pm in ProviderMachine.objects.filter(instance_source__provider=provider): uuid = _generate_app_uuid(pm.identifier) #if print_log: # print "ProviderMachine: %s == UUID: %s" % (pm.identifier, uuid) apps = Application.objects.filter(uuid=uuid) if not apps.count(): # NO UUID Match on providermachine's identifier g_img = get_image(accounts, pm.identifier) if not g_img: if print_log: print "DELETE: Image <%s> DoesNotExist" % pm.identifier not_real_apps.append(pm) continue #Lookup by name name = g_img.name if Application.objects.filter(name=name).count(): #Application name matches original image name apps_2 = Application.objects.filter(name=name) if apps_2[0] == pm.application: #Matched name is ProviderMachines application #if print_log: # print "OKAY: %s points to correct application by NAME: %s" % (pm.identifier, name) name_match.append(pm) else: #Matched name is NOT ProviderMachines application if print_log or True: print "ProviderMachine: %s points to %s , doesnt match Image Name:%s OR UUID:%s" % (pm, pm.application, name, uuid) incorrect_apps.append(pm) else: # No matching named application.. Print original machine and application if print_log: print "CREATE: ProviderMachine: %s points to %s, Creating new application-%s and assigning to %s. Named %s based on glance image." % (pm.identifier, pm.application, uuid, pm.identifier, name) new_apps.append(pm) else: # UUID Match on providermachine's identifier if apps[0] == pm.application: #if print_log: # print "OKAY: %s points to correct application." % pm.identifier correct_apps.append(pm) else: if print_log or True: print "Application for UUID:%s - %s exists but PM points to %s" % (uuid, apps[0], pm.application) incorrect_apps.append(pm) return (not_real_apps, incorrect_apps, new_apps, name_match, correct_apps)
def fix_images(provider, images=[]): accounts = get_account_driver(provider) for image_id in images: glance_image = accounts.image_manager.get_image(image_id) if not glance_image: print "ERROR: Image %s does not exist." % image_id break try: # NOTE: Will need to change provider query when migrating to DD and # beyond pm = ProviderMachine.objects.get(provider=provider, identifier=image_id) except ProviderMachine.DoesNotExist: print "Error: NO ProviderMachine for Provider:%s Image ID:%s" % ( provider, image_id) break # It's a real image. It SHOULD have a corresponding machine request try: mr = MachineRequest.objects.get(new_machine__identifier=image_id) except MachineRequest.DoesNotExist: print "Warn: MachineRequest by this ID could not be found" mr = None current_application = pm.application uuid = _generate_app_uuid(image_id) try: original_application = Application.objects.get(uuid=uuid) except Application.DoesNotExist: print "ProviderMachine %s is an update to Application: %s" % ( pm, current_application) print "Creating seperate Application for ProviderMachine %s" % pm original_application = _create_new_application(mr, image_id) # Update Application from MachineRequest information if mr: original_application = _update_application(original_application, mr) if original_application.uuid is not current_application.uuid: pm.application = original_application pm.save() # Write to metadata INCLUDING kernel and ramdisk id! fix_image_metadata(accounts, glance_image, original_application, mr)
def fix_images(provider, images=[]): accounts = get_account_driver(provider) for image_id in images: glance_image = accounts.image_manager.get_image(image_id) if not glance_image: print "ERROR: Image %s does not exist." % image_id break try: # NOTE: Will need to change provider query when migrating to DD and # beyond pm = ProviderMachine.objects.get( provider=provider, identifier=image_id) except ProviderMachine.DoesNotExist: print "Error: NO ProviderMachine for Provider:%s Image ID:%s" % (provider, image_id) break # It's a real image. It SHOULD have a corresponding machine request try: mr = MachineRequest.objects.get(new_machine__identifier=image_id) except MachineRequest.DoesNotExist: print "Warn: MachineRequest by this ID could not be found" mr = None current_application = pm.application uuid = _generate_app_uuid(image_id) try: original_application = Application.objects.get(uuid=uuid) except Application.DoesNotExist: print "ProviderMachine %s is an update to Application: %s" % (pm, current_application) print "Creating seperate Application for ProviderMachine %s" % pm original_application = _create_new_application(mr, image_id) # Update Application from MachineRequest information if mr: original_application = _update_application( original_application, mr) if original_application.uuid is not current_application.uuid: pm.application = original_application pm.save() # Write to metadata INCLUDING kernel and ramdisk id! fix_image_metadata(accounts, glance_image, original_application, mr)