blob: bef0ca0cd2518b2bbea08dfa47d44e02fe63ff0a [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()
24 for deployment in deployments:
25 driver = self.driver.admin_driver(deployment=deployment.name)
26 compute_nodes = driver.shell.nova.hypervisors.list()
Tony Macke1509e82013-10-09 12:38:04 -040027 if compute_node.hypervisor_hostname not in node_hostnames:
Tony Macke4be32f2014-03-11 20:45:25 -040028 # XX TODO:figure out how to correctly identify a node's site.
29 # XX pick a random site to add the node to for now
Tony Macke1509e82013-10-09 12:38:04 -040030 site_index = random.randint(0, len(sites))
Tony Macke4be32f2014-03-11 20:45:25 -040031 node = Node(name=compute_node.hypervisor_hostname,
Tony Macke1509e82013-10-09 12:38:04 -040032 site=sites[site_index], deployment=deployment)
Tony Macke4be32f2014-03-11 20:45:25 -040033 new_nodes.append(node)
34
35 return new_nodes
36
Tony Macke1509e82013-10-09 12:38:04 -040037
38 def sync_record(self, node):
39 node.save()
40