Salt Stack with Django

Salt Stack with Django

Postby Jenny_V » Wed Aug 31, 2016 12:32 pm

Hi everyone!

I am having a bit of trouble setting up my salt api to be used in my django Rest framework application.
So what I have is a working django application, and I have a master and a lot of minions.
I have installed salt and salt api on the master and then did the following:

(1.) cloned django-saltapi from git hub and added django salt api to my installed_apps:
INSTALLED_APPS = (
[...]
'django_saltapi',
)
(2.) Added salt path in the config for the master :
SALT_CONFIG = {
'master_config': '/etc/salt/master',
}

(3.) included the url to be used :
url(r'^api/salt/', include('django_saltapi.urls')),

Step number 3 is strange for me because I do not use that syntax in my urls.py, My urls are without the urls() just r^ etc...
Still It doesn't show the page when I try to access it from localhost no matter what path I try.
The file is in my root where I have all other working stuff including another api(not salt)
Any thoughts?

Thanks,

Jenny
Jenny_V
 
Posts: 7
Joined: Wed Jul 20, 2016 5:30 am

Re: Salt Stack with Django

Postby nilamo » Wed Aug 31, 2016 4:49 pm

include(), used like this, takes a completely different urls.py, and attaches it to the end of whatever url fragment you have. So /salt/api/banana would check the included urls.py for a "banana" entry. That way, you can have modules included, base them on a url the rest of your site doesn't use, so it doesn't conflict with anything. Here's the doc: https://docs.djangoproject.com/en/1.10/ref/urls/#django.conf.urls.url.

As to your actual issue, I don't know. Could you share the entire urls.py you're using? And please, put it in [code] tags :)
This forum is shutting down. Future discussion should take place at http://python-forum.io
User avatar
nilamo
 
Posts: 87
Joined: Thu Jul 21, 2016 8:00 pm
Location: Michigan

Re: Salt Stack with Django

Postby Jenny_V » Thu Sep 01, 2016 11:51 am

Thanks nilamo for the brief!

as for my issue:

This is what I've got in urls.py
Code: Select all

from django.conf.urls import patterns, url
urlpatterns = patterns(url(r'^api/salt/', include('django_saltapi.urls')),
                                      r'^cdr_view/$', 'cdr_view),



Maybe it's in the wrong file?.. there are a lot of urls,py in all various files on the server..

I put mine this directory : /usr/share/cdrstats/django_saltapi/

I have an api that is located in the same location(/usr/share/cdrstats/g_invoice) and that works fine..
Thanks!

Jenny
Jenny_V
 
Posts: 7
Joined: Wed Jul 20, 2016 5:30 am

Re: Salt Stack with Django

Postby nilamo » Thu Sep 01, 2016 3:01 pm

Jenny_V wrote:
Code: Select all
from django.conf.urls import patterns, url
urlpatterns = patterns(...)

What is django.conf.urls.patterns(), and what's it supposed to do? I checked the docs, and couldn't find it mentioned anywhere. So I checked django's source, and didn't see it defined anywhere. I'm surprised you don't get errors, since it's apparently not a real thing. In most examples, urlpatterns is just a list of values. Like this:
Code: Select all
urlpatterns = [
    url(r'^api/salt/', include('django_saltapi.urls')),
    url(r'^cdr_view/$', 'cdr_view')
]
This forum is shutting down. Future discussion should take place at http://python-forum.io
User avatar
nilamo
 
Posts: 87
Joined: Thu Jul 21, 2016 8:00 pm
Location: Michigan

salt JSON data into a table

Postby Jenny_V » Sat Sep 10, 2016 6:18 pm

Hi,

I have a django project that works with saltapi.
I have a url that is named minions_info that communicates with minions_info Module in views.py
here is my output when I access localhost:

{"return": [{"taken.j.br.co": {"SwapTotal": {"value": "5603320", "unit": "kB"}, "SwapFree": {"value": "5603204", "unit": "kB"}, "MemFree": {"value": "481440", "unit": "kB"}, "HighTotal": {"value": "2664744", "unit": "kB"}, "HugePages_Rsvd": {"value": "0"}, "Committed_AS": {"value": "557872", "unit": "kB"}, "NFS_Unstable": {"value": "0", "unit": "kB"}, "Writeback": {"value": "0", "unit": "kB"}, "MemTotal": {"value": "3543716", "unit": "kB"}, "VmallocUsed": {"value": "9060", "unit": "kB"}, "HugePages_Free": {"value": "0"}, "Inactive": {"value": "458668", "unit": "kB"}, "Active": {"value": "2384836", "unit": "kB"}, "CommitLimit": {"value": "7375176", "unit": "kB"}, "Hugepagesize": {"value": "4096", "unit": "kB"}, "Cached": {"value": "2338492", "unit": "kB"}, "SwapCached": {"value": "0", "unit": "kB"}, "LowTotal": {"value": "878972", "unit": "kB"}, "Dirty": {"value": "408", "unit": "kB"}, "Mapped": {"value": "30716", "unit": "kB"}, "HighFree": {"value": "147128", "unit": "kB"}, "LowFree": {"value": "334312", "unit": "kB"}, "VmallocTotal": {"value": "114680", "unit": "kB"}, "Bounce": {"value": "0", "unit": "kB"}, "AnonPages": {"value": "167064", "unit": "kB"}, "PageTables": {"value": "5636", "unit": "kB"}, "HugePages_Total": {"value": "0"}, "Slab": {"value": "200720", "unit": "kB"}, "Buffers": {"value": "337880", "unit": "kB"}, "VmallocChunk": {"value": "104752", "unit": "kB"}}, "baren.j.br.co": {"SwapTotal":

I would like to take that info(which holds pillar info) into a table where I would be able to see the server name in the rows and some of the pillar information on the columns so that every row would eventually show all server info(mem,cpu etc.) in this case I'd like to take MemFree from each server(just the value).

Question is, how do I take it and show it in a nice looking table?

here is how my module in views.py looks like
Code: Select all
def minions_info(request):
ret = client.low([{'client': ' local', 'tgt': tgt, 'fun' : ' status.meminfo', 'timeout': '2'}])
return JsonResponse(ret)


Any help would be appreciated!

Jenny
Last edited by micseydel on Sat Sep 10, 2016 6:40 pm, edited 1 time in total.
Reason: Merged threads.
Jenny_V
 
Posts: 7
Joined: Wed Jul 20, 2016 5:30 am

Re: Salt Stack with Django

Postby Jenny_V » Sat Sep 10, 2016 6:27 pm

I ended up switching methods using pepper instead nad it worked, So thanks for the help!
Jenny_V
 
Posts: 7
Joined: Wed Jul 20, 2016 5:30 am


Return to Web Development

Who is online

Users browsing this forum: No registered users and 4 guests

cron