# Path: tsuru_autoscale/wizard/forms.py
# OPERATOR_CHOICES = (
#     ('>', '>'),
#     ('>=', '>='),
#     ('<=', '<='),
#     ('<', '<'),
#     ('!=', '!='),
# )
# AGGREGATOR_CHOICES = (
#     ('avg', 'average'),
#     ('max', 'maximum'),
# )
# class ScaleForm(forms.Form):
# class ConfigForm(forms.Form):
#     def __init__(self, min_wait, *args, **kwargs):
#     def clean_value(self):
#     def clean_step(self):
# 
# 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/datasource/client.py
# def host():
# def new(data, token):
# def list(token):
# def remove(name, token):
# def get(name, token):


from django.shortcuts import render, redirect
from django.core.urlresolvers import reverse
from django.contrib import messages
from tsuru_autoscale.wizard import forms
from tsuru_autoscale.wizard import client
from tsuru_autoscale.datasource import client as dclient
import requests
import urllib
    p_list = client.process_list(instance, token)
    config_form.fields['process'].choices = p_list

    if scale_up_form.is_valid() and scale_down_form.is_valid() and config_form.is_valid():
        get_or_create_tsuru_instance(instance, token)
        config_data = {
            "name": instance,
            "minUnits": config_form.cleaned_data["min"],
            "scaleUp": scale_up_form.cleaned_data,
            "scaleDown": scale_down_form.cleaned_data,
            "process": config_form.cleaned_data["process"],
        }
        client.new(config_data, token)
        messages.success(request, u"Auto scale saved.")
        url = reverse("autoscale-app-info", args=[instance])
        return redirect(url)

    token = urllib.quote(token)
    context = {
        "scale_up_form": scale_up_form,
        "scale_down_form": scale_down_form,
        "config_form": config_form,
        "token": token,
    }

    return render(request, "wizard/index.html", context)


def remove(request, instance):
    token = request.session.get('tsuru_token').split(" ")[-1]

# Path: tsuru_autoscale/wizard/forms.py
# OPERATOR_CHOICES = (
#     ('>', '>'),
#     ('>=', '>='),
#     ('<=', '<='),
#     ('<', '<'),
#     ('!=', '!='),
# )
# AGGREGATOR_CHOICES = (
#     ('avg', 'average'),
#     ('max', 'maximum'),
# )
# class ScaleForm(forms.Form):
# class ConfigForm(forms.Form):
#     def __init__(self, min_wait, *args, **kwargs):
#     def clean_value(self):
#     def clean_step(self):
# 
# 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/datasource/client.py
# def host():
# def new(data, token):
# def list(token):
# def remove(name, token):
# def get(name, token):


# Path: tsuru_autoscale/wizard/views.py
from django.shortcuts import render, redirect
from django.core.urlresolvers import reverse
from django.contrib import messages
from tsuru_autoscale.wizard import forms
from tsuru_autoscale.wizard import client
from tsuru_autoscale.datasource import client as dclient
import requests
import urllib

    p_list = client.process_list(instance, token)
    config_form.fields['process'].choices = p_list

    if scale_up_form.is_valid() and scale_down_form.is_valid() and config_form.is_valid():
        get_or_create_tsuru_instance(instance, token)
        config_data = {
            "name": instance,
            "minUnits": config_form.cleaned_data["min"],
            "scaleUp": scale_up_form.cleaned_data,
            "scaleDown": scale_down_form.cleaned_data,
            "process": config_form.cleaned_data["process"],
        }
        client.new(config_data, token)
        messages.success(request, u"Auto scale saved.")
        url = reverse("autoscale-app-info", args=[instance])
        return redirect(url)

    token = urllib.quote(token)
    context = {
        "scale_up_form": scale_up_form,
        "scale_down_form": scale_down_form,
        "config_form": config_form,
        "token": token,
    }

    return render(request, "wizard/index.html", context)


def remove(request, instance):
    token = request.session.get('tsuru_token').split(" ")[-1]

    client.remove(instance, token)