blob: ecd32b4712afd6c546ce40fca88f0212067433cd [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):
Tony Macke1509e82013-10-09 12:38:04 -040017 # collect local nodes
Tony Macke4be32f2014-03-11 20:45:25 -040018 sites = Site.objects.all()
Tony Macke1509e82013-10-09 12:38:04 -040019 nodes = Node.objects.all()
20 node_hostnames = [node.name for node in nodes]
21
Tony Macke4be32f2014-03-11 20:45:25 -040022 # fetch all nodes from each deployment
23 deployments = Deployment.objects.all()
Tony Mack026ffbe2014-05-07 13:31:55 -040024 new_nodes = []
Tony Macke4be32f2014-03-11 20:45:25 -040025 for deployment in deployments:
26 driver = self.driver.admin_driver(deployment=deployment.name)
27 compute_nodes = driver.shell.nova.hypervisors.list()
Tony Mack6d2a98c2014-06-03 21:08:39 -040028 for compute_node in compute_nodes:
29 if compute_node.hypervisor_hostname not in node_hostnames:
30 # XX TODO:figure out how to correctly identify a node's site.
31 # XX pick a random site to add the node to for now
32 site_index = random.randint(0, len(sites))
33 node = Node(name=compute_node.hypervisor_hostname,
34 site=sites[site_index], deployment=deployment)
35 new_nodes.append(node)
Tony Macke4be32f2014-03-11 20:45:25 -040036
37 return new_nodes
38
Tony Macke1509e82013-10-09 12:38:04 -040039
40 def sync_record(self, node):
41 node.save()
42