# Path: zaqar_ui/api/zaqar.py
# LOG = logging.getLogger(__name__)
# RESERVED_QUEUE_METADATA = ["_max_messages_post_size", "_default_message_ttl"]
# def zaqarclient(request):
# def queue_list(request, limit=None, marker=None):
# def queue_create(request, queue_name, metadata):
# def queue_delete(request, queue_name):
# def queue_update(request, queue_name, metadata):
# def queue_get(request, queue_name):
# def queue_purge(request, queue_name, resource_types):
# def message_post(request, queue_name, messages_data):
# def message_list(request, queue_name):
# def queue_signed_url(request, queue_name, paths, ttl_seconds, methods):
# def subscription_list(request, queue_name):
# def subscription_create(request, queue_name, sub_data):
# def subscription_delete(request, queue_name, sub_data):
# def subscription_update(request, queue_name, old_data, new_data):
# def pool_list(request, limit=None, marker=None):
# def pool_create(request, pool_name, params):
# def pool_delete(request, pool_name):
# def pool_update(request, pool_name, params):
# def pool_get(request, pool_name):
# def flavor_list(request, limit=None, marker=None):
# def flavor_create(request, flavor_name, params):
# def flavor_delete(request, flavor_name):
# def flavor_update(request, flavor_name, params):
# def flavor_get(request, flavor_name):


import json
import yaml
from django.utils.translation import ugettext_lazy as _
from django.views import generic
from openstack_dashboard.api.rest import urls
from openstack_dashboard.api.rest import utils as rest_utils
from zaqar_ui.api import zaqar

def _convert_to_yaml(data, default_flow_style=False):
    if not data:
        return ''
    try:
        return yaml.safe_dump(data, default_flow_style=default_flow_style)
    except Exception:
        return ''


def _load_yaml(data):
    if not data:
        loaded_data = {}
    else:
        try:
            loaded_data = yaml.safe_load(data)
        except Exception as ex:
            raise Exception(_('The specified input is not a valid '
                              'YAML format: %s') % str(ex))
    return loaded_data


@urls.register
class Queue(generic.View):
    """API for retrieving a single queue"""
    url_regex = r'zaqar/queues/(?P<queue_name>[^/]+)$'

    @rest_utils.ajax()
    def get(self, request, queue_name):
        """Get a specific queue"""

# Path: zaqar_ui/api/zaqar.py
# LOG = logging.getLogger(__name__)
# RESERVED_QUEUE_METADATA = ["_max_messages_post_size", "_default_message_ttl"]
# def zaqarclient(request):
# def queue_list(request, limit=None, marker=None):
# def queue_create(request, queue_name, metadata):
# def queue_delete(request, queue_name):
# def queue_update(request, queue_name, metadata):
# def queue_get(request, queue_name):
# def queue_purge(request, queue_name, resource_types):
# def message_post(request, queue_name, messages_data):
# def message_list(request, queue_name):
# def queue_signed_url(request, queue_name, paths, ttl_seconds, methods):
# def subscription_list(request, queue_name):
# def subscription_create(request, queue_name, sub_data):
# def subscription_delete(request, queue_name, sub_data):
# def subscription_update(request, queue_name, old_data, new_data):
# def pool_list(request, limit=None, marker=None):
# def pool_create(request, pool_name, params):
# def pool_delete(request, pool_name):
# def pool_update(request, pool_name, params):
# def pool_get(request, pool_name):
# def flavor_list(request, limit=None, marker=None):
# def flavor_create(request, flavor_name, params):
# def flavor_delete(request, flavor_name):
# def flavor_update(request, flavor_name, params):
# def flavor_get(request, flavor_name):


# Path: zaqar_ui/api/rest/zaqar.py
import json
import yaml
from django.utils.translation import ugettext_lazy as _
from django.views import generic
from openstack_dashboard.api.rest import urls
from openstack_dashboard.api.rest import utils as rest_utils
from zaqar_ui.api import zaqar


def _convert_to_yaml(data, default_flow_style=False):
    if not data:
        return ''
    try:
        return yaml.safe_dump(data, default_flow_style=default_flow_style)
    except Exception:
        return ''


def _load_yaml(data):
    if not data:
        loaded_data = {}
    else:
        try:
            loaded_data = yaml.safe_load(data)
        except Exception as ex:
            raise Exception(_('The specified input is not a valid '
                              'YAML format: %s') % str(ex))
    return loaded_data


@urls.register
class Queue(generic.View):
    """API for retrieving a single queue"""
    url_regex = r'zaqar/queues/(?P<queue_name>[^/]+)$'

    @rest_utils.ajax()
    def get(self, request, queue_name):
        """Get a specific queue"""

        queue = zaqar.queue_get(request, queue_name)