Skip to content

Commit

Permalink
Release 0.0.6
Browse files Browse the repository at this point in the history
* Update libs (ansible==2.3.2)
* Create elements from copy
* Import inventory from file
* Ansible modules autocomplite
* Ansible command args check before run/save
* Bugfixes
* UI-refactoring for some buttons and actions

See merge request !19
  • Loading branch information
onegreyonewhite committed Aug 25, 2017
2 parents 69e3f2f + 0ad54d8 commit a3b66c0
Show file tree
Hide file tree
Showing 65 changed files with 4,246 additions and 1,081 deletions.
4 changes: 4 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ py34-django110:
<<: *tests_template
py34-django111:
<<: *tests_template
py35-django111:
<<: *tests_template
image: onegreyonewhite/tox:ubuntu


pep8_checks:
stage: code_standarts
Expand Down
10 changes: 10 additions & 0 deletions .gitlab/issue_templates/Ask.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ASK

Replace all comments to answers.
Before adding a new issue check the tracker for similar issues.

#### What's the core of the question?
what's the core of the (your) question about......

#### Details
Files, code, etc....
25 changes: 25 additions & 0 deletions .gitlab/issue_templates/Bug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#BUG

Replace all comments to answers.
Before adding a new issue check the tracker for similar issues.

#### What's the core of the bug?
what's the core of the bug in......

#### Exception output
...if exists.

#### How to reproduce?
How bug we could reproduce?

#### Polemarch version
`sudo -u polemarch /opt/polemarch/bin/polemarchctl webserver --version`

#### Database type
Default, Mysql, etc...

#### RPC type
Default, RabbitMQ, etc...

#### Additional info
Other info that could help.
13 changes: 13 additions & 0 deletions .gitlab/issue_templates/Feature request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Feature request

Replace all comments to answers.
Before adding a new issue check the tracker for similar issues.

#### What feature do you suggest?
Description of features.

#### How do you imagine it?
Describe the changes in functionality after adding this feature

#### Why do you think that this feature should be implemented in the application?
Describe shortly how this feature will be useful for users
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ all: compile
docs:
-rm -rf doc/_build
mkdir -p doc/_static
$(PY) setup.py build_sphinx --build-dir doc/_build
$(PY) setup.py build_sphinx --build-dir doc/_build -W

test:
tox -e $(ENVS) $(TESTS)
Expand Down
10 changes: 7 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ Polemarch
**Polemarch** is service for orchestration infrastructure by ansible.
Simply WEB gui for orchestration infrastructure by ansible playbooks.

Official site: https://gitlab.com/vstconsulting/polemarch
Official site:
https://gitlab.com/vstconsulting/polemarch

For any questions you could use issues tracker:
https://gitlab.com/vstconsulting/polemarch/issues

.. image:: https://raw.githubusercontent.com/vstconsulting/polemarch/master/doc/screencast.gif
:alt: interface of Polemarch
Expand Down Expand Up @@ -33,7 +37,7 @@ Red Hat/CentOS installation

.. sourcecode:: bash

sudo yum localinstall polemarch-0.0.2-0.x86_64.rpm.
sudo yum localinstall polemarch-0.0.X-0.x86_64.rpm.

3. Run services with commands

Expand Down Expand Up @@ -62,7 +66,7 @@ Ubuntu/Debian installation

.. sourcecode:: bash

sudo dpkg -i polemarch_0.0.2-1_amd64.deb || sudo apt-get install -f
sudo dpkg -i polemarch_0.0.X-1_amd64.deb || sudo apt-get install -f

3. Run services with commands

Expand Down
2 changes: 1 addition & 1 deletion deb.mk
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export DEBIAN_RULES
define DEBIAN_PREINST
#!/bin/bash
# making sure user created
id -u $(USER) &>/dev/null || useradd -M $(USER)
id -u $(USER) &>/dev/null || useradd -m $(USER)
id -g $(USER) &>/dev/null || groupadd $(USER)
endef
export DEBIAN_PREINST
Expand Down
20 changes: 5 additions & 15 deletions doc/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ example than general howto) you must do such steps:
location = 127.0.0.1:11211

4. Setup some network filesystem. NFS for example. Mount it in same directory
to all worker-intended nodes. Write that directory in :ref:`worker`.
to all worker-intended nodes. Write that directory in :ref:`main`.
Example:

.. sourcecode:: ini

[worker]
exchange_dir = /mnt/mynfs
[main]
projects_dir = /mnt/mynfs

5. Setup some http-balancer. HAProxy for example. Point it to web-intended
nodes.
Expand Down Expand Up @@ -129,6 +129,8 @@ example than general howto) you must do such steps:

That's it.

.. _main:

Main settings
-------------

Expand Down Expand Up @@ -211,15 +213,3 @@ Section ``[web]``.

Here placed settings related to web-server. It is settings like: allowed hosts,
static files directory or pagination limit.

.. _worker:

Worker settings
---------------

Section ``[worker]``.

Section for worker-related settings. Now here just one - directory to store
files, which must be accessible by all workers. It have meaning only if you
have cluster - more than one workers. In such case you must use some kind of
network filesystem to share data between workers. Like NFS, Samba or something.
4 changes: 2 additions & 2 deletions doc/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Red Hat/CentOS installation

.. sourcecode:: bash

sudo yum localinstall polemarch-0.0.2-0.x86_64.rpm.
sudo yum localinstall polemarch-0.0.X-0.x86_64.rpm.

3. Run services with commands

Expand Down Expand Up @@ -41,7 +41,7 @@ Ubuntu/Debian installation

.. sourcecode:: bash

sudo dpkg -i polemarch_0.0.2-1_amd64.deb || sudo apt-get install -f
sudo dpkg -i polemarch_0.0.X-1_amd64.deb || sudo apt-get install -f

3. Run services with commands

Expand Down
97 changes: 96 additions & 1 deletion doc/restapi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1683,7 +1683,9 @@ History records
"stop_time":"2017-07-02T13:48:11.922777Z",
"raw_inventory":"inventory",
"raw_args": "ansible-playbook main.yml -i /tmp/tmpvMIwMg -v",
"raw_stdout":"text"
"raw_stdout":"text",
"initiator": 1,
"initiator_type": "users"
}

:>json number id: id of history record.
Expand All @@ -1704,6 +1706,8 @@ History records
:>json string raw_stdout: what Ansible wrote to stdout and stderr during
execution. The size is limited to 10M characters. Full output
in :http:get:`/api/v1/history/{id}/raw/`.
:>json number initiator: initiator id.
:>json string initiator_type: initiator type like in api url.
:>json string url: url to this specific history record.

.. |history_details_ref| replace:: **Response JSON Object:** response json fields
Expand Down Expand Up @@ -1940,6 +1944,97 @@ History records
:statuscode 424: facts still not ready because module is currently running
or only scheduled for run.

Ansible
-------

.. http:get:: /api/v1/ansible/
Get list of available methods in that category. All methods under
`/ansible/` designed to provide information about ansible installation which
Polemarch is currently using.

Example request:

.. sourcecode:: http

GET /api/v1/ansible/ HTTP/1.1
Host: example.com
Accept: application/json, text/javascript

Results:

.. sourcecode:: js

{
"cli-reference": "http://localhost:8000/api/v1/ansible/cli_reference/",
"modules": "http://localhost:8000/api/v1/ansible/modules/"
}

.. http:get:: /api/v1/ansible/cli_reference/
Get list of available ansible command line tools arguments with their type
and hint.

:query filter: filter by tool, for which you want get help (either `ansible`
or `ansible-playbook`).

Example request:

.. sourcecode:: http

GET /api/v1/ansible/cli_reference/?filter=ansible HTTP/1.1
Host: example.com
Accept: application/json, text/javascript

Results:

.. sourcecode:: js

{
"ansible": {
"extra-vars": {
"type": "text",
"help": "set additional variables as key=value or YAML/JSON"
},
"help": {
"type": "boolean",
"help": "show this help message and exit"
},
// there is much more arguments to type it here
// ...
}
}

.. http:get:: /api/v1/ansible/modules/
Get list of installed ansible modules.

:query filter: filter to search by module name. It is Python regular
expression.

Example request:

.. sourcecode:: http

GET /api/v1/ansible/modules/?filter=\.git HTTP/1.1
Host: example.com
Accept: application/json, text/javascript

Results:

.. sourcecode:: js

[
"extras.source_control.git_config",
"extras.source_control.github_release",
"extras.source_control.github_hooks",
"extras.source_control.gitlab_user",
"extras.source_control.github_key",
"extras.source_control.gitlab_group",
"extras.source_control.gitlab_project",
"core.source_control.git"
]

.. _variables:

Variables
Expand Down
2 changes: 1 addition & 1 deletion polemarch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.0.5"
__version__ = "0.0.6"

def _main(settings="polemarch.main.settings"):
# pylint: disable=unused-variable
Expand Down
41 changes: 37 additions & 4 deletions polemarch/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.db.models import Q
from django.db.models.query import QuerySet
from rest_framework import viewsets, views as rest_views
from rest_framework.reverse import reverse
from rest_framework.response import Response as RestResponse
from rest_framework.decorators import detail_route, list_route

Expand Down Expand Up @@ -48,12 +49,14 @@ def _base_get_queryset(self):
queryset = queryset.all()
return queryset

def get_user_aval_projects(self):
return self.request.user.related_objects.values_list('projects',
flat=True)

def _get_extra_queryset(self):
aval_projs = self.request.user.related_objects.values_list('projects',
flat=True)
return self.queryset.filter(
Q(related_objects__user=self.request.user) |
Q(related_objects__projects__in=aval_projs)
Q(related_objects__projects__in=self.get_user_aval_projects())
).distinct()

def get_queryset(self):
Expand Down Expand Up @@ -109,7 +112,7 @@ def get_paginated_route_response(self, queryset, serializer_class=None,
def permissions(self, request, pk=None):
# pylint: disable=unused-argument
serializer = self.get_serializer(self.get_object())
return serializer.permissions(request)
return serializer.permissions(request).resp

@list_route(methods=["post"])
def filter(self, request):
Expand Down Expand Up @@ -139,3 +142,33 @@ class HistoryModelViewSet(GenericViewSet,

class ModelViewSetSet(GenericViewSet, viewsets.ModelViewSet):
pass


class NonModelsViewSet(GenericViewSet):
base_name = None

def get_queryset(self):
return QuerySet()


class ListNonModelViewSet(NonModelsViewSet,
viewsets.mixins.ListModelMixin):

@property
def methods(self):
this_class_dict = ListNonModelViewSet.__dict__
obj_class_dict = self.__class__.__dict__
new_methods = list()
for name, attr in obj_class_dict.items():
detail = getattr(attr, 'detail', True)
if name not in this_class_dict and not detail:
new_methods.append(name.replace('_', "-"))
return new_methods

def list(self, request, *args, **kwargs):
routes = {
method: reverse("{}-{}".format(self.base_name, method),
request=request)
for method in self.methods
}
return Response(routes, 200).resp
3 changes: 3 additions & 0 deletions polemarch/api/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def __init__(self, *args, **kwargs):
super(_AbstractRouter, self).__init__(*args, **kwargs)

def get_default_base_name(self, viewset):
base_name = getattr(viewset, 'base_name', None)
if base_name is not None:
return base_name
queryset = getattr(viewset, 'queryset', None)
model = getattr(viewset, 'model', None)
if queryset is None:
Expand Down
1 change: 1 addition & 0 deletions polemarch/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
routerv1.register(r'periodic-tasks', v1.PeriodicTaskViewSet)
routerv1.register(r'templates', v1.TemplateViewSet)
routerv1.register(r'history', v1.HistoryViewSet)
routerv1.register(r'ansible', v1.AnsibleViewSet)
routerv1.register_view(r'token', v1.TokenView)
routerv1.register_view(r'_bulk', v1.BulkViewSet)

Expand Down
4 changes: 3 additions & 1 deletion polemarch/api/v1/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ class Meta:
'status',
'inventory',
'start_time',
'stop_time')
'stop_time',
'initiator',
'initiator_type')


class PeriodicTaskFilter(_BaseFilter):
Expand Down
Loading

0 comments on commit a3b66c0

Please sign in to comment.