示例#1
0
    def action():
        """
		Prints current hypervisor usage information.
		"""
        from webapp.libs.openstack import get_stats

        # check appliance is ready to go - exit if not
        settings = Status().check_settings()
        if not settings['ngrok'] or not settings['openstack']:
            print "Appliance is not ready."
            return action

        stats = get_stats()

        print stats['result']['message']
        for key in stats['result']['stats']:
            print
            print key
            print stats['result']['stats'][key]
示例#2
0
文件: manage.py 项目: replay/utter-va
	def action():
		"""
		Prints current hypervisor usage information.
		"""
		from webapp.libs.openstack import get_stats

		# check appliance is ready to go - exit if not
		settings = Status().check_settings()
		if not settings['ngrok'] or not settings['openstack']:
			print "Appliance is not ready."
			return action

		stats = get_stats()

		print stats['result']['message']
		for key in stats['result']['stats']:
			print
			print key 
			print stats['result']['stats'][key]
示例#3
0
def pool_salesman(instances=None, appliance=None):
    from webapp.libs.openstack import get_stats

    # form the URL to advertise instance for sale
    url = "%s/api/v1/broker/" % (app.config['POOL_APPSPOT_WEBSITE'])

    # grab the cluster's stats
    try:
        response = get_stats()
        stats = response['result']['stats']
    except:
        stats = {}

    # build the sales packet
    packet = {
        "appliance": {
            "apitoken": appliance.apitoken,
            "dynamicimages": appliance.dynamicimages,
            "location": {
                "latitude": appliance.latitude,
                "longitude": appliance.longitude
            },
            "stats": stats
        },
        "instances": []
    }

    # response
    response = {"response": "success", "result": {"message": ""}}

    # loop through advertised instances
    for instance in instances:
        try:
            # convert to a dict
            pool_instance = row2dict(instance)

            # patch in flavor, ask, default image, address
            pool_instance['flavor'] = {
                "vpus": instance.flavor.vpus,
                "memory": instance.flavor.memory,
                "disk": instance.flavor.disk,
                "network_up": instance.flavor.network_up,
                "network_down": instance.flavor.network_down,
                "ask": instance.flavor.ask
            }
            pool_instance['state'] = instance.state
            pool_instance['address'] = instance.address

            # add instances to the data packet
            packet['instances'].append(pool_instance)

        except:
            # something didn't go right somewhere, so just nail the instance
            app.logger.error("Instance=(%s) integrity error." % instance.name)
            # instance.delete(instance)

    try:
        request = Request(url)
        request.add_header('Content-Type', 'application/json')
        response = json.loads(
            urlopen(request, json.dumps(packet), timeout=10).read())
        app.logger.info(
            "Appliance has placed quantity=(%s) instances up for sale." %
            len(instances))

    except HTTPError as ex:
        response['response'] = "error"
        response['result'][
            'message'] = "Error code %s returned from server." % ex.code
    except IOError as ex:
        response['response'] = "error"
        response['result'][
            'message'] = "Can't contact callback server.  Try again later."
    except ValueError as ex:
        response['response'] = "error"
        response['result'][
            'message'] = "Having issues parsing JSON from the site: %s.  Open a ticket." % type(
                ex).__name__
    except Exception as ex:
        response['response'] = "error"
        response['result'][
            'message'] = "An error of type %s has occured.  Open a ticket." % type(
                ex).__name__

    return response
示例#4
0
def pool_salesman(instances=None, appliance=None):
	from webapp.libs.openstack import get_stats

	# form the URL to advertise instance for sale
	url = "%s/api/v1/broker/" % (
		app.config['POOL_APPSPOT_WEBSITE']
	)

	# grab the cluster's stats
	try:
		response = get_stats()
		stats = response['result']['stats']
	except:
		stats = {}

	# build the sales packet
	packet = { 
		"appliance": {
			"apitoken": appliance.apitoken, 
			"dynamicimages": appliance.dynamicimages,
			"location": {
				"latitude": appliance.latitude,
				"longitude": appliance.longitude
			},
			"stats": stats
		},
		"instances": []
	}

	# response
	response = {"response": "success", "result": {"message": ""}}

	# loop through advertised instances
	for instance in instances:
		try:
			# convert to a dict
			pool_instance = row2dict(instance)

			# patch in flavor, ask, default image, address
			pool_instance['flavor'] = instance.flavor.name
			pool_instance['ask'] = instance.flavor.ask
			pool_instance['state'] = instance.state
			pool_instance['image'] = instance.image.name
			pool_instance['address'] = instance.address.address

			# add instances to the data packet
			packet['instances'].append(pool_instance)
		
		except:
			# something didn't go right somewhere, so just nail the instance
			app.logger.error("Instance=(%s) integrity error." % instance.name)
			instance.delete(instance)

	try:
		request = Request(url)
		request.add_header('Content-Type', 'application/json')
		response = json.loads(urlopen(request, json.dumps(packet), timeout=10).read())
		app.logger.info("Appliance has placed quantity=(%s) instances up for sale." % len(instances))

	except HTTPError as ex:
		response['response'] = "error"
		response['result']['message'] = "Error code %s returned from server." % ex.code
	except IOError as ex:
		response['response'] = "error"
		response['result']['message'] = "Can't contact callback server.  Try again later."
	except ValueError as ex:
		response['response'] = "error"
		response['result']['message'] = "Having issues parsing JSON from the site: %s.  Open a ticket." % type(ex).__name__
	except Exception as ex:
		response['response'] = "error"
		response['result']['message'] = "An error of type %s has occured.  Open a ticket." % type(ex).__name__

	return response