blob: 030d57c03a40dd5e8d3857c33d2984633353e6ed [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
Tony Mack91463d92014-06-19 20:42:03 -04009from core.models.site import Site, Deployment
Tony Macke1509e82013-10-09 12:38:04 -040010
11class SyncNodes(OpenStackSyncStep):
12 provides=[Node]
13 requested_interval=0
14
15 def fetch_pending(self):
Tony Macke1509e82013-10-09 12:38:04 -040016 # collect local nodes
Tony Macke4be32f2014-03-11 20:45:25 -040017 sites = Site.objects.all()
Tony Macke1509e82013-10-09 12:38:04 -040018 nodes = Node.objects.all()
19 node_hostnames = [node.name for node in nodes]
20
Tony Macke4be32f2014-03-11 20:45:25 -040021 # fetch all nodes from each deployment
22 deployments = Deployment.objects.all()
Tony Mack026ffbe2014-05-07 13:31:55 -040023 new_nodes = []
Tony Macke4be32f2014-03-11 20:45:25 -040024 for deployment in deployments:
25 driver = self.driver.admin_driver(deployment=deployment.name)
26 compute_nodes = driver.shell.nova.hypervisors.list()
Tony Mack6d2a98c2014-06-03 21:08:39 -040027 for compute_node in compute_nodes:
28 if compute_node.hypervisor_hostname not in node_hostnames:
29 # XX TODO:figure out how to correctly identify a node's site.
30 # XX pick a random site to add the node to for now
31 site_index = random.randint(0, len(sites))
32 node = Node(name=compute_node.hypervisor_hostname,
33 site=sites[site_index], deployment=deployment)
34 new_nodes.append(node)
Tony Macke4be32f2014-03-11 20:45:25 -040035
36 return new_nodes
37
Tony Macke1509e82013-10-09 12:38:04 -040038
39 def sync_record(self, node):
40 node.save()
41