예제 #1
0
def create_application(identifier, provider_id, name=None,
        owner=None, private=False, version=None, description=None, tags=None,
        uuid=None):
    from core.models import AtmosphereUser
    if not uuid:
        uuid = uuid5(settings.ATMOSPHERE_NAMESPACE_UUID, str(identifier))
        uuid = str(uuid)
    exists = Application.objects.filter(uuid=uuid)
    if exists:
        return exists[0]
    if not name:
        name = "UnknownApp %s" % identifier
    if not description:
        description = "New application - %s" % name
    if not owner:
        owner = _get_admin_owner(provider_id)
    if not tags:
        tags = []
    new_app = Application.objects.create(
            name=name,
            description=description,
            created_by=owner.created_by,
            created_by_identity=owner,
            uuid=uuid)
    if tags:
        updateTags(new_app, tags, owner.created_by)
    return new_app
예제 #2
0
def create_application(
        provider_uuid,
        identifier,
        name=None,
        created_by_identity=None,
        created_by=None,
        description=None,
        private=False,
        tags=None,
        uuid=None):
    """
    Create application & Initial ApplicationVersion.
    Build information (Based on MachineRequest or API inputs..)
    and RETURN Application!!
    """
    new_app = None

    if not uuid:
        uuid = _generate_app_uuid(identifier)

    existing_app = Application.objects.filter(uuid=uuid)
    if existing_app.count():
        new_app = existing_app[0]

    if not name:
        name = "Imported App: %s" % identifier
    if not description:
        description = "Imported Application - %s" % name
    if created_by:
        created_by_identity = _username_lookup(
            provider_uuid,
            created_by.username)
    if not created_by_identity:
        created_by_identity = _get_admin_owner(provider_uuid)
    if not tags:
        tags = []
    if new_app:
        new_app.name = name
        new_app.description = description
        new_app.created_by = created_by_identity.created_by
        new_app.created_by_identity = created_by_identity
        new_app.private = private
        new_app.save()
    else:
        new_app = Application.objects.create(
            name=name,
            description=description,
            created_by=created_by_identity.created_by,
            created_by_identity=created_by_identity,
            private=private,
            uuid=uuid)
    if tags:
        updateTags(new_app, tags, created_by_identity.created_by)
    return new_app
예제 #3
0
def create_application(
        provider_uuid,
        identifier,
        name=None,
        created_by_identity=None,
        created_by=None,
        description=None,
        private=False,
        tags=None,
        uuid=None):
    """
    Create application & Initial ApplicationVersion.
    Build information (Based on MachineRequest or API inputs..)
    and RETURN Application!!
    """
    new_app = None

    if not uuid:
        uuid = _generate_app_uuid(identifier)

    existing_app = Application.objects.filter(uuid=uuid)
    if existing_app.count():
        new_app = existing_app[0]

    if not name:
        name = "Imported App: %s" % identifier
    if not description:
        description = "Imported Application - %s" % name
    if created_by:
        created_by_identity = _username_lookup(
            provider_uuid,
            created_by.username)
    if not created_by_identity:
        created_by_identity = _get_admin_owner(provider_uuid)
    if not tags:
        tags = []
    if new_app:
        new_app.name = name
        new_app.description = description
        new_app.created_by = created_by_identity.created_by
        new_app.created_by_identity = created_by_identity
        new_app.private = private
        new_app.save()
    else:
        new_app = Application.objects.create(
            name=name,
            description=description,
            created_by=created_by_identity.created_by,
            created_by_identity=created_by_identity,
            private=private,
            uuid=uuid)
    if tags:
        updateTags(new_app, tags, created_by_identity.created_by)
    return new_app
예제 #4
0
def create_application(provider_uuid,
                       identifier,
                       name=None,
                       created_by_identity=None,
                       created_by=None,
                       description=None,
                       private=False,
                       tags=None,
                       uuid=None):
    from core.models import AtmosphereUser
    new_app = None

    if not uuid:
        uuid = _generate_app_uuid(identifier)

    existing_app = Application.objects.filter(uuid=uuid)
    if existing_app.count():
        new_app = existing_app[0]

    if not name:
        name = "Imported App: %s" % identifier
    if not description:
        description = "Imported Application - %s" % name
    if created_by:
        created_by_identity = _username_lookup(provider_uuid,
                                               created_by.username)
    if not created_by_identity:
        created_by_identity = _get_admin_owner(provider_uuid)
    if not tags:
        tags = []
    if new_app:
        new_app.name = name
        new_app.description = description
        new_app.created_by = owner.created_by
        new_app.created_by_identity = owner
        new_app.private = private
        new_app.save()
    else:
        new_app = Application.objects.create(
            name=name,
            description=description,
            created_by=created_by_identity.created_by,
            created_by_identity=created_by_identity,
            private=private,
            uuid=uuid)
    if tags:
        updateTags(new_app, tags, created_by_identity.created_by)
    return new_app
예제 #5
0
 def update(self, *args, **kwargs):
     """
     Allows for partial updating of the model
     """
     # Upload args into kwargs
     for arg in args:
         for (key, value) in arg.items():
             kwargs[key] = value
     # Update the values
     for key in kwargs.keys():
         if key == 'tags':
             if not isinstance(kwargs[key], list):
                 tags_list = kwargs[key].split(",")
             else:
                 tags_list = kwargs[key]
             updateTags(self, tags_list)
             continue
         setattr(self, key, kwargs[key])
     self.save()
     return self
예제 #6
0
 def update(self, *args, **kwargs):
     """
     Allows for partial updating of the model
     """
     # Upload args into kwargs
     for arg in args:
         for (key, value) in arg.items():
             kwargs[key] = value
     # Update the values
     for key in kwargs.keys():
         if key == 'tags':
             if not isinstance(kwargs[key], list):
                 tags_list = kwargs[key].split(",")
             else:
                 tags_list = kwargs[key]
             updateTags(self, tags_list)
             continue
         setattr(self, key, kwargs[key])
     self.save()
     return self
예제 #7
0
def create_application(provider_uuid, identifier, name=None,
                       created_by_identity=None, created_by=None, description=None, private=False, tags=None, uuid=None):
    from core.models import AtmosphereUser
    new_app = None

    if not uuid:
        uuid = _generate_app_uuid(identifier)

    existing_app = Application.objects.filter(uuid=uuid)
    if existing_app.count():
        new_app = existing_app[0]

    if not name:
        name = "Imported App: %s" % identifier
    if not description:
        description = "Imported Application - %s" % name
    if created_by:
        created_by_identity = _username_lookup(provider_uuid, created_by.username)
    if not created_by_identity:
        created_by_identity = _get_admin_owner(provider_uuid)
    if not tags:
        tags = []
    if new_app:
        new_app.name = name
        new_app.description = description
        new_app.created_by = owner.created_by
        new_app.created_by_identity = owner
        new_app.private = private
        new_app.save()
    else:
        new_app = Application.objects.create(name=name,
                                         description=description,
                                         created_by=created_by_identity.created_by,
                                         created_by_identity=created_by_identity,
                                         private=private,
                                         uuid=uuid)
    if tags:
        updateTags(new_app, tags, created_by_identity.created_by)
    return new_app
예제 #8
0
def create_application(
        provider_uuid,
        identifier,
        name=None,
        created_by_identity=None,
        created_by=None,
        description=None,
        private=False,
        tags=None,
        uuid=None):
    """
    Create application & Initial ApplicationVersion.
    Build information (Based on MachineRequest or API inputs..)
    and RETURN Application!!
    """
    new_app = None

    if not uuid:
        uuid = _generate_app_uuid(identifier)

    existing_app = Application.objects.filter(uuid=uuid)
    if existing_app.count():
        new_app = existing_app[0]

    if not name:
        name = "Imported App: %s" % identifier
    if not description:
        description = "Imported Application - %s" % name
    if created_by:
        created_by_identity = _username_lookup(
            provider_uuid,
            created_by.username)
    if not created_by_identity:
        logger.error("ERROR: No identity was found for image <%s> -- the 'author' will be admin" % identifier)
        created_by_identity = _get_admin_owner(provider_uuid)
    if not tags:
        tags = []
    elif isinstance(tags, basestring):
        if "[" in tags:
            #Format expected -- ["CentOS", "development", "test1"]
            tags = json.loads(tags)
        elif "," in tags:
            #Format expected -- CentOS, development, test1,test2,test3
            tags = [t.strip() for t in tags.split(',')]
        else:
            tags = [tags]
    if new_app:
        new_app.name = name
        new_app.description = description
        new_app.created_by = created_by_identity.created_by
        new_app.created_by_identity = created_by_identity
        new_app.private = private
        new_app.save()
    else:
        new_app = Application.objects.create(
            name=name,
            description=description,
            created_by=created_by_identity.created_by,
            created_by_identity=created_by_identity,
            private=private,
            uuid=uuid)
    if tags:
        updateTags(new_app, tags, created_by_identity.created_by)
    return new_app
예제 #9
0
def create_application(provider_uuid,
                       identifier,
                       name=None,
                       created_by_identity=None,
                       created_by=None,
                       description=None,
                       private=False,
                       tags=None,
                       access_list=None,
                       uuid=None):
    """
    Create application & Initial ApplicationVersion.
    Build information (Based on MachineRequest or API inputs..)
    and RETURN Application!!
    """
    application = None

    if not uuid:
        uuid = _generate_app_uuid(identifier)

    uuid_match = Application.objects.filter(uuid=uuid).first()
    if uuid_match:
        application = uuid_match

    provider = Provider.objects.get(uuid=provider_uuid)
    if not name:
        name = "Imported App: %s" % identifier
    if not description:
        description = "Imported Application - %s" % name
    if not created_by_identity and uuid_match:
        #Use existing authorship on UUID matches.
        # This will avoid bounceback on replica-machines
        return uuid_match.created_by_identity
    elif not created_by_identity:
        created_by_identity = _get_owner_identity(provider, created_by)

    if not tags:
        tags = []
    elif isinstance(tags, basestring):
        if "[" in tags:
            #Format expected -- ["CentOS", "development", "test1"]
            tags = json.loads(tags)
        elif "," in tags:
            #Format expected -- CentOS, development, test1,test2,test3
            tags = [t.strip() for t in tags.split(',')]
        else:
            tags = [tags]
    if application:
        application.name = name
        application.description = description
        application.created_by_identity = created_by_identity
        application.created_by = created_by_identity.created_by
        application.private = private
        application.save()
    else:
        application = Application.objects.create(
            name=name,
            description=description,
            created_by=created_by_identity.created_by,
            created_by_identity=created_by_identity,
            private=private,
            uuid=uuid)
    if tags:
        updateTags(application, tags, created_by_identity.created_by)
    if access_list:
        for pattern_match in access_list:
            application.access_list.add(pattern_match)
    return application
def create_application(
    provider_uuid,
    identifier,
    name=None,
    created_by_identity=None,
    created_by=None,
    description=None,
    private=False,
    tags=None,
    access_list=None,
    uuid=None
):
    """
    Create application & Initial ApplicationVersion.
    Build information (Based on MachineRequest or API inputs..)
    and RETURN Application!!
    """
    application = None

    if not uuid:
        uuid = _generate_app_uuid(identifier)

    uuid_match = Application.objects.filter(uuid=uuid).first()
    if uuid_match:
        application = uuid_match

    provider = Provider.objects.get(uuid=provider_uuid)
    if not name:
        name = "Imported App: %s" % identifier
    if not description:
        description = "Imported Application - %s" % name
    if not created_by_identity and uuid_match:
        #Use existing authorship on UUID matches.
        # This will avoid bounceback on replica-machines
        return uuid_match.created_by_identity
    elif not created_by_identity:
        created_by_identity = _get_owner_identity(provider, created_by)

    if not tags:
        tags = []
    elif isinstance(tags, basestring):
        if "[" in tags:
            #Format expected -- ["CentOS", "development", "test1"]
            tags = json.loads(tags)
        elif "," in tags:
            #Format expected -- CentOS, development, test1,test2,test3
            tags = [t.strip() for t in tags.split(',')]
        else:
            tags = [tags]
    if application:
        application.name = name
        application.description = description
        application.created_by_identity = created_by_identity
        application.created_by = created_by_identity.created_by
        application.private = private
        application.save()
    else:
        application = Application.objects.create(
            name=name,
            description=description,
            created_by=created_by_identity.created_by,
            created_by_identity=created_by_identity,
            private=private,
            uuid=uuid
        )
    if tags:
        updateTags(application, tags, created_by_identity.created_by)
    if access_list:
        for pattern_match in access_list:
            application.access_list.add(pattern_match)
    return application