def convert_glance_image( account_driver, glance_image, provider_uuid, owner=None ): """ Guaranteed Return of ProviderMachine. 1. Load provider machine from DB and return 2a. If 'Miss': * Lookup application based on glance_machine metadata for application_uuid If 'Miss': * Create application based on available glance_machine metadata 2b. Using application from 2. Create provider machine """ if hasattr(glance_image, 'id'): image_id = glance_image.id elif type(glance_image) == dict: image_id = glance_image.get('id') else: raise ValueError("Unexpected glance_image: %s" % glance_image) provider_machine = get_provider_machine(image_id, provider_uuid) if provider_machine: if provider_machine.is_end_dated(): return (None, False) update_instance_source_size( provider_machine.instance_source, glance_image.get('size') ) return (provider_machine, False) (app_kwargs, version_kwargs ) = _application_and_version_from_metadata(account_driver, glance_image) # TODO: use version_kwargs in method below? version = get_version_for_machine(provider_uuid, image_id, fuzzy=True) if version: app = version.application else: app = create_application(**app_kwargs) version = create_app_version(app=app, **version_kwargs) #TODO: fuzzy=True returns a list, but call comes through as a .get()? # this line will cover that edge-case. if type(version) in [models.QuerySet, list]: version = version[0] machine_kwargs = { 'created_by_identity': version_kwargs.get('created_by_identity'), 'version': version } provider_machine = create_provider_machine( image_id, provider_uuid, app, **machine_kwargs ) update_instance_source_size( provider_machine.instance_source, glance_image.get('size') ) return (provider_machine, True)
def convert_glance_image(glance_image, provider_uuid, owner=None): """ Guaranteed Return of ProviderMachine. 1. Load provider machine from DB and return 2a. If 'Miss': * Lookup application based on glance_machine metadata for application_uuid If 'Miss': * Create application based on available glance_machine metadata 2b. Using application from 2. Create provider machine """ from core.models import AtmosphereUser image_id = glance_image.id machine_name = glance_image.name application_name = machine_name # Future: application_name will partition at the 'Application Version separator'.. and pass the version_name to create_version provider_machine = get_provider_machine(image_id, provider_uuid) if provider_machine: update_instance_source_size(provider_machine.instance_source, glance_image.get('size')) return (provider_machine, False) app_kwargs = collect_image_metadata(glance_image) if owner and hasattr(owner, 'name'): owner_name = owner.name else: owner_name = glance_image.get('application_owner') user = AtmosphereUser.objects.filter(username=owner_name).first() if user: identity = Identity.objects.filter(provider__uuid=provider_uuid, created_by=user).first() else: identity = None app_kwargs.update({'created_by': user, 'created_by_identity': identity}) app = create_application(provider_uuid, image_id, application_name, **app_kwargs) version = get_version_for_machine(provider_uuid, image_id, fuzzy=True) if not version: version_kwargs = { 'version_str': glance_image.get('application_version', '1.0'), 'created_by': user, 'created_by_identity': identity, 'provider_machine_id': image_id } version = create_app_version(app, **version_kwargs) #TODO: fuzzy=True returns a list, but call comes through as a .get()? # this line will cover that edge-case. if type(version) in [models.QuerySet, list]: version = version[0] machine_kwargs = {'created_by_identity': identity, 'version': version} provider_machine = create_provider_machine(image_id, provider_uuid, app, **machine_kwargs) update_instance_source_size(provider_machine.instance_source, glance_image.get('size')) return (provider_machine, True)
def convert_glance_image(account_driver, glance_image, provider_uuid, owner=None): """ Guaranteed Return of ProviderMachine. 1. Load provider machine from DB and return 2a. If 'Miss': * Lookup application based on glance_machine metadata for application_uuid If 'Miss': * Create application based on available glance_machine metadata 2b. Using application from 2. Create provider machine """ if hasattr(glance_image, 'id'): image_id = glance_image.id elif type(glance_image) == dict: image_id = glance_image.get('id') else: raise ValueError("Unexpected glance_image: %s" % glance_image) provider_machine = get_provider_machine(image_id, provider_uuid) if provider_machine: if provider_machine.is_end_dated(): return (None, False) update_instance_source_size(provider_machine.instance_source, glance_image.get('size')) return (provider_machine, False) (app_kwargs, version_kwargs) = _application_and_version_from_metadata( account_driver, glance_image) # TODO: use version_kwargs in method below? version = get_version_for_machine(provider_uuid, image_id, fuzzy=True) if version: app = version.application else: app = create_application(**app_kwargs) version = create_app_version(app=app, **version_kwargs) #TODO: fuzzy=True returns a list, but call comes through as a .get()? # this line will cover that edge-case. if type(version) in [models.QuerySet, list]: version = version[0] machine_kwargs = { 'created_by_identity': version_kwargs.get('created_by_identity'), 'version': version } provider_machine = create_provider_machine(image_id, provider_uuid, app, **machine_kwargs) update_instance_source_size(provider_machine.instance_source, glance_image.get('size')) return (provider_machine, True)
def _load_machine(esh_machine, provider_uuid): name = esh_machine.name alias = esh_machine.id app = get_application(provider_uuid, alias, name) if not app: logger.debug("Creating Application for Image %s" % (alias, )) app = create_application(provider_uuid, alias, name) # Using what we know about our (possibly new) application # and load (or possibly create) the provider machine provider_machine = get_or_create_provider_machine( alias, name, provider_uuid, app=app) lc_machine = esh_machine._image image_size = lc_machine.extra.get('image_size') update_instance_source_size(provider_machine.instance_source, image_size) return provider_machine
def _load_machine(esh_machine, provider_uuid): name = esh_machine.name alias = esh_machine.id app = get_application(provider_uuid, alias, name) if not app: logger.debug("Creating Application for Image %s" % (alias, )) app = create_application(provider_uuid, alias, name) # Using what we know about our (possibly new) application # and load (or possibly create) the provider machine provider_machine = get_or_create_provider_machine( alias, name, provider_uuid, app=app) lc_machine = esh_machine._image image_size = lc_machine.extra.get('image_size') update_instance_source_size(provider_machine.instance_source, image_size) return provider_machine