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 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, 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