Skip to content

Commit

Permalink
Record the OS Family (prep for integration with PuppetDB).
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamgilbert committed Apr 30, 2014
1 parent 21fdd22 commit ddfbe47
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 17 deletions.
6 changes: 6 additions & 0 deletions sal/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@
)
if settings.DEBUG:
urlpatterns += staticfiles_urlpatterns()

if 'config' in settings.INSTALLED_APPS:
config_pattern = patterns('',
url(r'^config/', include('config.urls'))
)
urlpatterns += config_pattern
2 changes: 1 addition & 1 deletion scripts/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
USE_PKGBUILD=1
include /usr/local/share/luggage/luggage.make
VERSION=0.0.6
PACKAGE_VERSION=0.1.0
TITLE=sal_scripts
PACKAGE_NAME=sal_scripts
REVERSE_DOMAIN=com.grahamgilbert
Expand Down
3 changes: 3 additions & 0 deletions scripts/postflight
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ task = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
name = stdout
data = {}

# Set the OS family
report['os_family'] = 'Darwin'

# Compress the report
plist = FoundationPlist.writePlistToString(report)
zipped = bz2.compress(plist)
Expand Down
138 changes: 138 additions & 0 deletions server/migrations/0018_auto__add_field_machine_os_family.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models


class Migration(SchemaMigration):

def forwards(self, orm):
# Adding field 'Machine.os_family'
db.add_column(u'server_machine', 'os_family',
self.gf('django.db.models.fields.CharField')(max_length=256, null=True, blank=True),
keep_default=False)


def backwards(self, orm):
# Deleting field 'Machine.os_family'
db.delete_column(u'server_machine', 'os_family')


models = {
u'auth.group': {
'Meta': {'object_name': 'Group'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
u'auth.permission': {
'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
u'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
u'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
u'server.businessunit': {
'Meta': {'ordering': "['name']", 'object_name': 'BusinessUnit'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'users': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.User']", 'symmetrical': 'False'})
},
u'server.condition': {
'Meta': {'ordering': "['condition_name']", 'object_name': 'Condition'},
'condition_data': ('django.db.models.fields.TextField', [], {}),
'condition_name': ('django.db.models.fields.TextField', [], {}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'machine': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['server.Machine']"})
},
u'server.fact': {
'Meta': {'ordering': "['fact_name']", 'object_name': 'Fact'},
'fact_data': ('django.db.models.fields.TextField', [], {}),
'fact_name': ('django.db.models.fields.TextField', [], {}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'machine': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['server.Machine']"})
},
u'server.machine': {
'Meta': {'ordering': "['hostname']", 'object_name': 'Machine'},
'activity': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
'console_user': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
'cpu_speed': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
'cpu_type': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
'errors': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'hd_percent': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
'hd_space': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
'hd_total': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
'hostname': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'last_checkin': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'last_puppet_run': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'machine_group': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['server.MachineGroup']"}),
'machine_model': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
'manifest': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
'memory': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
'memory_kb': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'munki_version': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
'operating_system': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
'os_family': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
'puppet_errors': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'puppet_version': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
'report': ('django.db.models.fields.TextField', [], {'null': 'True'}),
'serial': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'}),
'warnings': ('django.db.models.fields.IntegerField', [], {'default': '0'})
},
u'server.machinegroup': {
'Meta': {'ordering': "['name']", 'object_name': 'MachineGroup'},
'business_unit': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['server.BusinessUnit']"}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
u'server.pendingappleupdate': {
'Meta': {'ordering': "['display_name']", 'unique_together': "(('machine', 'update'),)", 'object_name': 'PendingAppleUpdate'},
'display_name': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'machine': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['server.Machine']"}),
'update': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
'update_version': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'})
},
u'server.pendingupdate': {
'Meta': {'ordering': "['display_name']", 'unique_together': "(('machine', 'update'),)", 'object_name': 'PendingUpdate'},
'display_name': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'machine': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['server.Machine']"}),
'update': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
'update_version': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'})
},
u'server.userprofile': {
'Meta': {'object_name': 'UserProfile'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'level': ('django.db.models.fields.CharField', [], {'default': "'SO'", 'max_length': '2'}),
'user': ('django.db.models.fields.related.OneToOneField', [], {'to': u"orm['auth.User']", 'unique': 'True'})
}
}

complete_apps = ['server']
1 change: 1 addition & 0 deletions server/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Machine(models.Model):
machine_model = models.CharField(max_length=256, null=True, blank=True)
cpu_type = models.CharField(max_length=256, null=True, blank=True)
cpu_speed = models.CharField(max_length=256, null=True, blank=True)
os_family = models.CharField(max_length=256, null=True, blank=True)
last_checkin = models.DateTimeField(blank=True,null=True)
report = models.TextField(editable=True, null=True)
errors = models.IntegerField(default=0)
Expand Down
4 changes: 4 additions & 0 deletions server/templates/server/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
{% block nav %}
{% if user.userprofile.level == 'GA' %}
<li><a href="{% url 'new_business_unit' %}">New Business Unit</a></li>
{% if config_installed %}
<li><a href="{% url 'config_index' %}">Configure Machines</a></li>
{% endif %}
{% endif %}

{% endblock %}
{% block content %}
<div class="row">
Expand Down
7 changes: 6 additions & 1 deletion server/templates/server/machine_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
{% endblock %}

{% block nav %}
{% if config_installed %}
<li><a href="{% url 'config_configure_machine' machine.id %}">Configure Machine</a></li>
{% endif %}
{% endblock %}
{% block content %}
<div class="row">
Expand Down Expand Up @@ -62,7 +65,9 @@ <h3>Machine</h3>
</tr>
<tr>
<th>OS version:</th>
<td>{{ report.MachineInfo.os_vers }}
<td>{% if report.os_family == 'Darwin' %}
OS X {% endif %}
{{ report.MachineInfo.os_vers }}
{{ report.MachineInfo.arch }}</td>
</tr>
{% endif %}
Expand Down
15 changes: 11 additions & 4 deletions server/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ def index(request):

# get the user level - if they're a global admin, show all of the machines. If not, show only the machines they have access to
business_units = BusinessUnit.objects.all()
config_installed = 'config' in settings.INSTALLED_APPS

c = {'user': request.user, 'business_units': business_units, 'output': output}
c = {'user': request.user, 'business_units': business_units, 'output': output, 'config_installed': config_installed}
return render_to_response('server/index.html', c, context_instance=RequestContext(request))

# Plugin machine list
Expand Down Expand Up @@ -482,8 +483,8 @@ def machine_detail(request, machine_id):

if 'managed_uninstalls_list' in report:
report['managed_uninstalls_list'].sort()

c = {'user':user, 'machine_group': machine_group, 'business_unit': business_unit, 'report': report, 'install_results': install_results, 'removal_results': removal_results, 'machine': machine, 'facts':facts, 'conditions':conditions, 'ip_address':ip_address }
config_installed = 'config' in settings.INSTALLED_APPS
c = {'user':user, 'machine_group': machine_group, 'business_unit': business_unit, 'report': report, 'install_results': install_results, 'removal_results': removal_results, 'machine': machine, 'facts':facts, 'conditions':conditions, 'ip_address':ip_address, 'config_installed':config_installed }
return render_to_response('server/machine_detail.html', c, context_instance=RequestContext(request))

# checkin
Expand Down Expand Up @@ -515,7 +516,10 @@ def checkin(request):
machine = Machine(serial=serial)
if machine:
machine.hostname = data.get('name', '<NO NAME>')
machine.machine_group = machine_group
if not settings.USE_ENC:
# If we're using Sal's Puppet ENC, don't change the machine group,
# as we're setting it in the GUI
machine.machine_group = machine_group
machine.last_checkin = datetime.now()
if 'username' in data:
machine.username = data.get('username')
Expand Down Expand Up @@ -567,6 +571,9 @@ def checkin(request):
if hwinfo.get('physical_memory')[-2:] == 'TB':
memory_tb = float(hwinfo.get('physical_memory')[:-3])
machine.memory_kb = int(memory_tb * 1024 * 1024 * 1024)

if 'os_family' in report_data:
machine.os_family = report_data['os_family']

machine.save()

Expand Down
4 changes: 4 additions & 0 deletions site_static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ h1, h2, h3, h4, h5, h6, h3 a{

legend {
padding-top: 10px;
}

legend a.pull-right{
margin-top:10px
}
19 changes: 8 additions & 11 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}jquery.dataTables.min.js"></script>
{% bootstrap_javascript_tag %}

<script type="text/javascript" src="{{ STATIC_URL }}datatables-bootstrap.js"></script>
{% block script %}
{% endblock%}

</head>

Expand Down Expand Up @@ -106,16 +114,5 @@ <h2>Heading</h2>

</div> <!-- /container -->

<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}jquery.dataTables.min.js"></script>
{% bootstrap_javascript_tag %}

<script type="text/javascript" src="{{ STATIC_URL }}datatables-bootstrap.js"></script>
{% block script %}
{% endblock%}
</body>
</html>

0 comments on commit ddfbe47

Please sign in to comment.