Example #1
0
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!
    """
    from core.models.machine import add_to_cache
    from core.application import update_owner
    from core.models.tag import Tag
    #Get all the data you can from the machine request
    #TODO: This could select multiple, we should probably have a more
    #TODO: restrictive query here..
    parent_mach = machine_request.instance.provider_machine
    parent_app = machine_request.instance.provider_machine.application
    if machine_request.new_machine_tags:
        tags = [Tag.objects.filter(name__iexact=tag)[0] for tag in
                machine_request.new_machine_tags.split(',')]
    else:
        tags = []

    #NOTE: Swap these lines when application forking/versioning is supported in the UI
    if machine_request.new_machine_forked:
        app_to_use = _create_new_application(machine_request, new_image_id, tags)
    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 = _update_application(machine_request, new_image_id, tags)
    #TODO: CANT 'update' an application if you used a bootable volume.. (for now)
    new_machine = _create_new_provider_machine(machine_request, app_to_use, new_image_id)
    machine_request.new_machine = new_machine

    if machine_request.has_threshold():
        machine_request.update_threshold()
    #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)

    #TODO: Lookup tenant name when we move away from
    # the usergroup model
    user = machine_request.new_machine_owner
    tenant_name = user.username
    update_owner(new_machine, tenant_name, update_cloud)

    if update_cloud:
        save_app_to_metadata(new_machine.application)
        add_to_cache(new_machine)

    machine_request.end_date = timezone.now()

    #After processing, validate the image.
    machine_request.status = 'validating'
    machine_request.save()
    return machine_request
Example #2
0
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):
    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