Esempio n. 1
0
def create_notification(resource_name, notif_type, notification, user):
    expires = datetime.datetime.utcnow() + datetime.timedelta(seconds=30)
    type = '%s.%s' % (resource_name, notif_type)
    ModelImporter.model('notification').createNotification(type=type,
                                                           data=notification,
                                                           user=user,
                                                           expires=expires)
Esempio n. 2
0
def update_profile(user, profile, params):
    body = getBodyJson()
    properties = [
        'accessKeyId', 'secretAccessKey', 'status', 'errorMessage',
        'publicIPs', 'cloudProvider'
    ]
    for prop in properties:
        if prop in body:
            profile[prop] = body[prop]

    ModelImporter.model('aws',
                        'cumulus').update_aws_profile(getCurrentUser(),
                                                      profile)
Esempio n. 3
0
def _get_group_id(group):
    group = ModelImporter.model('group').find({'name': group})

    if group.count() != 1:
        raise Exception('Unable to load group "%s"' % group)

    return group.next()['_id']
Esempio n. 4
0
def _get_group_id(group):
    group = ModelImporter.model('group').find({'name': group})

    if group.count() != 1:
        raise Exception('Unable to load group "%s"' % group)

    return group.next()['_id']
Esempio n. 5
0
def create_profile(user, params):
    body = getBodyJson()
    requireParams([
        'name', 'accessKeyId', 'secretAccessKey', 'regionName',
        'availabilityZone'
    ], body)

    profile_type = 'ec2' if 'cloudProvider' not in body.keys() \
                   else body['cloudProvider']

    model = ModelImporter.model('aws', 'cumulus')
    profile = model.create_profile(user['_id'], body['name'], profile_type,
                                   body['accessKeyId'],
                                   body['secretAccessKey'], body['regionName'],
                                   body['availabilityZone'],
                                   body.get('publicIPs', False))

    # Now fire of a task to create a key pair for this profile
    try:
        cumulus.aws.ec2.tasks.key.generate_key_pair.delay(
            _filter(profile),
            get_task_token()['_id'])

        cherrypy.response.status = 201
        cherrypy.response.headers['Location'] \
            = '/user/%s/aws/profile/%s' % (str(user['_id']),
                                           str(profile['_id']))

        return model.filter(profile, getCurrentUser())
    except Exception:
        # Remove profile if error occurs fire of task
        model.remove(profile)
        raise
Esempio n. 6
0
def move_files_to_assetstore(files, totalsize):
    user, token = getCurrentUser(True)
    assetstore = ModelImporter.model('assetstore').getCurrent()
    upload = ModelImporter.model('upload')
    with ProgressContext(True,
                         interval=1.0,
                         message=files[0]['name'],
                         user=user,
                         token=token,
                         total=totalsize,
                         title='Moving files') as ctx:
        for file in files:
            ctx.update(message=file['name'])
            upload.moveFileToAssetstore(file=file,
                                        user=user,
                                        assetstore=assetstore,
                                        progress=ctx)
Esempio n. 7
0
def _get_profile(profile_id):
    user = getCurrentUser()
    query = {'userId': user['_id']}
    try:
        query['_id'] = ObjectId(profile_id)
    except InvalidId:
        query['name'] = profile_id

    profile = ModelImporter.model('aws', 'cumulus').findOne(query)
    secret = profile['secretAccessKey']

    profile = ModelImporter.model('aws', 'cumulus').filter(profile, user)

    if profile is None:
        raise ValidationException('Profile must be specified!')

    profile['_id'] = str(profile['_id'])

    return profile, secret
Esempio n. 8
0
def _get_profile(profile_id):
    user = getCurrentUser()
    query = {'userId': user['_id']}
    try:
        query['_id'] = ObjectId(profile_id)
    except InvalidId:
        query['name'] = profile_id

    profile = ModelImporter.model('aws', 'cumulus').findOne(query)
    secret = profile['secretAccessKey']

    profile = ModelImporter.model('aws', 'cumulus').filter(profile, user)

    if profile is None:
        raise ValidationException('Profile must be specified!')

    profile['_id'] = str(profile['_id'])

    return profile, secret
Esempio n. 9
0
def get_profiles(user, params):
    user = getCurrentUser()
    model = ModelImporter.model('aws', 'cumulus')
    limit = params.get('limit', 50)
    profiles = model.find_profiles(user['_id'])

    profiles = model.filterResultsByPermission(profiles,
                                               user,
                                               AccessType.READ,
                                               limit=int(limit))

    return [model.filter(profile, user) for profile in profiles]
Esempio n. 10
0
def get_task_token(cluster=None):
    """
    Gets a Girder token to use to access Girder while running a task. By default
    we create a token using the cumulus girder user ( this user has certain
    privileges, such as access to passphrases that a regular user doesn't have).
    However, in the case of a NEWT cluster we need the token to be associated
    with the logged in user as this is used to look up the NEWT session ID.
    """
    if cluster and cluster['type'] == ClusterType.NEWT:
        user = getCurrentUser()
    else:
        user = ModelImporter.model('user') \
            .find({'login': cumulus.config.girder.user})

        if user.count() != 1:
            raise Exception('Unable to load user "%s"' %
                            cumulus.config.girder.user)

        user = user.next()

    return ModelImporter.model('token').createToken(user=user, days=7)
Esempio n. 11
0
def get_task_token(cluster=None):
    """
    Gets a Girder token to use to access Girder while running a task. By default
    we create a token using the cumulus girder user ( this user has certain
    privileges, such as access to passphrases that a regular user doesn't have).
    However, in the case of a NEWT cluster we need the token to be associated
    with the logged in user as this is used to look up the NEWT session ID.
    """
    if cluster and cluster['type'] == ClusterType.NEWT:
        user = getCurrentUser()
    else:
        user = ModelImporter.model('user') \
            .find({'login': cumulus.config.girder.user})

        if user.count() != 1:
            raise Exception('Unable to load user "%s"' %
                            cumulus.config.girder.user)

        user = user.next()

    return ModelImporter.model('token').createToken(user=user, days=7)
Esempio n. 12
0
def delete_profile(user, profile, params):

    query = {'profileId': profile['_id']}

    if ModelImporter.model('volume', 'cumulus').findOne(query):
        raise RestException(
            'Unable to delete profile as it is associated with'
            ' a volume', 400)

    if ModelImporter.model('cluster', 'cumulus').findOne(query):
        raise RestException(
            'Unable to delete profile as it is associated with'
            ' a cluster', 400)

    # Clean up key associate with profile
    cumulus.aws.ec2.tasks.key.delete_key_pair.delay(_filter(profile),
                                                    get_task_token()['_id'])

    client = get_ec2_client(profile)
    client.delete_key_pair(KeyName=str(profile['_id']))

    ModelImporter.model('aws', 'cumulus').remove(profile)
Esempio n. 13
0
    def __init__(self, profile):
        super(EC2Provider, self).__init__(profile)

        if not hasattr(self, 'secretAccessKey'):
            try:
                profile = ModelImporter.model('aws', 'cumulus').load(
                    self.girder_profile_id)

                self.secretAccessKey = profile.get('secreteAccessKey', None)
            # Cumulus plugin libraries are not available
            except ImportError:
                self.secretAccessKey = None

        self._volume_cache = {}
Esempio n. 14
0
    def __init__(self, profile):

        self.girder_profile_id = profile.get('_id', None)

        for key, value in profile.items():
            setattr(self, key, value)

        if not hasattr(self, 'secretAccessKey'):
            try:
                profile = ModelImporter.model('aws', 'cumulus').load(
                    self.girder_profile_id)

                self.secretAccessKey = profile.get('secreteAccessKey', None)
            # Cumulus plugin libraries are not available
            except ImportError:
                self.secretAccessKey = None

        self._volume_cache = {}
Esempio n. 15
0
    def __init__(self, profile):

        self.girder_profile_id = profile.get('_id', None)

        for key, value in profile.items():
            setattr(self, key, value)

        if not hasattr(self, 'secretAccessKey'):
            try:
                profile = ModelImporter.model('aws', 'cumulus').load(
                    self.girder_profile_id)

                self.secretAccessKey = profile.get('secreteAccessKey', None)
            # Cumulus plugin libraries are not available
            except ImportError:
                self.secretAccessKey = None

        self._volume_cache = {}
Esempio n. 16
0
def create_notification(resource_name, notif_type, notification, user):
    expires = datetime.datetime.utcnow() + datetime.timedelta(seconds=30)
    type = '%s.%s' % (resource_name, notif_type)
    ModelImporter.model('notification').createNotification(
        type=type, data=notification, user=user, expires=expires)
Esempio n. 17
0
 def load_file(file):
     return ModelImporter.model('file').load(file['_id'],
                                             user=getCurrentUser())