Пример #1
0
    def action():
        """
		Verify authentication token is being accepted by pool.
		"""
        # get the appliance configuration
        appliance = db.session.query(Appliance).first()

        if appliance.apitoken:
            response = pool_connect("authorization", appliance)
            print response['result']['message']
        else:
            configure_blurb()
Пример #2
0
	def action():
		"""
		Verify authentication token is being accepted by pool.
		"""
		# get the appliance configuration
		appliance = db.session.query(Appliance).first()

		if appliance.apitoken:
			response = pool_connect("authorization", appliance)
			print response['result']['message']
		else:
			configure_blurb()
Пример #3
0
def token_validate():
	# update appliance database with a new token
	appliance = db.session.query(Appliance).first()
	
	# check with pool operator
	response = pool_connect(method="authorization", appliance=appliance)

	if response['response'] == "success":
		# flush the cached status
		Status().flush()
		return jsonify(response)
	else:
		return jsonify(response), 401
Пример #4
0
def token_validate():
    # update appliance database with a new token
    appliance = db.session.query(Appliance).first()

    # check with pool operator
    response = pool_connect(method="authorization", appliance=appliance)

    if response['response'] == "success":
        # flush the cached status
        Status().flush()
        return jsonify(response)
    else:
        return jsonify(response), 401
Пример #5
0
	def sync(self, appliance):
		# grab image list from pool server
		response = pool_connect(method="images", appliance=appliance)

		if response['response'] == "success":
			remoteimages = response['result']
					
			# update database for images
			for remoteimage in remoteimages['images']:
				# see if we have a matching image
				image = db.session.query(Images).filter_by(name=remoteimage['name']).first()
				
				# check if we need to delete image from local db
				# b'001000' indicates delete image
				# TODO: need to cleanup OpenStack images if we uninstall
				if (remoteimage['flags'] & 8) == 8:
					# only delete if we have it
					if image is not None:
						# try to delete the local copy
						uninstall_image(image)

						# remove the image from the database
						image.delete(image)
					else:
						# we don't have it, so we do nothing
						pass

				# we don't have the image coming in from the server, so install
				elif image is None:
					# create a new image
					image = Images()
					epoch_time = int(time.time())
					image.created = epoch_time
					image.updated = epoch_time
					image.name = remoteimage['name']
					image.description = remoteimage['description']
					image.url = remoteimage['url']
					image.size = remoteimage['size'] # used as a suggestion of size only
					image.cache = 1 # cache locally (unlike dynamic images)
					image.diskformat = remoteimage['diskformat']
					image.containerformat = remoteimage['containerformat']
					image.active = 1 # indicates we know about it, but not downloaded
					image.flags = remoteimage['flags']

					# add and commit
					image.update(image)

				else:
					# update image from remote images (local lookup was by name)
					epoch_time = int(time.time())
					image.description = remoteimage['description']
					if image.url != remoteimage['url']:
						image.url = remoteimage['url']
						image.updated = epoch_time
					if image.diskformat != remoteimage['diskformat']:
						image.diskformat = remoteimage['diskformat']
						image.updated = epoch_time
					if image.containerformat != remoteimage['containerformat']:
						image.containerformat = remoteimage['containerformat']
						image.updated = epoch_time
					if image.flags != remoteimage['flags']:
						image.flags = remoteimage['flags']
						image.updated = epoch_time

					# update
					image.update(image)

			# grab a new copy of the images in database
			images = db.session.query(Images).all()

			# overload the results with the list of current images
			response['result']['images'] = []
			images = db.session.query(Images).all()

			for image in images:
				response['result']['images'].append(row2dict(image))

			return response

		# failure contacting server
		else:
			# lift respose from server call to view
			return response
Пример #6
0
	def check_settings(self):
		status = db.session.query(Status).first()
		
		# calculate cache timeout (120 seconds)
		epoch_time = int(time.time())
		try:
			if (status.updated + 900) < epoch_time:
				# it's been 15 minutes so we are hot
				check = True
			else:
				check = False
		except:
			# need to create a new entry
			check = True
			status = Status()

		# objects
		appliance = Appliance().get()
		openstack = OpenStack()
		flavors = Flavors()

		# if the cache time has been a while, or we are on
		# the configuration page, check settings and cache
		if check:
			app.logger.info("Running full status check.")
			
			# openstack connected?
			openstack_check = openstack.check()
			status.openstack_check = openstack_check['result']

			# coinbase tokens working?
			coinbase_check = coinbase_checker(appliance)
			status.coinbase_check = coinbase_check

			# token valid?
			response = pool_connect(method='authorization', appliance=appliance)

			if response['response'] == "success":
				token_check = True
			else:
				token_check = False
			status.token_check = token_check

			# update database
			status.updated = epoch_time

			# ngrok connection
			ngrok_check = ngrok_checker(appliance)
			status.ngrok_check = ngrok_check
			
			# one flavor installed?
			flavors_check = flavors.check()
			status.flavors_check = flavors_check

			status.update()
		
		else:
			# app.logger.info("Running partial status check.")
			
			# stuff we check all the time
			# openstack connected?
			openstack_check = openstack.check()
			status.openstack_check = openstack_check['result']

			# ngrok connection
			ngrok_check = ngrok_checker(appliance)
			status.ngrok_check = ngrok_check

			# one flavor installed?
			flavors_check = flavors.check()
			status.flavors_check = flavors_check

			# update
			status.update()

		# build the response object
		settings = {
			"flavors": status.flavors_check,
			"openstack": status.openstack_check,
			"coinbase": status.coinbase_check,
			"ngrok": status.ngrok_check,
			"token": status.token_check,
		}
		
		return settings
Пример #7
0
	def sync(self, appliance):
		# grab image list from pool server
		response = pool_connect(method="flavors", appliance=appliance)

		# remote sync
		if response['response'] == "success":
			remoteflavors = response['result']

			# update the database with the flavors
			for remoteflavor in remoteflavors['flavors']:
				flavor = db.session.query(Flavors).filter_by(name=remoteflavor['name']).first()

				# check if we need to delete flavor from local db
				# b'001000' indicates delete image
				# TODO: need to cleanup OpenStack flavor if we uninstall
				if (remoteflavor['flags'] & 8) == 8:
					# only delete if we have it
					if flavor is not None:
						# remove the flavor from the database
						flavor.delete(flavor)
					else:
						# we don't have it, so we do nothing
						pass

				elif flavor is None:
					# we don't have the flavor coming in from the server
					flavor = Flavors()

					# create a new flavor
					flavor.name = remoteflavor['name']
					flavor.description = remoteflavor['description']
					flavor.vpus = remoteflavor['vpus']
					flavor.memory = remoteflavor['memory']
					flavor.disk = remoteflavor['disk']
					flavor.network = remoteflavor['network']
					flavor.rate = remoteflavor['rate']
					flavor.ask = remoteflavor['rate'] # set ask to market rate
					flavor.hot = remoteflavor['hot']
					flavor.launches = remoteflavor['launches']
					flavor.flags = remoteflavor['flags']
					flavor.active = 1

					# add and commit
					flavor.update(flavor)

				# we have the flavor and need to update it	
				else:
					# we have the flavor already, so update
					flavor.name = remoteflavor['name']
					flavor.description = remoteflavor['description']
					flavor.vpus = remoteflavor['vpus']
					flavor.memory = remoteflavor['memory']
					flavor.disk = remoteflavor['disk']
					flavor.network = remoteflavor['network']
					flavor.rate = remoteflavor['rate']
					flavor.hot = remoteflavor['hot']
					# we leave flavor.ask alone
					# we leave flavor.active alone
					flavor.launches = remoteflavor['launches']
					flavor.flags = remoteflavor['flags']
					
					# update
					flavor.update(flavor)

			# overload the results with the list of current flavors
			response['result']['flavors'] = []
			flavors = db.session.query(Flavors).all()
			for flavor in flavors:
				response['result']['flavors'].append(row2dict(flavor))
		
		return response