-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
102 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
from mountain.core import registration | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,38 @@ | ||
import uuid, string | ||
import string | ||
import uuid | ||
from random import choice | ||
|
||
from django.utils.simplejson import dumps | ||
|
||
from taggit.utils import parse_tags | ||
|
||
from mountain.core.models import Computer, Company, Message | ||
from mountain.core.models import Computer, Company | ||
from mountain.core.signals import message_available | ||
from mountain.core.utils import MessageType, hash_types | ||
|
||
CHARS = string.ascii_letters + string.digits + string.punctuation | ||
|
||
|
||
def handle_registration(sender, computer, request_data, msg_data, **kwargs): | ||
try: | ||
company = Company.objects.get(account_name=msg_data['account_name']) | ||
except Company.DoesNotExist: | ||
return [{'type':'registration', 'info':'unknown-account'}] | ||
return [{'type':'registration', 'info':'unknown-account'}] | ||
|
||
if msg_data['registration_password'] != company.registration_password: | ||
return [{'type':'registration', 'info':'unknown-account'}] | ||
|
||
comp = Computer() | ||
comp.hostname=msg_data['hostname'] | ||
comp.company=company | ||
comp.computer_title=msg_data['computer_title'] | ||
comp.secure_id= ''.join([choice(CHARS) for i in range(1600)]) | ||
comp.insecure_id=str(uuid.uuid4()) | ||
comp.client_accepted_types_hash = hash_types(request_data['client-accepted-types']).encode('hex') | ||
comp.hostname = msg_data['hostname'] | ||
comp.company = company | ||
comp.computer_title = msg_data['computer_title'] | ||
comp.secure_id = ''.join([choice(CHARS) for i in range(1600)]) | ||
comp.insecure_id = str(uuid.uuid4()) | ||
comp.client_accepted_types_hash = \ | ||
hash_types(request_data['client-accepted-types']).encode('hex') | ||
comp.save() | ||
comp.tags.set(*parse_tags(msg_data['tags'])) | ||
|
||
return [{'type':'set-id', 'id':comp.secure_id, | ||
'insecure-id':comp.insecure_id}] | ||
|
||
|
||
message_available.connect(handle_registration, sender=MessageType("register")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import django.dispatch | ||
|
||
message_available = django.dispatch.Signal(providing_args=['computer', 'request_data', 'msg_data']) | ||
message_available = django.dispatch.Signal(providing_args=['computer', | ||
'request_data', 'msg_data']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,26 @@ | ||
from mountain.core.signals import message_available | ||
from mountain.core.utils import MessageType, register_messagetype | ||
from mountain.core.utils import MessageType | ||
from mountain.monitor.models import ComputerInfo | ||
|
||
|
||
def handle_computer_info(sender, computer, request_data, msg_data, **kwargs): | ||
comp_info, created = ComputerInfo.objects.get_or_create(computer=computer) | ||
for i in ['total-memory', 'total-swap', 'hostname']: | ||
setattr(comp_info, i.replace('-','_'), msg_data[i]) | ||
setattr(comp_info, i.replace('-', '_'), msg_data[i]) | ||
computer.hostname = msg_data['hostname'] | ||
comp_info.save() | ||
return [] | ||
|
||
|
||
def handle_distribution_info(sender, computer, request_data, msg_data, **kwargs): | ||
dist_info, created = ComputerInfo.objects.get_or_create(computer=computer) | ||
for i in ['code-name', 'description', 'distributor-id', 'release'] : | ||
setattr(dist_info, i.replace('-','_'), msg_data[i]) | ||
for i in ['code-name', 'description', 'distributor-id', 'release']: | ||
setattr(dist_info, i.replace('-', '_'), msg_data[i]) | ||
dist_info.save() | ||
return [] | ||
|
||
message_available.connect(handle_computer_info, sender=MessageType('computer-info')) | ||
message_available.connect(handle_distribution_info, sender=MessageType('distribution-info')) | ||
|
||
message_available.connect(handle_computer_info, | ||
sender=MessageType('computer-info')) | ||
message_available.connect(handle_distribution_info, | ||
sender=MessageType('distribution-info')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.