def update_application_owner(application, identity): from service.openstack import glance_update_machine_metadata from service.driver import get_account_driver old_identity = application.created_by_identity tenant_name = _extract_tenant_name(identity) old_tenant_name = _extract_tenant_name(old_identity) # Prepare the application application.created_by_identity = identity application.created_by = identity.created_by application.save() # Update all the PMs all_pms = application.providermachine_set.all() print "Updating %s machines.." % len(all_pms) for provider_machine in all_pms: accounts = get_account_driver(provider_machine.provider) image_id = provider_machine.instance_source.identifier image = accounts.get_image(image_id) if not image: continue tenant_id = accounts.get_project(tenant_name).id glance_update_machine_metadata(provider_machine, {"owner": tenant_id, "application_owner": tenant_name}) print "App data saved for %s" % image_id accounts.image_manager.share_image(image, tenant_name) print "Shared access to %s with %s" % (image_id, tenant_name) accounts.image_manager.unshare_image(image, old_tenant_name) print "Removed access to %s for %s" % (image_id, old_tenant_name)
def update_application_owner(application, identity): from service.openstack import glance_update_machine_metadata from service.driver import get_account_driver old_identity = application.created_by_identity tenant_name = _extract_tenant_name(identity) old_tenant_name = _extract_tenant_name(old_identity) # Prepare the application application.created_by_identity = identity application.created_by = identity.created_by application.save() # Update all the PMs all_pms = application.providermachine_set.all() print "Updating %s machines.." % len(all_pms) for provider_machine in all_pms: accounts = get_account_driver(provider_machine.provider) image_id = provider_machine.instance_source.identifier image = accounts.get_image(image_id) if not image: continue tenant_id = accounts.get_project(tenant_name).id glance_update_machine_metadata( provider_machine, {'owner': tenant_id, 'application_owner': tenant_name}) print "App data saved for %s" % image_id accounts.image_manager.share_image(image, tenant_name) print "Shared access to %s with %s" % (image_id, tenant_name) accounts.image_manager.unshare_image(image, old_tenant_name) print "Removed access to %s for %s" % (image_id, old_tenant_name)