blob: 342b08ed0564bfbe6288341cd4495c63b176dc91 [file] [log] [blame]
Tony Mack735493a2013-04-04 23:54:28 -04001from plstackapi.planetstack import settings
2from django.core import management
3management.setup_environ(settings)
Tony Mack48952032013-04-12 11:49:34 -04004from plstackapi.openstack.client import OpenStackClient
Tony Mack735493a2013-04-04 23:54:28 -04005
6
7class Manager:
8
9 def __init__(self):
10
Tony Mack48952032013-04-12 11:49:34 -040011 self.client = OpenStackClient()
Tony Mack735493a2013-04-04 23:54:28 -040012
13 def refresh_nodes(self):
14 # collect local nodes
Tony Mack48952032013-04-12 11:49:34 -040015 from plstackapi.core.models import Node
16 from plstackapi.core.models import DeploymentNetwork
17 from plstackapi.core.models import Site
Tony Mack735493a2013-04-04 23:54:28 -040018 nodes = Node.objects.all()
19 nodes_dict = {}
20 for node in nodes:
Tony Mack48952032013-04-12 11:49:34 -040021 if 'viccidev10' not in node.name:
22 nodes_dict[node.name] = node
23
Tony Mack51f113d2013-04-13 02:02:22 -040024 deployment = DeploymentNetwork.objects.filter(name='VICCI')[0]
Tony Mack48952032013-04-12 11:49:34 -040025 login_bases = ['princeton', 'stanford', 'gt', 'uw', 'mpisws']
26 sites = Site.objects.filter(login_base__in=login_bases)
Tony Mack735493a2013-04-04 23:54:28 -040027 # collect nova nodes:
Tony Mack48952032013-04-12 11:49:34 -040028 compute_nodes = self.client.nova.hypervisors.list()
29
Tony Mack735493a2013-04-04 23:54:28 -040030 compute_nodes_dict = {}
31 for compute_node in compute_nodes:
32 compute_nodes_dict[compute_node.hypervisor_hostname] = compute_node
33
34 # add new nodes:
35 new_node_names = set(compute_nodes_dict.keys()).difference(nodes_dict.keys())
Tony Mack51f113d2013-04-13 02:02:22 -040036 i = 0
37 max = len(sites)
Tony Mack735493a2013-04-04 23:54:28 -040038 for name in new_node_names:
Tony Mack51f113d2013-04-13 02:02:22 -040039 if i == max:
40 i = 0
41 site = sites[i]
42 node = Node(name=compute_nodes_dict[name].hypervisor_hostname,
43 site=site,
44 deploymentNetwork=deployment)
Tony Mack735493a2013-04-04 23:54:28 -040045 node.save()
Tony Mack51f113d2013-04-13 02:02:22 -040046 i+=1
Tony Mack735493a2013-04-04 23:54:28 -040047
48 # remove old nodes
49 old_node_names = set(nodes_dict.keys()).difference(compute_nodes_dict.keys())
50 Node.objects.filter(name__in=old_node_names).delete()
51
52 def refresh_flavors(self):
53 # collect local flavors
Tony Mack48952032013-04-12 11:49:34 -040054 from plstackapi.core.models import Flavor
Tony Mack735493a2013-04-04 23:54:28 -040055 flavors = Flavor.objects.all()
56 flavors_dict = {}
57 for flavor in flavors:
58 flavors_dict[flavor.name] = flavor
59
60 # collect nova falvors
Tony Mack48952032013-04-12 11:49:34 -040061 nova_flavors = self.client.nova.flavors.list()
Tony Mack735493a2013-04-04 23:54:28 -040062 nova_flavors_dict = {}
63 for nova_flavor in nova_flavors:
64 nova_flavors_dict[nova_flavor.name] = nova_flavor
65
66 # add new flavors
67 new_flavor_names = set(nova_flavors_dict.keys()).difference(flavors_dict.keys())
68 for name in new_flavor_names:
69
70 flavor = Flavor(flavor_id=nova_flavors_dict[name].id,
71 name=nova_flavors_dict[name].name,
72 memory_mb=nova_flavors_dict[name].ram,
73 disk_gb=nova_flavors_dict[name].disk,
74 vcpus=nova_flavors_dict[name].vcpus)
75 flavor.save()
76
77 # remove old flavors
78 old_flavor_names = set(flavors_dict.keys()).difference(nova_flavors_dict.keys())
79 Flavor.objects.filter(name__in=old_flavor_names).delete()
80
81 def refresh_images(self):
82 # collect local images
Tony Mack48952032013-04-12 11:49:34 -040083 from plstackapi.core.models import Image
Tony Mack735493a2013-04-04 23:54:28 -040084 images = Image.objects.all()
85 images_dict = {}
86 for image in images:
87 images_dict[image.name] = image
88
89 # collect glance images
Tony Mack48952032013-04-12 11:49:34 -040090 glance_images = self.client.glance.get_images()
Tony Mack735493a2013-04-04 23:54:28 -040091 glance_images_dict = {}
92 for glance_image in glance_images:
93 glance_images_dict[glance_image['name']] = glance_image
94
95 # add new images
96 new_image_names = set(glance_images_dict.keys()).difference(images_dict.keys())
97 for name in new_image_names:
98 image = Image(image_id=glance_images_dict[name]['id'],
99 name=glance_images_dict[name]['name'],
100 disk_format=glance_images_dict[name]['disk_format'],
101 container_format=glance_images_dict[name]['container_format'])
102 image.save()
103
104 # remove old images
105 old_image_names = set(images_dict.keys()).difference(glance_images_dict.keys())
106 Image.objects.filter(name__in=old_image_names).delete()