blob: f09ec83eed83717d8890f8e496fc7222d45261fc [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 Macke1509e82013-10-09 12:38:04 -040028 if compute_node.hypervisor_hostname not in node_hostnames:
Tony Macke4be32f2014-03-11 20:45:25 -040029 # 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
Tony Macke1509e82013-10-09 12:38:04 -040031 site_index = random.randint(0, len(sites))
Tony Macke4be32f2014-03-11 20:45:25 -040032 node = Node(name=compute_node.hypervisor_hostname,
Tony Macke1509e82013-10-09 12:38:04 -040033 site=sites[site_index], deployment=deployment)
Tony Macke4be32f2014-03-11 20:45:25 -040034 new_nodes.append(node)
35
36 return new_nodes
37
Tony Macke1509e82013-10-09 12:38:04 -040038
39 def sync_record(self, node):
40 node.save()
41