Sapan Bhatia | 26d40bc | 2014-05-12 15:28:02 -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 | # collect local nodes |
| 18 | sites = Site.objects.all() |
| 19 | one_and_only_deployment = Deployments.objects.all() |
| 20 | |
| 21 | node_hostnames = [node.name for node in nodes] |
| 22 | |
| 23 | instance_types = 'm1.small | m1.medium | m1.large | m1.xlarge | m3.medium | m3.large | m3.xlarge | m3.2xlarge'.split(' | ') |
| 24 | |
| 25 | all_new_nodes = [] |
| 26 | for s in sites: |
| 27 | node_names = [n.name for n in s.nodes] |
| 28 | new_node_names = list(set(instance_types) - set(node_names)) |
| 29 | new_nodes = [] |
| 30 | for node_name in new_node_names: |
| 31 | node = Node(name=node_name, |
| 32 | site=s, deployment=one_and_only_deployment) |
| 33 | new_nodes.append(node) |
| 34 | |
| 35 | all_new_nodes.extend(new_nodes) |
| 36 | |
| 37 | return all_new_nodes |
| 38 | |
| 39 | |
| 40 | def sync_record(self, node): |
| 41 | node.save() |
| 42 | |