def process_machine_request(machine_request, new_image_id, update_cloud=True): """ NOTE: Current process accepts instance with source of 'Image' ONLY! VOLUMES CANNOT BE IMAGED until this function is updated! """ parent_mach = machine_request.instance.provider_machine parent_app = machine_request.instance.provider_machine.application new_provider = machine_request.new_machine_provider new_owner = machine_request.new_machine_owner owner_identity = _get_owner(new_provider, new_owner) tags = _match_tags_to_names(machine_request.new_machine_tags) if machine_request.new_machine_forked: app = create_application( new_image_id, new_provider.uuid, machine_request.new_machine_name, created_by_identity=owner_identity, description=machine_request.new_machine_description, private=not machine_request.is_public(), tags=tags) else: parent_app = machine_request.instance.source.providermachine.application app = update_application(parent_app, machine_request.new_machine_name, machine_request.new_machine_description, tags) #2. Create the new InstanceSource and appropriate Object, relations, Memberships.. if ProviderMachine.test_existence(new_provider, new_image_id): pm = ProviderMachine.objects.get(identifier=new_image_id, provider=new_provider) pm = update_provider_machine(pm, new_created_by_identity=owner_identity, new_created_by=machine_request.new_machine_owner, new_application=app, new_version=machine_request.new_machine_version, allow_imaging=machine_request.new_machine_allow_imaging) else: pm = create_provider_machine(new_image_id, new_provider.uuid, app, owner_identity, machine_request.new_machine_version, machine_request.new_machine_allow_imaging) provider_machine_write_hook(pm) #Must be set in order to ask for threshold information machine_request.new_machine = pm #3. Associate additional attributes to new application if machine_request.has_threshold(): machine_request.update_threshold() #3. Add new *Memberships For new ProviderMachine//Application if not machine_request.is_public(): upload_privacy_data(machine_request, pm) #5. Advance the state of machine request machine_request.end_date = timezone.now() #After processing, validate the image. machine_request.status = 'validating' machine_request.save() return machine_request
def process_machine_request(machine_request, new_image_id, update_cloud=True): """ NOTE: Current process accepts instance with source of 'Image' ONLY! VOLUMES CANNOT BE IMAGED until this function is updated! """ parent_mach = machine_request.instance.provider_machine parent_app = machine_request.instance.provider_machine.application new_provider = machine_request.new_machine_provider new_owner = machine_request.new_machine_owner owner_identity = _get_owner(new_provider, new_owner) tags = _match_tags_to_names(machine_request.new_machine_tags) if machine_request.new_machine_forked: app = create_application( new_image_id, new_provider.uuid, machine_request.new_machine_name, created_by_identity=owner_identity, description=machine_request.new_machine_description, private=not machine_request.is_public(), tags=tags) else: parent_app = machine_request.instance.source.providermachine.application app = update_application(parent_app, machine_request.new_machine_name, machine_request.new_machine_description, tags) #2. Create the new InstanceSource and appropriate Object, relations, Memberships.. if ProviderMachine.test_existence(new_provider, new_image_id): pm = ProviderMachine.objects.get(identifier=new_image_id, provider=new_provider) pm = update_provider_machine(pm, new_created_by_identity=owner_identity, new_created_by=machine_request.new_machine_owner, new_application=app, new_version=machine_request.new_machine_version) else: pm = create_provider_machine(new_image_id, new_provider.uuid, app, owner_identity, machine_request.new_machine_version) provider_machine_write_hook(pm) #Must be set in order to ask for threshold information machine_request.new_machine = pm #3. Associate additional attributes to new application if machine_request.has_threshold(): machine_request.update_threshold() #3. Add new *Memberships For new ProviderMachine//Application if not machine_request.is_public(): upload_privacy_data(machine_request, pm) #5. Advance the state of machine request machine_request.end_date = timezone.now() #After processing, validate the image. machine_request.status = 'validating' machine_request.save() return machine_request
def _create_new_provider_machine(machine_request, application, new_image_id): #Set application data to an existing/new providermachine from core.models import ProviderMachine try: #In this case, we have 'found' the ProviderMachine via other methods #PRIOR to processing machine request new_provider = machine_request.new_machine_provider new_machine = ProviderMachine.objects.get(identifier=new_image_id, provider=new_provider) _update_existing_machine(machine_request, application, new_machine) except ProviderMachine.DoesNotExist: new_machine = create_provider_machine( machine_request.new_machine_name, new_image_id, machine_request.new_machine_provider.uuid, application, { 'owner':machine_request.new_machine_owner, 'version' : machine_request.new_machine_version}) return new_machine
def process_machine_request(machine_request, new_image_id, update_cloud=True): """ NOTE: Current process accepts instance with source of 'Image' ONLY! VOLUMES CANNOT BE IMAGED until this function is updated! """ # Based on original instance -- You'll need this: parent_mach = machine_request.instance.provider_machine parent_version = parent_mach.application_version # Based on data provided in MR: new_provider = machine_request.new_machine_provider new_owner = machine_request.new_machine_owner owner_identity = _get_owner(new_provider, new_owner) tags = _match_tags_to_names(machine_request.new_version_tags) # TODO: Use it or remove it # membership = _match_membership_to_access( # machine_request.access_list, # machine_request.new_version_membership) if machine_request.new_version_forked: application = create_application( new_provider.uuid, new_image_id, machine_request.new_application_name, created_by_identity=owner_identity, description=machine_request.new_application_description, private=not machine_request.is_public(), tags=tags) else: application = update_application( parent_version.application, machine_request.new_application_name, tags, machine_request.new_application_description) #FIXME: Either *add* system_files here, or *remove* the entire field. app_version = create_app_version(application, machine_request.new_version_name, new_owner, owner_identity, machine_request.new_version_change_log, machine_request.new_version_allow_imaging, provider_machine_id=new_image_id) # 2. Create the new InstanceSource and appropriate Object, relations, # Memberships.. if models.ProviderMachine.test_existence(new_provider, new_image_id): pm = models.ProviderMachine.objects.get( instance_source__identifier=new_image_id, instance_source__provider=new_provider) pm = update_provider_machine( pm, new_created_by_identity=owner_identity, new_created_by=machine_request.new_machine_owner, new_application_version=app_version) else: pm = create_provider_machine(new_image_id, new_provider.uuid, application, owner_identity, app_version) provider_machine_write_hook(pm) # Must be set in order to ask for threshold information machine_request.new_application_version = app_version machine_request.new_machine = pm machine_request.save() # 3. Associate additional attributes to new application if machine_request.has_threshold(): machine_request.update_threshold() # 4a. Add new *Memberships For new ProviderMachine//Application if not machine_request.is_public(): upload_privacy_data(machine_request, pm) # 4b. If new boot scripts have been associated, # add them to the new version. if machine_request.new_version_scripts.count(): for script in machine_request.new_version_scripts.all(): app_version.boot_scripts.add(script) # 4c. If new licenses have been associated, add them to the new version. if machine_request.new_version_licenses.count(): for license in machine_request.new_version_licenses.all(): app_version.licenses.add(license) return machine_request
def process_machine_request(machine_request, new_image_id): from core.models.machine import add_to_cache from core.models.tag import Tag from core.models import Identity, ProviderMachine #Get all the data you can from the machine request owner_ident = Identity.objects.get(created_by=machine_request.new_machine_owner, provider=machine_request.new_machine_provider) parent_mach = machine_request.instance.provider_machine parent_app = machine_request.instance.provider_machine.application if machine_request.new_machine_tags: tags = [Tag.objects.get(name__iexact=tag) for tag in machine_request.new_machine_tags.split(',')] else: tags = [] if machine_request.new_machine_forked: # This is a brand new app and a brand new providermachine new_app = create_application( new_image_id, new_machine_provider.id, machine_request.new_machine_name, owner_ident, machine_request.new_machine_version, machine_request.new_machine_description, tags) app_to_use = new_app else: #This is NOT a fork, the application to be used is that of your # ancestor app_to_use = parent_app #Include your ancestors tags, description if necessary tags.extend(parent_app.tags.all()) if not machine_request.new_machine_description: description = parent_app.description else: description = machine_request.new_machine_description try: #Set application data to an existing/new providermachine new_machine = ProviderMachine.objects.get(identifier=new_image_id) new_machine.application = app_to_use new_machine.save() except ProviderMachine.DoesNotExist: new_machine = create_provider_machine( machine_request.new_machine_name, new_image_id, machine_request.new_machine_provider_id, app_to_use) app = new_machine.application #app.created_by = machine_request.new_machine_owner #app.created_by_identity = owner_ident app.tags = tags app.description = description app.save() new_machine.version = machine_request.new_machine_version new_machine.created_by = machine_request.new_machine_owner new_machine.created_by_identity = owner_ident new_machine.save() add_to_cache(new_machine) machine_request.new_machine = new_machine machine_request.end_date = timezone.now() machine_request.status = 'completed' machine_request.save() return machine_request
def process_machine_request(machine_request, new_image_id, update_cloud=True): """ NOTE: Current process accepts instance with source of 'Image' ONLY! VOLUMES CANNOT BE IMAGED until this function is updated! """ # Based on original instance -- You'll need this: parent_mach = machine_request.instance.provider_machine parent_version = parent_mach.application_version # Based on data provided in MR: new_provider = machine_request.new_machine_provider new_owner = machine_request.new_machine_owner owner_identity = _get_owner(new_provider, new_owner) tags = _match_tags_to_names(machine_request.new_version_tags) # TODO: Use it or remove it # membership = _match_membership_to_access( # machine_request.access_list, # machine_request.new_version_membership) if machine_request.new_version_forked: application = create_application( new_provider.uuid, new_image_id, machine_request.new_application_name, created_by_identity=owner_identity, description=machine_request.new_application_description, private=not machine_request.is_public(), tags=tags) else: application = update_application( parent_version.application, machine_request.new_application_name, tags, machine_request.new_application_description) app_version = create_app_version( application, machine_request.new_version_name, new_owner, owner_identity, machine_request.new_version_change_log, machine_request.new_version_allow_imaging, provider_machine_id=new_image_id) # 2. Create the new InstanceSource and appropriate Object, relations, # Memberships.. if ProviderMachine.test_existence(new_provider, new_image_id): pm = ProviderMachine.objects.get( instance_source__identifier=new_image_id, instance_source__provider=new_provider) pm = update_provider_machine( pm, new_created_by_identity=owner_identity, new_created_by=machine_request.new_machine_owner, new_application_version=app_version) else: pm = create_provider_machine(new_image_id, new_provider.uuid, application, owner_identity, app_version) provider_machine_write_hook(pm) # Must be set in order to ask for threshold information machine_request.new_application_version = app_version machine_request.new_machine = pm machine_request.save() # 3. Associate additional attributes to new application if machine_request.has_threshold(): machine_request.update_threshold() # 4a. Add new *Memberships For new ProviderMachine//Application if not machine_request.is_public(): upload_privacy_data(machine_request, pm) # 4b. If new boot scripts have been associated, # add them to the new version. if machine_request.new_version_scripts.count(): for script in machine_request.new_version_scripts.all(): app_version.boot_scripts.add(script) # 4c. If new licenses have been associated, add them to the new version. if machine_request.new_version_licenses.count(): for license in machine_request.new_version_licenses.all(): app_version.licenses.add(license) # 5. Advance the state of machine request # After processing, validate the image. machine_request.status = 'validating' machine_request.save() return machine_request
def process_machine_request(machine_request, new_image_id): from core.models.machine import add_to_cache from core.models.tag import Tag from core.models import Identity, ProviderMachine #Get all the data you can from the machine request new_provider = machine_request.new_machine_provider owner_ident = Identity.objects.get( created_by=machine_request.new_machine_owner, provider=new_provider) parent_mach = machine_request.instance.provider_machine parent_app = machine_request.instance.provider_machine.application if machine_request.new_machine_tags: tags = [ Tag.objects.get(name__iexact=tag) for tag in machine_request.new_machine_tags.split(',') ] else: tags = [] #if machine_request.new_machine_forked: #NOTE: Swap these lines when application forking/versioning is supported in the UI if True: # This is a brand new app and a brand new providermachine new_app = create_application( new_image_id, new_provider.id, machine_request.new_machine_name, owner_ident, #new_app.Private = False when machine_request.is_public = True not machine_request.is_public(), machine_request.new_machine_version, machine_request.new_machine_description, tags) app_to_use = new_app description = machine_request.new_machine_description else: #This is NOT a fork, the application to be used is that of your # ancestor, and the app owner should not be changed. app_to_use = parent_app #Include your ancestors tags, description if necessary tags.extend(parent_app.tags.all()) if not machine_request.new_machine_description: description = parent_app.description else: description = machine_request.new_machine_description app.private = not machine_request.is_public() app.tags = tags app.description = description app.save() #Set application data to an existing/new providermachine try: new_machine = ProviderMachine.objects.get(identifier=new_image_id) new_machine.application = app_to_use new_machine.version = machine_request.new_machine_version new_machine.created_by = machine_request.new_machine_owner new_machine.created_by_identity = owner_ident new_machine.save() except ProviderMachine.DoesNotExist: new_machine = create_provider_machine( machine_request.new_machine_name, new_image_id, machine_request.new_machine_provider_id, app_to_use, {'version': machine_request.new_machine_version}) #Be sure to write all this data to openstack metadata #So that it can continue to be the 'authoritative source' if not machine_request.is_public(): upload_privacy_data(machine_request, new_machine) save_app_data(new_machine.application) add_to_cache(new_machine) machine_request.new_machine = new_machine machine_request.end_date = timezone.now() machine_request.status = 'completed' machine_request.save() return machine_request
def process_machine_request(machine_request, new_image_id): from core.models.machine import add_to_cache from core.models.tag import Tag from core.models import Identity, ProviderMachine #Get all the data you can from the machine request new_provider = machine_request.new_machine_provider owner_ident = Identity.objects.get(created_by=machine_request.new_machine_owner, provider=new_provider) parent_mach = machine_request.instance.provider_machine parent_app = machine_request.instance.provider_machine.application if machine_request.new_machine_tags: tags = [Tag.objects.get(name__iexact=tag) for tag in machine_request.new_machine_tags.split(',')] else: tags = [] #if machine_request.new_machine_forked: #NOTE: Swap these lines when application forking/versioning is supported in the UI if True: # This is a brand new app and a brand new providermachine new_app = create_application( new_image_id, new_provider.id, machine_request.new_machine_name, owner_ident, #new_app.Private = False when machine_request.is_public = True not machine_request.is_public(), machine_request.new_machine_version, machine_request.new_machine_description, tags) app_to_use = new_app description = machine_request.new_machine_description else: #This is NOT a fork, the application to be used is that of your # ancestor, and the app owner should not be changed. app_to_use = parent_app #Include your ancestors tags, description if necessary tags.extend(parent_app.tags.all()) if not machine_request.new_machine_description: description = parent_app.description else: description = machine_request.new_machine_description app.private = not machine_request.is_public() app.tags = tags app.description = description app.save() #Set application data to an existing/new providermachine try: new_machine = ProviderMachine.objects.get(identifier=new_image_id) new_machine.application = app_to_use new_machine.version = machine_request.new_machine_version new_machine.created_by = machine_request.new_machine_owner new_machine.created_by_identity = owner_ident new_machine.save() except ProviderMachine.DoesNotExist: new_machine = create_provider_machine( machine_request.new_machine_name, new_image_id, machine_request.new_machine_provider_id, app_to_use, {'version' : machine_request.new_machine_version}) #Be sure to write all this data to openstack metadata #So that it can continue to be the 'authoritative source' if not machine_request.is_public(): upload_privacy_data(machine_request, new_machine) save_app_data(new_machine.application) add_to_cache(new_machine) machine_request.new_machine = new_machine machine_request.end_date = timezone.now() machine_request.status = 'completed' machine_request.save() return machine_request