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 get_public_and_private_apps(provider): """ INPUT: Provider provider OUTPUT: 2-tuple ( new_public_apps [], private_apps(key) + super-set-membership(value) {}) """ account_driver = get_account_driver(provider) all_projects_map = tenant_id_to_name_map(account_driver) cloud_machines = account_driver.list_all_images() db_machines = ProviderMachine.objects.filter( only_current_source(), instance_source__provider=provider) new_public_apps = [] private_apps = {} # ASSERT: All non-end-dated machines in the DB can be found in the cloud # if you do not believe this is the case, you should call 'prune_machines_for' for cloud_machine in cloud_machines: #Filter out: ChromoSnapShot, eri-, eki-, ... (Or dont..) if any( cloud_machine.name.startswith(prefix) for prefix in ['eri-', 'eki-', 'ChromoSnapShot']): #celery_logger.debug("Skipping cloud machine %s" % cloud_machine) continue app_name, version_name = ProviderMachine._split_cloud_name( cloud_machine.name) db_machine = get_or_create_provider_machine(cloud_machine.id, app_name, provider.uuid, version_name=version_name) db_version = db_machine.application_version db_application = db_version.application if cloud_machine.get('visibility') == 'public': if db_application.private and db_application not in new_public_apps: new_public_apps.append(db_application) #Distinct list.. #Else the db app is public and no changes are necessary. else: # cloud machine is private membership = get_shared_identities(account_driver, cloud_machine, all_projects_map) all_members = private_apps.get(db_application, []) all_members.extend(membership) #Distinct list.. private_apps[db_application] = all_members return new_public_apps, private_apps
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