Tony Mack | e1509e8 | 2013-10-09 12:38:04 -0400 | [diff] [blame] | 1 | import os |
| 2 | import base64 |
| 3 | import random |
| 4 | from datetime import datetime |
| 5 | from django.db.models import F, Q |
| 6 | from planetstack.config import Config |
| 7 | from observer.openstacksyncstep import OpenStackSyncStep |
| 8 | from core.models.node import Node |
| 9 | from core.models.deployment import Deployment |
| 10 | from core.models.site import Site |
| 11 | |
| 12 | class 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 | |