# Path: tsuru_autoscale/wizard/client.py
# def host():
# def tsuru_host():
# def clean_token(token):
# def app_info(name, token):
# def pool_info(name, token):
# def process_list(instance_name, token):
# def new(data, token):
# def get(name, token):
# def remove(name, token):
# def enable(name, token):
# def disable(name, token):
# def events(name, token):
# 
# Path: tsuru_autoscale/native/forms.py
# class ScaleForm(forms.Form):
#     def clean(self):


import json
import requests
from django.shortcuts import redirect
from django.core.urlresolvers import reverse
from django.contrib import messages
from django.views.generic import FormView, View
from tsuru_dashboard.apps.views import AppMixin
from tsuru_autoscale.wizard import client as wclient
from tsuru_autoscale.native import forms
    def get(self, request, app_name, process):
        token = request.session.get('tsuru_token').split(" ")[-1]

        try:
            remove_autoscale(app_name, process, token)
        except Exception as e:
            messages.error(request, e)
        else:
            messages.success(request, u"Auto scale saved.")

        url = reverse("autoscale-app-info", args=[app_name])
        return redirect(url)


def add_autoscale(app, data, token):
    url = "{}/apps/{}/units/autoscale".format(wclient.tsuru_host(), app)
    headers = {
        "Authorization": wclient.clean_token(token),
        "Content-Type": "application/json",
    }
    response = requests.post(url, data=json.dumps(data), headers=headers)
    if response.status_code != 200:
        raise Exception(
            'Invalid response {}: {}'.format(response.status_code, response.text),
        )


def remove_autoscale(app, process, token):
    url = "{}/apps/{}/units/autoscale?process={}".format(wclient.tsuru_host(), app, process)
    headers = {

# Path: tsuru_autoscale/wizard/client.py
# def host():
# def tsuru_host():
# def clean_token(token):
# def app_info(name, token):
# def pool_info(name, token):
# def process_list(instance_name, token):
# def new(data, token):
# def get(name, token):
# def remove(name, token):
# def enable(name, token):
# def disable(name, token):
# def events(name, token):
# 
# Path: tsuru_autoscale/native/forms.py
# class ScaleForm(forms.Form):
#     def clean(self):


# Path: tsuru_autoscale/native/views.py
import json
import requests
from django.shortcuts import redirect
from django.core.urlresolvers import reverse
from django.contrib import messages
from django.views.generic import FormView, View
from tsuru_dashboard.apps.views import AppMixin
from tsuru_autoscale.wizard import client as wclient
from tsuru_autoscale.native import forms

    def get(self, request, app_name, process):
        token = request.session.get('tsuru_token').split(" ")[-1]

        try:
            remove_autoscale(app_name, process, token)
        except Exception as e:
            messages.error(request, e)
        else:
            messages.success(request, u"Auto scale saved.")

        url = reverse("autoscale-app-info", args=[app_name])
        return redirect(url)


def add_autoscale(app, data, token):
    url = "{}/apps/{}/units/autoscale".format(wclient.tsuru_host(), app)
    headers = {
        "Authorization": wclient.clean_token(token),
        "Content-Type": "application/json",
    }
    response = requests.post(url, data=json.dumps(data), headers=headers)
    if response.status_code != 200:
        raise Exception(
            'Invalid response {}: {}'.format(response.status_code, response.text),
        )


def remove_autoscale(app, process, token):
    url = "{}/apps/{}/units/autoscale?process={}".format(wclient.tsuru_host(), app, process)
    headers = {

        "Authorization": wclient.clean_token(token),