示例#1
0
def configure_flavors_detail(flavor_id):
    # get the matching flavor
    flavor = db.session.query(Flavors).filter_by(id=flavor_id).first()

    # handle a GET
    if request.method == 'GET':
        # check configuration
        settings = Status().check_settings()

        # how much is a micro BTC?
        try:
            quote = float(
                coinbase_get_quote(
                    currency='btc_to_usd')['result']['btc_to_usd']) / 1000000
        except:
            quote = 0

        return render_template('/configure/flavor_detail.html',
                               settings=settings,
                               quote=quote,
                               flavor=flavor)

    # handle a PUT
    elif request.method == 'PUT':
        # clear settings cache
        Status().flush()

        try:
            state = int(request.form['enable'])
            flavor.active = state

            # set instances with this flavor to the state
            instances = Instances()
            instances.toggle(flavor.id, state)

        except:
            pass

        try:
            ask = request.form['ask']
            flavor.ask = ask
        except:
            pass

        # update entry
        flavor.update()

        return jsonify({"response": "success", "flavor": row2dict(flavor)})
示例#2
0
def configure_flavors_detail(flavor_id):
    # get the matching flavor
    flavor = db.session.query(Flavors).filter_by(id=flavor_id).first()

    # handle a GET
    if request.method == "GET":
        # check configuration
        settings = Status().check_settings()

        # how much is a micro BTC?
        try:
            quote = float(coinbase_get_quote(currency="btc_to_usd")["result"]["btc_to_usd"]) / 1000000
        except:
            quote = 0

        return render_template("/configure/flavor_detail.html", settings=settings, quote=quote, flavor=flavor)

        # handle a PUT
    elif request.method == "PUT":
        # clear settings cache
        Status().flush()

        try:
            state = int(request.form["enable"])
            flavor.active = state

            # set instances with this flavor to the state
            instances = Instances()
            instances.toggle(flavor.id, state)

        except:
            pass

        try:
            ask = request.form["ask"]
            flavor.ask = ask
        except:
            pass

            # update entry
        flavor.update()

        return jsonify({"response": "success", "flavor": row2dict(flavor)})
示例#3
0
def configure_flavors_detail(flavor_id):
    # get the matching flavor
    flavor = db.session.query(Flavors).filter_by(id=flavor_id).first()

    # clear settings cache
    Status().flush()

    # enable/diskable
    if 'enable' in request.form.keys():
        flavor.update(active=int(request.form['enable']))

    # set ask
    if 'ask' in request.form.keys():
        flavor.update(ask=int(request.form['ask']))

    # set max-instances
    if 'max-instances' in request.form.keys():
        flavor.update(max_instances=int(request.form['max-instances']))

    # install pool flavor
    if 'install' in request.form.keys():
        # let's see what we can break, er install
        try:
            if not flavor:
                response = jsonify({
                    "response": "error",
                    "result": {
                        "message": "Flavor %s not found." % flavor_id
                    }
                })
                response.status_code = 404
                return response

            # we are told to install
            if int(request.form['install']):
                response = flavor_verify_install(flavor)
                if not response['response'] == 'success':
                    raise Exception(response['result']['message'])

                if flavor.ask > 0:
                    flavor.update(active=True)
                else:
                    flavor.update(active=False)
            else:
                # we are told to uninstall (install=0)
                response = flavor_uninstall(flavor)
                if not response['response'] == 'success':
                    raise Exception(response['result']['message'])

                flavor.update(installed=False, active=False, osid=None)

        except Exception as e:
            response = jsonify({
                "response": "error",
                "result": {
                    "message": str(e)
                }
            })
            response.status_code = 403
            return response

    # set instance state to match flavor's state
    instances = Instances()
    instances.toggle(flavor.id, flavor.active)

    # update the ask prices on the openstack cluster using metadata
    try:
        # get current ask price on openstack and update
        flavor.save()

    # warn because we couldn't update the ask price that's set on openstack
    except nova_exceptions.Forbidden:
        app.logger.warning(
            'No permissions to update price of flavor "{0}".'.format(
                flavor.name))
        return response

    # handle any other exception while talking to openstack
    except Exception as e:
        app.logger.warning('Error updating price of flavor "{0}": {1}.'.format(
            flavor.name, str(e)))

    return jsonify({"response": "success", "flavor": row2dict(flavor)})
示例#4
0
def configure_flavors_detail(flavor_id):
	# get the matching flavor
	flavor = db.session.query(Flavors).filter_by(id=flavor_id).first()

	# clear settings cache
	Status().flush()

	# enable/diskable
	if 'enable' in request.form.keys():
		flavor.update(active=int(request.form['enable']))

	# set ask
	if 'ask' in request.form.keys():
		flavor.update(ask=int(request.form['ask']))

	# set max-instances
	if 'max-instances' in request.form.keys():
		flavor.update(max_instances=int(request.form['max-instances']))

	# install pool flavor
	if 'install' in request.form.keys():
		# let's see what we can break, er install
		try:
			if not flavor:
				response = jsonify({"response": "error", "result": {"message": "Flavor %s not found." % flavor_id }})
				response.status_code = 404
				return response

			# we are told to install
			if int(request.form['install']):
				response = flavor_verify_install(flavor)
				if not response['response'] == 'success':
					raise Exception(response['result']['message'])
				
				if flavor.ask > 0:
					flavor.update(active=True)
				else:
					flavor.update(active=False)
			else:
				# we are told to uninstall (install=0)
				response = flavor_uninstall(flavor)
				if not response['response'] == 'success':
					raise Exception(response['result']['message'])

				flavor.update(installed=False, active=False, osid=None)

		except Exception as e:
			response = jsonify({"response": "error", "result": {"message": str(e)}})
			response.status_code = 403
			return response

	# set instance state to match flavor's state
	instances = Instances()
	instances.toggle(flavor.id, flavor.active)

	# update the ask prices on the openstack cluster using metadata
	try:
		# get current ask price on openstack and update
		flavor.save()

	# warn because we couldn't update the ask price that's set on openstack
	except nova_exceptions.Forbidden:
		app.logger.warning('No permissions to update price of flavor "{0}".'.format(
											 flavor.name))
		return response
	
	# handle any other exception while talking to openstack
	except Exception as e:
		app.logger.warning('Error updating price of flavor "{0}": {1}.'.format(
											 flavor.name, str(e)))

	return jsonify({"response": "success", "flavor": row2dict(flavor)})