예제 #1
0
	def get(self):
		# lookup user's auth info
		user_info = User.get_by_id(long(self.user_id))

		# look up wisps
		wisps = Wisp.get_by_user(user_info.key)

		# redirect if we don't have any wisps
		if not wisps:
			return self.redirect_to('account-wisps-new')

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

		# params build out
		params = {
			'wisps': wisps, 
			'refresh_channel': refresh_channel,
			'channel_token': channel_token 
		}

		# check for default
		default = False
		for wisp in wisps:
			if wisp.default:
				default = True
		if not default:
			print "wtf"
			self.add_message("Please set a wisp to be default!", "error")

		return self.render_template('wisp/wisps.html', **params)
예제 #2
0
	def get(self):
		# basics
		ip = self.request.remote_addr

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

		# various pulldown initialization
		self.form.flavor.choices=[]
		self.form.wisp.choices=[]
		self.form.cloud.choices=[]

		# add list of user's flavors, if any
		flavors = Flavor.flavors_with_instances_on_sale()
		for flavor in flavors:
			self.form.flavor.choices.insert(0, (flavor.name, flavor.description))

		# used for determining element layout
		wisp = None
		cloud = None

		# if the user is logged in, we build out the list of their wisps
		if self.user_id:
			# lookup user's auth info and wisps
			user_info = User.get_by_id(long(self.user_id))
			wisps = Wisp.get_by_user(user_info.key)
			for wisp in wisps:
				self.form.wisp.choices.insert(0, (wisp.key.id(), wisp.name))
		
			# load clouds
			clouds = Cloud.get_by_user(user_info.key)

			# create default cloud if none
			if not clouds:
				cloud = Cloud.create_default(user_info.key)
				clouds.append(cloud)
				self.add_message("Default cloud created.", 'success')

			for cloud in clouds:
				self.form.cloud.choices.insert(0, (cloud.key.id(), cloud.name))

		# params build out (injects the last wisp, if there was one)
		params = {
			'remote_ip': ip,
			'wisp': wisp,
			'cloud': cloud,
			'refresh_channel': refresh_channel,
			'channel_token': channel_token 
		}

		return self.render_template('lab/launcher.html', **params)
예제 #3
0
    def get(self):
        # lookup user's auth info
        user_info = User.get_by_id(long(self.user_id))

        # look up wisps
        wisps = Wisp.get_by_user(user_info.key)
        if len(wisps) > 0:
            wisps_exist = True
        else:
            wisps_exist = False

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

        # params build out
        params = {
            'wisps_exist': wisps_exist,
            'refresh_channel': refresh_channel,
            'channel_token': channel_token
        }

        return self.render_template('user/status.html', **params)
예제 #4
0
	def get(self):
		# lookup user's auth info
		user_info = User.get_by_id(long(self.user_id))

		# look up wisps
		wisps = Wisp.get_by_user(user_info.key)
		if len(wisps) > 0:
			wisps_exist = True
		else:
			wisps_exist = False
			
		# setup channel to do page refresh
		channel_token = user_info.key.urlsafe()
		refresh_channel = channel.create_channel(channel_token)

		# params build out
		params = {
			'wisps_exist': wisps_exist,
			'refresh_channel': refresh_channel,
			'channel_token': channel_token 
		}

		return self.render_template('user/status.html', **params)
예제 #5
0
	def post(self):
		# lookup user's auth info
		user_info = User.get_by_id(long(self.user_id))

		# load projects pulldown
		self.form.project.choices = []

		# public + private
		projects = Project.get_available(user_info.key)
		for project in projects:
			self.form.project.choices.insert(0, (str(project.key.id()), project.name))

		# insert images into list for wisp
		self.form.image.choices=[('custom', "Dynamic Image URL")]
		images = Image.get_all()
		for image in images:
			self.form.image.choices.insert(0, (str(image.key.id()), image.description))

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

		# load form values
		name = self.form.name.data.strip()
		ssh_key = self.form.ssh_key.data.strip()
		dynamic_image_url = self.form.dynamic_image_url.data.strip()
		image_container_format = self.form.image_container_format.data.strip()
		image_disk_format = self.form.image_disk_format.data.strip()
		post_creation = self.form.post_creation.data.strip()
		callback_url = self.form.callback_url.data.strip()
		default = self.form.default.data # no strip cause bool

		# check if project is selected
		if self.form.wisp_type.data.strip() == 'project':
			project = Project.get_by_id(long(self.form.project.data.strip())).key
		else:
			project = None		

		# hack up form to deal with custom image
		if self.form.image.data.strip() == "custom":
			image = None
		else:
			image = Image.get_by_id(long(self.form.image.data.strip())).key

		# hack up form to deal with custom callback
		if self.form.wisp_type.data.strip() == "custom":
			image = None
			ssh_key = None
			dynamic_image_url = None
			post_creation = None
		elif self.form.wisp_type.data.strip() == "project":
			image = None
			dynamic_image_url = None
			post_creation = None
		else:
			callback_url = None

		# check if we have it already
		if Wisp.get_by_user_name(user_info.key, name):
			self.add_message("A wisp with that name already exists in this account!", "error")
			return self.redirect_to('account-wisps')		
		
		# check if we need to force default setting for first new wisp
		if not Wisp.get_by_user(user_info.key):
			default = True

		# save the new wisp in our database            
		wisp = Wisp(
			name = name,
			owner = user_info.key,
			image = image,
			ssh_key = ssh_key,
			dynamic_image_url = dynamic_image_url,
			image_container_format = image_container_format,
			image_disk_format = image_disk_format,
			post_creation = post_creation,
			callback_url = callback_url,
			project = project
		)
		wisp.put()

		# set default if true
		if default:
			Wisp.set_default(wisp)

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

		# give it a few seconds to update db, then redirect
		time.sleep(1)
		return self.redirect_to('account-wisps-detail', wisp_id=wisp.key.id())