blob: a1f08030958aad7bedd376e058fa451596a5c6fd [file] [log] [blame]
Tony Macke1509e82013-10-09 12:38:04 -04001import os
2import base64
3import random
4from datetime import datetime
5from django.db.models import F, Q
6from planetstack.config import Config
7from observer.openstacksyncstep import OpenStackSyncStep
8from core.models.node import Node
9from core.models.deployment import Deployment
10from core.models.site import Site
11
12class SyncNodes(OpenStackSyncStep):
13 provides=[Node]
14 requested_interval=0
15
16 def fetch_pending(self):
17 config = Config()
18 deployment = Deployment.objects.filter(name=config.plc_deployment)[0]
19 login_bases = ['princeton', 'stanford', 'gt', 'uw', 'mpisws']
20 sites = Site.objects.filter(login_base__in=login_bases)
21
22 # collect local nodes
23 nodes = Node.objects.all()
24 node_hostnames = [node.name for node in nodes]
25
26 # collect nova nodes
27 # generate list of new nodes
28 new_nodes = []
29 compute_nodes = self.driver.shell.nova.hypervisors.list()
30 for compute_node in compute_nodes:
31 if compute_node.hypervisor_hostname not in node_hostnames:
32 # pick a random site to add the node to for now
33 site_index = random.randint(0, len(sites))
34 node = Node(name=compute_node.hypervisor_hostname,
35 site=sites[site_index], deployment=deployment)
36 new_nodes.append(node)
37
38 return new_nodes
39
40 def sync_record(self, node):
41 node.save()
42