# 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
        form = forms.ScaleForm(self.request.POST or None)
        p_list = wclient.process_list(app_name, token)
        form.fields['process'].choices = p_list
        return form

    def get_context_data(self, *args, **kwargs):
        return super(NativeAutoscale, self).get_context_data(*self.args, **self.kwargs)

    def form_valid(self, form):
        token = self.request.session.get('tsuru_token').split(" ")[-1]
        app_name = self.kwargs.get('app_name')
        cpuMilli = form.cleaned_data["target_cpu"] * 10
        data = {
            "process": form.cleaned_data["process"],
            "minUnits": form.cleaned_data["min_units"],
            "maxUnits": form.cleaned_data["max_units"],
            "averageCPU": '{}m'.format(cpuMilli),
        }

        try:
            add_autoscale(app_name, data, token)
        except Exception as e:
            messages.error(self.request, e)
        else:
            messages.success(self.request, u"Auto scale saved.")
            url = reverse("autoscale-app-info", args=[app_name])
            return redirect(url)


class NativeAutoscaleRemove(AppMixin, View):

# 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

        form = forms.ScaleForm(self.request.POST or None)
        p_list = wclient.process_list(app_name, token)
        form.fields['process'].choices = p_list
        return form

    def get_context_data(self, *args, **kwargs):
        return super(NativeAutoscale, self).get_context_data(*self.args, **self.kwargs)

    def form_valid(self, form):
        token = self.request.session.get('tsuru_token').split(" ")[-1]
        app_name = self.kwargs.get('app_name')
        cpuMilli = form.cleaned_data["target_cpu"] * 10
        data = {
            "process": form.cleaned_data["process"],
            "minUnits": form.cleaned_data["min_units"],
            "maxUnits": form.cleaned_data["max_units"],
            "averageCPU": '{}m'.format(cpuMilli),
        }

        try:
            add_autoscale(app_name, data, token)
        except Exception as e:
            messages.error(self.request, e)
        else:
            messages.success(self.request, u"Auto scale saved.")
            url = reverse("autoscale-app-info", args=[app_name])
            return redirect(url)


class NativeAutoscaleRemove(AppMixin, View):

    def get(self, request, app_name, process):