def convert_instance_source(esh_driver, esh_instance, esh_source, provider_uuid, identity_uuid, user): """ Given the instance source, create the appropriate core REPR and return """ from rtwo.models.volume import BaseVolume from rtwo.models.machine import BaseMachine # TODO: Future Release.. new_source = None if isinstance(esh_source, BaseVolume): core_source = convert_esh_volume(esh_source, provider_uuid, identity_uuid, user) elif isinstance(esh_source, BaseMachine): if isinstance(esh_source, MockMachine): # MockMachine includes only the Alias/ID information # so a lookup on the machine is required to get accurate # information. new_source = esh_driver.get_machine(esh_source.id) if not new_source: core_source = get_or_create_provider_machine( esh_source.id, "Inactive Machine for Instance %s" % esh_instance.id, provider_uuid) else: core_source = convert_esh_machine(esh_driver, new_source, provider_uuid, user) elif not isinstance(esh_source, BaseMachine): raise Exception("Encountered unknown source %s" % esh_source) return core_source
def convert_instance_source( esh_driver, esh_instance, esh_source, provider_uuid, identity_uuid, user ): """ Given the instance source, create the appropriate core REPR and return """ from rtwo.models.volume import BaseVolume from rtwo.models.machine import BaseMachine # TODO: Future Release.. new_source = None if isinstance(esh_source, BaseVolume): core_source = convert_esh_volume( esh_source, provider_uuid, identity_uuid, user ) elif isinstance(esh_source, BaseMachine): if isinstance(esh_source, MockMachine): # MockMachine includes only the Alias/ID information # so a lookup on the machine is required to get accurate # information. new_source = esh_driver.get_machine(esh_source.id) if not new_source: core_source = get_or_create_provider_machine( esh_source.id, "Inactive Machine for Instance %s" % esh_instance.id, provider_uuid ) else: core_source = convert_esh_machine( esh_driver, new_source, provider_uuid, user ) elif not isinstance(esh_source, BaseMachine): raise Exception("Encountered unknown source %s" % esh_source) return core_source
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 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 db_machine = get_or_create_provider_machine( cloud_machine.id, cloud_machine.name, provider.uuid) db_version = db_machine.application_version db_application = db_version.application if cloud_machine.is_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