Beispiel #1
0
    def delete(self, group_id=None):
        # lookup user's auth info
        user_info = User.get_by_id(long(self.user_id))

        # find the the entry
        group = Group.get_by_id(long(group_id))

        # this member's membership
        membership = GroupMembers.get_by_userid_groupid(
            user_info.key, group.key)

        # list of users that have the group enabled
        members = GroupMembers.get_group_users(group.key)

        # remove this user's membership
        membership.key.delete()

        # if this user is not the group owner, we simply notify we are done
        if not group or group.owner != user_info.key:
            # use the channel to tell the browser we are done and reload
            self.add_message('Group was removed from account.', 'success')
            channel_token = self.request.get('channel_token')
            channel.send_message(channel_token, 'reload')
            return

        # was there more than just this member?
        if len(members) > 1:
            # find the next user by date and assign them as owner
            entry = GroupMembers.get_new_owner(user_info.key, group.key)
            print "new owner is %s" % entry.member
            new_owner = entry.member
            group.owner = new_owner
            group.put()

            # find member's appliances that match this group and remove
            appliances = Appliance.get_by_user_group(user_info.key, group.key)
            for appliance in appliances:
                appliance.group = None  # public group
                appliance.put()

        else:
            # no more members, so delete the group
            group.key.delete()
            self.add_message('Group successfully deleted!', 'success')

            # remove group from any and all appliances (heavy handed)
            appliances = Appliance.get_by_group(group.key)
            for appliance in appliances:
                appliance.group = None  # public group
                appliance.put()

        # hangout for a second
        time.sleep(1)

        # use the channel to tell the browser we are done and reload
        channel_token = self.request.get('channel_token')
        channel.send_message(channel_token, 'reload')
        return
Beispiel #2
0
	def delete(self, group_id = None):
		# lookup user's auth info
		user_info = User.get_by_id(long(self.user_id))

		# find the the entry
		group = Group.get_by_id(long(group_id))

		# this member's membership
		membership = GroupMembers.get_by_userid_groupid(user_info.key, group.key)

		# list of users that have the group enabled
		members = GroupMembers.get_group_users(group.key)

		# remove this user's membership
		membership.key.delete()
		
		# if this user is not the group owner, we simply notify we are done
		if not group or group.owner != user_info.key:
			# use the channel to tell the browser we are done and reload
			self.add_message('Group was removed from account.', 'success')
			channel_token = self.request.get('channel_token')
			channel.send_message(channel_token, 'reload')
			return

		# was there more than just this member?
		if len(members) > 1:
			# find the next user by date and assign them as owner
			entry = GroupMembers.get_new_owner(user_info.key, group.key)
			print "new owner is %s" % entry.member
			new_owner = entry.member
			group.owner = new_owner
			group.put()
		
			# find member's appliances that match this group and remove
			appliances = Appliance.get_by_user_group(user_info.key, group.key)
			for appliance in appliances:
				appliance.group = None # public group
				appliance.put()
		
		else:
			# no more members, so delete the group
			group.key.delete()
			self.add_message('Group successfully deleted!', 'success')

			# remove group from any and all appliances (heavy handed)
			appliances = Appliance.get_by_group(group.key)
			for appliance in appliances:
				appliance.group = None # public group
				appliance.put()

		# hangout for a second
		time.sleep(1)

		# use the channel to tell the browser we are done and reload
		channel_token = self.request.get('channel_token')
		channel.send_message(channel_token, 'reload')
		return
Beispiel #3
0
	def post(self):
		# lookup user's auth info
		user_info = User.get_by_id(long(self.user_id))

		# load form values
		name = self.form.name.data.strip()
		description = self.form.description.data.strip()

		# check if we have it already
		if Group.get_by_name(name):
			self.add_message("A group with that name already exists!", "error")
			return self.redirect_to('account-groups')

		# check what was returned from form validates
		if not self.form.validate():          
			self.add_message("The new group form did not validate.", "error")
			return self.get()

		# create the group
		group = Group(
			name = name,
			description = description,
			owner = user_info.key,
		)
		group.put()

		# create the group member entry
		groupmember = GroupMembers(
			group = group.key,
			member = user_info.key,
			invitor = user_info.key, # same same
			active = True
		)
		groupmember.put()
		
		# log to alert
		self.add_message("Group %s successfully created!" % name, "success")

		# give it a few seconds to update db, then redirect
		time.sleep(1)
		return self.redirect_to('account-groups-configure', group_id = group.key.id())
Beispiel #4
0
    def post(self):
        # lookup user's auth info
        user_info = User.get_by_id(long(self.user_id))

        # load form values
        name = self.form.name.data.strip()
        description = self.form.description.data.strip()

        # check if we have it already
        if Group.get_by_name(name):
            self.add_message("A group with that name already exists!", "error")
            return self.redirect_to('account-groups')

        # check what was returned from form validates
        if not self.form.validate():
            self.add_message("The new group form did not validate.", "error")
            return self.get()

        # create the group
        group = Group(
            name=name,
            description=description,
            owner=user_info.key,
        )
        group.put()

        # create the group member entry
        groupmember = GroupMembers(
            group=group.key,
            member=user_info.key,
            invitor=user_info.key,  # same same
            active=True)
        groupmember.put()

        # log to alert
        self.add_message("Group %s successfully created!" % name, "success")

        # give it a few seconds to update db, then redirect
        time.sleep(1)
        return self.redirect_to('account-groups-configure',
                                group_id=group.key.id())
Beispiel #5
0
    def post(self):
        to = self.request.get("to")
        group_id = self.request.get("group_id")
        invitor_id = self.request.get("invitor_id")
        invite_url = self.request.get("invite_url")

        # admin of the pool
        sender = config.contact_sender

        # test to see if the sender_id and group number is real
        invitor = User.get_by_id(long(invitor_id))
        group = Group.get_by_id(long(group_id))

        # if we found the sending user and group
        if invitor and group:
            # rest of the email stuff
            subject = "You've Been Invited to the %s Group on %s" % (
                group.name, config.app_name)
            body = """
Howdy!

You've been invited to the %s group on the %s Compute Pool by %s.  Acceptance of the group invite will require linking the site to your Google account.

%s

This invite will allow you to start instances which are managed exclusively by appliances in the %s group.  Your membership also allows you to add your own OpenStack cluster and appliance to the group.  This is a very good thing for all involved.

If this email comes as a complete surprise to you, simply delete it.  We may yet meet again.

Cheers,

%s
%s
		""" % (group.name, config.app_name, invitor.username, invite_url, group.name,
            config.app_owner, config.app_name)

            logEmail = LogEmail(sender=sender,
                                to=to,
                                subject=subject,
                                body=body,
                                when=utils.get_date_time("datetimeProperty"))
            logEmail.put()

            try:
                mail.send_mail(sender, to, subject, body)
            except Exception as ex:
                logging.error(
                    "Failed attempt to send invite email because %s." % ex)
        else:
            # doing nothing, you fuckers
            logging.error("Failed attempt to send invite email.")
Beispiel #6
0
    def post(self, group_id=None):
        # lookup user's auth info
        user_info = User.get_by_id(long(self.user_id))

        # get the group in question
        group = Group.get_by_id(long(group_id))

        # bail if group doesn't exist user isn't the owner/admin
        if not group or group.owner != user_info.key:
            return self.redirect_to('account-groups')

        # check what was returned from form validates
        if not self.form.validate():
            self.add_message("The %s group was not updated." % group.name,
                             "info")
            return self.redirect_to('account-groups')

        # load form values
        name = self.form.name.data.strip()
        description = self.form.description.data.strip()

        # check if we have a group named that already
        if Group.get_by_name(name):
            self.add_message("A group with that name already exists!", "error")
            return self.redirect_to('account-groups')

        # save the new group
        group.name = name
        group.description = description
        group.put()

        # log to alert
        self.add_message("Group %s updated!" % name, "success")

        # give it a few seconds to update db, then redirect
        time.sleep(1)

        return self.redirect_to('account-groups')
Beispiel #7
0
	def post(self):
		to = self.request.get("to")
		group_id = self.request.get("group_id")
		invitor_id = self.request.get("invitor_id")
		invite_url = self.request.get("invite_url")

		# admin of the pool
		sender = config.contact_sender

		# test to see if the sender_id and group number is real
		invitor = User.get_by_id(long(invitor_id))
		group = Group.get_by_id(long(group_id))

		# if we found the sending user and group
		if invitor and group:
			# rest of the email stuff
			subject = "You've Been Invited to the %s Group on %s" % (group.name, config.app_name)
			body = """
Howdy!

You've been invited to the %s group on %s by %s.  Acceptance of the group invite will require linking the site to your Google account.

%s

This invite will allow you to start instances which are managed exclusively by appliances in the %s group.  Your membership also allows you to add your own OpenStack cluster and appliance to the group.  This is a very good thing for all involved.

If this email comes as a complete surprise to you, simply delete it.  We may yet meet again.

Cheers,

%s
%s
		""" % (group.name, config.app_name, invitor.username, invite_url, group.name, config.app_owner, config.app_name)

			logEmail = LogEmail(
				sender = sender,
				to = to,
				subject = subject,
				body = body,
				when = utils.get_date_time("datetimeProperty")
			)
			logEmail.put()

			try:
				mail.send_mail(sender, to, subject, body)
			except Exception as ex:
				logging.error("Failed attempt to send invite email because %s." % ex)
		else:
			# doing nothing, you fuckers
			logging.error("Failed attempt to send invite email.")
Beispiel #8
0
	def post(self, group_id = None):
		# lookup user's auth info
		user_info = User.get_by_id(long(self.user_id))
		
		# get the group in question
		group = Group.get_by_id(long(group_id))

		# bail if group doesn't exist user isn't the owner/admin
		if not group or group.owner != user_info.key:
			return self.redirect_to('account-groups')

		# check what was returned from form validates
		if not self.form.validate():          
			self.add_message("The %s group was not updated." % group.name, "info")
			return self.redirect_to('account-groups')

		# load form values
		name = self.form.name.data.strip()
		description = self.form.description.data.strip()

		# check if we have a group named that already
		if Group.get_by_name(name):
			self.add_message("A group with that name already exists!", "error")
			return self.redirect_to('account-groups')
			
		# save the new group            
		group.name = name
		group.description = description
		group.put()

		# log to alert
		self.add_message("Group %s updated!" % name, "success")

		# give it a few seconds to update db, then redirect
		time.sleep(1)
		
		return self.redirect_to('account-groups')
Beispiel #9
0
    def get(self, group_id=None):
        # lookup user's auth info
        user_info = User.get_by_id(long(self.user_id))

        # get the group in question
        group = Group.get_by_id(long(group_id))

        # scan if this user is a member and/or admin
        if group.owner == user_info.key:
            is_admin = True
            is_member = True  # obvious
        else:
            is_admin = False
            is_member = GroupMembers.is_member(user_info.key, group.key)

        # bail if group doesn't exist or user isn't in the membership list
        if not group or not is_member:
            return self.redirect_to('account-groups')

        # get the members
        members = GroupMembers.get_group_users(group.key)

        # create an object with appliance counts per user
        appliance_count = {}
        for member in members:
            # get the appliance counts per user for this group
            count = Appliance.get_appliance_count_by_user_group(
                member.key, group.key)
            appliance_count[member.key.id()] = count

        # setup channel to do page refresh
        channel_token = user_info.key.urlsafe()
        refresh_channel = channel.create_channel(channel_token)

        # params build out - ugly cause instructions/admin stuff
        params = {
            'is_admin': is_admin,
            'is_member': is_member,
            'group': group,
            'members': members,
            'appliance_count': appliance_count,
            'num_members': len(members),
            'gmform': self.gmform,
            'refresh_channel': refresh_channel,
            'channel_token': channel_token
        }

        return self.render_template('groups/group_manage.html', **params)
Beispiel #10
0
	def get(self, group_id = None):
		# lookup user's auth info
		user_info = User.get_by_id(long(self.user_id))
		
		# get the group in question
		group = Group.get_by_id(long(group_id))

		# scan if this user is a member and/or admin
		if group.owner == user_info.key:
			is_admin = True
			is_member = True # obvious
		else:
			is_admin = False
			is_member = GroupMembers.is_member(user_info.key, group.key)

		# bail if group doesn't exist or user isn't in the membership list
		if not group or not is_member:
			return self.redirect_to('account-groups')

		# get the members
		members = GroupMembers.get_group_users(group.key)

		# create an object with appliance counts per user
		appliance_count = {}
		for member in members:
			# get the appliance counts per user for this group
			count = Appliance.get_appliance_count_by_user_group(member.key, group.key)
			appliance_count[member.key.id()] = count

		# setup channel to do page refresh
		channel_token = user_info.key.urlsafe()
		refresh_channel = channel.create_channel(channel_token)

		# params build out - ugly cause instructions/admin stuff
		params = {
			'is_admin': is_admin,
			'is_member': is_member,
			'group': group,
			'members': members,
			'appliance_count': appliance_count,
			'num_members': len(members),
			'gmform': self.gmform,
			'refresh_channel': refresh_channel,
			'channel_token': channel_token 
		}

		return self.render_template('groups/edit.html', **params)
Beispiel #11
0
    def post(self, group_id=None):
        # lookup user's auth info
        user_info = User.get_by_id(long(self.user_id))

        # get the group in question
        group = Group.get_by_id(long(group_id))

        # get this user's membership
        is_member = GroupMembers.is_member(user_info.key, group.key)

        # bail if group doesn't exist or user not a member
        if not group or not is_member:
            return self.redirect_to('account-groups')

        # check what was returned from form validates
        if not self.form.validate():
            self.add_message("The email form did not validate.", "error")
            return self.redirect_to('account-groups-configure',
                                    group_id=group.key.id())

        # load form values
        email = self.form.email.data.strip()

        # create the invite
        member = GroupMembers.invite(email, group.key, user_info.key)

        time.sleep(1)

        # build an invite URL, load the email_url, and then execute the task to send invite
        invite_url = "%s%s?token=%s" % (self.request.host_url,
                                        self.uri_for('account-groups-invites'),
                                        member.token)
        email_url = self.uri_for('tasks-sendinvite')
        taskqueue.add(url=email_url,
                      params={
                          'to': str(email),
                          'group_id': group.key.id(),
                          'invitor_id': user_info.key.id(),
                          'invite_url': invite_url
                      })

        # log to alert
        self.add_message("User invited to group!", "success")

        return self.redirect_to('account-groups-configure',
                                group_id=group.key.id())
Beispiel #12
0
	def post(self, group_id = None):
		# lookup user's auth info
		user_info = User.get_by_id(long(self.user_id))
		
		# get the group in question
		group = Group.get_by_id(long(group_id))

		# get this user's membership
		is_member	= GroupMembers.is_member(user_info.key, group.key)

		# bail if group doesn't exist or user not a member
		if not group or not is_member:
			return self.redirect_to('account-groups')

		# check what was returned from form validates
		if not self.form.validate():          
			self.add_message("The email form did not validate.", "error")
			return self.redirect_to('account-groups-configure', group_id = group.key.id())

		# load form values
		email = self.form.email.data.strip()

		# create the invite
		member = GroupMembers.invite(email, group.key, user_info.key)
		
		time.sleep(1)

		# build an invite URL, load the email_url, and then execute the task to send invite
		invite_url = "%s%s?token=%s" % (self.request.host_url, self.uri_for('account-groups-invites'), member.token)
		email_url = self.uri_for('tasks-sendinvite')
		taskqueue.add(url = email_url, params={
				'to': str(email),
				'group_id': group.key.id(),
				'invitor_id' : user_info.key.id(),
				'invite_url' : invite_url
		})

		# log to alert
		self.add_message("User invited to group!", "success")
		
		return self.redirect_to('account-groups-configure', group_id = group.key.id())
Beispiel #13
0
    def delete(self, group_id=None, member_id=None):
        # lookup user's auth info
        user_info = User.get_by_id(long(self.user_id))

        # get the group in question
        group = Group.get_by_id(long(group_id))
        member = User.get_by_id(long(member_id))

        # get this user's admin rights
        is_admin = False
        if group.owner == user_info.key:
            is_admin = True

        # bail if group doesn't exist or user is not admin
        if not group or not is_admin:
            # log to alert
            self.add_message("You may not remove this user from group.",
                             "error")
        else:
            # look up the other user's group membership
            membership = GroupMembers.get_by_userid_groupid(
                member.key, group.key)

            # kill the membership
            membership.key.delete()

            # find member's appliances that match that group and remove
            appliances = Appliance.get_by_user_group(member.key, group.key)
            for appliance in appliances:
                appliance.group = None  # public group
                appliance.put()

            # log to alert
            self.add_message("User removed from group!", "success")

        # use the channel to tell the browser we are done and reload
        channel_token = self.request.get('channel_token')
        channel.send_message(channel_token, 'reload')
        return
Beispiel #14
0
	def delete(self, group_id = None, member_id = None):
		# lookup user's auth info
		user_info = User.get_by_id(long(self.user_id))
		
		# get the group in question
		group = Group.get_by_id(long(group_id))
		member = User.get_by_id(long(member_id))

		# get this user's admin rights
		is_admin = False
		if group.owner == user_info.key:
			is_admin = True

		# bail if group doesn't exist or user is not admin
		if not group or not is_admin:
			# log to alert
			self.add_message("You may not remove this user from group.", "error")
		else:	
			# look up the other user's group membership
			membership = GroupMembers.get_by_userid_groupid(member.key, group.key)

			# kill the membership
			membership.key.delete()

			# find member's appliances that match that group and remove
			appliances = Appliance.get_by_user_group(member.key, group.key)
			for appliance in appliances:
				appliance.group = None # public group
				appliance.put()

			# log to alert
			self.add_message("User removed from group!", "success")
			
		# use the channel to tell the browser we are done and reload
		channel_token = self.request.get('channel_token')
		channel.send_message(channel_token, 'reload')
		return
Beispiel #15
0
    def post(self):
        # lookup user's auth info
        user_info = User.get_by_id(long(self.user_id))

        # initialize form choices for group
        self.form.group.choices = []

        # add list of user's groups, if any
        groups = GroupMembers.get_user_groups(user_info.key)
        for group in groups:
            self.form.group.choices.insert(0,
                                           (str(group.key.id()), group.name))

        # public group
        self.form.group.choices.insert(0, ('public', "Public"))

        # check if we are getting a custom group entry
        if self.form.group.data == "custom":
            # check if the group exists
            if Group.get_by_name(self.form.custom.data.strip()):
                self.add_message("A group with that name already exists!",
                                 "error")
                return self.redirect_to('account-appliances')

            # make the new group
            group = Group(name=self.form.custom.data.strip(),
                          owner=user_info.key)
            group.put()
            group_key = group.key

            # create the group member entry
            groupmember = GroupMembers(
                group=group_key,
                member=user_info.key,
                invitor=user_info.key,  # same same
                active=True)
            groupmember.put()

            # hack the form with new group
            self.form.group.choices.insert(0, ('custom', "Custom"))
        else:
            # grab an existing group
            if self.form.group.data.strip() == 'public':
                # no group for public appliances
                group_key = None
            else:
                # check membership
                group = Group.get_by_id(int(self.form.group.data.strip()))
                if GroupMembers.is_member(user_info.key, group.key):
                    group_key = group.key
                else:
                    group_key = None

        # check what was returned from the rest of the form validates
        if not self.form.validate():
            self.add_message("The new appliance form did not validate.",
                             "error")
            return self.get()

        # load form values
        name = self.form.name.data.strip()
        token = self.form.token.data.strip()

        # check if we have it already - all that work bitches?
        if Appliance.get_by_token(token):
            self.add_message("An appliance with that token already exists!",
                             "error")
            return self.redirect_to('account-appliances')

        # save the new appliance in our database
        appliance = Appliance(name=name,
                              token=token,
                              group=group_key,
                              owner=user_info.key)
        appliance.put()

        # log to alert
        self.add_message("Appliance %s successfully created!" % name,
                         "success")

        # give it a few seconds to update db, then redirect
        time.sleep(1)
        return self.redirect_to('account-appliances')
Beispiel #16
0
    def post(self):
        # lookup user's auth info
        user_info = User.get_by_id(long(self.user_id))

        # initialize form choices for group
        self.form.group.choices = []

        # add list of user's groups, if any
        groups = GroupMembers.get_user_groups(user_info.key)
        for group in groups:
            self.form.group.choices.insert(0, (str(group.key.id()), group.name))

            # public group
        self.form.group.choices.insert(0, ("public", "Public"))

        # check if we are getting a custom group entry
        if self.form.group.data == "custom":
            # check if the group exists
            if Group.get_by_name(self.form.custom.data.strip()):
                self.add_message("A group with that name already exists!", "error")
                return self.redirect_to("account-appliances")

                # make the new group
            group = Group(name=self.form.custom.data.strip(), owner=user_info.key)
            group.put()
            group_key = group.key

            # create the group member entry
            groupmember = GroupMembers(
                group=group_key, member=user_info.key, invitor=user_info.key, active=True  # same same
            )
            groupmember.put()

            # hack the form with new group
            self.form.group.choices.insert(0, ("custom", "Custom"))
        else:
            # grab an existing group
            if self.form.group.data.strip() == "public":
                # no group for public appliances
                group_key = None
            else:
                # check membership
                group = Group.get_by_id(int(self.form.group.data.strip()))
                if GroupMembers.is_member(user_info.key, group.key):
                    group_key = group.key
                else:
                    group_key = None

                    # check what was returned from the rest of the form validates
        if not self.form.validate():
            self.add_message("The new appliance form did not validate.", "error")
            return self.get()

            # load form values
        name = self.form.name.data.strip()
        token = self.form.token.data.strip()

        # check if we have it already - all that work bitches?
        if Appliance.get_by_token(token):
            self.add_message("An appliance with that token already exists!", "error")
            return self.redirect_to("account-appliances")

            # save the new appliance in our database
        appliance = Appliance(name=name, token=token, group=group_key, owner=user_info.key)
        appliance.put()

        # log to alert
        self.add_message("Appliance %s successfully created!" % name, "success")

        # give it a few seconds to update db, then redirect
        time.sleep(1)
        return self.redirect_to("account-appliances")
Beispiel #17
0
	def get(self, project_id = None):
		project = Project.get_by_id(long(project_id))
		# if no project
		if not project:
			return self.redirect_to('projects')

		# assume this user is not owner
		owner = False

		# print self.render_url(project.json_url, {})

		# determine if we can show the project
		if not project.public:
			# see if we have a user
			try:
				user_info = User.get_by_id(long(self.user_id))
				if user_info.key != project.owner:
					raise Exception
				else:
					owner = True

			except:
				self.add_message("You must be the owner to do this.", "fail")
				return self.redirect_to('projects')
		else:
			try:
				user_info = User.get_by_id(long(self.user_id))
				if user_info.key == project.owner:
					owner = True

			except:
				user_info = None

		# define minimum specifications for the instance
		specs = {
			'vpus': project.vpus,
			'memory': project.memory,
			'disk': project.disk
		}

		# empty forms
		self.form.provider.choices = []
		self.form.flavor.choices = []

		# plenty?
		plenty = False

		# dict of providers
		providers = {}

		# find the all public provider's appliances and add to providers object
		appliances = Appliance.get_by_group(None)
		for appliance in appliances:
			providers[appliance.key.id()] = {
				'name': "%s (Public)" % appliance.name,
				'location': [appliance.location.lat, appliance.location.lon],
				'flavors': []
			}

		# if there is a user, find his groups and do the same with appliances in those groups
		if user_info:
			groups = Group.get_by_owner(user_info.key)
			for group in groups:
				appliances = Appliance.get_by_group(group.key)
				for appliance in appliances:
					providers[str(appliance.key.id())] = {
						'name': "%s of %s (Hybrid Group)" % (appliance.name, group.name),
						'location': [appliance.location.lat, appliance.location.lon],
						'flavors': []
					}

		# iterate over the dictionary of providers
		for provider in providers:
			# find the list of flavors for this provider which support this project
			flavors = Flavor.flavors_with_min_specs_by_appliance_on_sale(
				specs, 
				ndb.Key('Appliance', long(provider))
			)

			# add provider to the form and the flavors to provider object if flavors exist
			if flavors:
				plenty = True
				# insert this provider's appliance into the form
				self.form.provider.choices.insert(0, (provider, providers[provider]['name']))

				# insert flavors into object
				for flavor in flavors:
					providers[provider]['flavors'].append(
						{
							'id': str(flavor.key.id()),
							'name': flavor.name,
							'description': flavor.description
						}
					)

		# setup channel to do page refresh
		channel_token = 'changeme'
		refresh_channel = channel.create_channel(channel_token)

		# params build out
		params = {
			'project': project,
			'providers': json.dumps(providers),
			'plenty': plenty,
			'owner': owner,
			'refresh_channel': refresh_channel,
			'channel_token': channel_token 
		}

		return self.render_template('project/view.html', **params)