Exemplo n.º 1
0
 def save_model(self, request, obj, form, change):
     user = request.user
     application = form.save(commit=False)
     application.save()
     form.save_m2m()
     if change:
         save_app_data(application)
     return application
Exemplo n.º 2
0
 def save_model(self, request, obj, form, change):
     user = request.user
     application = form.save(commit=False)
     application.save()
     form.save_m2m()
     if change:
         try:
             save_app_data(application)
         except Exception, e:
             logger.exception("Could not update metadata for application %s"
                              % application)
Exemplo n.º 3
0
 def save_model(self, request, obj, form, change):
     user = request.user
     application = form.save(commit=False)
     application.save()
     form.save_m2m()
     if change:
         try:
             save_app_data(application)
         except Exception, e:
             logger.exception(
                 "Could not update metadata for application %s" %
                 application)
Exemplo n.º 4
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
    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
Exemplo n.º 5
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
    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