Commit 5255181d574d3e43759b1168c94d6c8f917fec17

Authored by Thanasis Naskos
1 parent 21a4a76571
Exists in master

Adding support for recognizing occupied dns names

Showing 2 changed files with 20 additions and 2 deletions

GanetiCluster.py View file @ 5255181
... ... @@ -130,8 +130,23 @@
130 130 images = json.loads(r.content)
131 131 return images
132 132  
  133 + def get_occupied_dns_names(self):
  134 + occupied = []
  135 + kwargs = {
  136 + "headers": headers,
  137 + "auth": (self.username, self.password),
  138 + "verify": False,
  139 + "params":"bulk=1"
  140 + }
  141 + r = requests.request("get", self.base_url+"instances", **kwargs)
  142 + list_answer = json.loads(r.content)
  143 + for i in range(0,len(list_answer)):
  144 + occupied.append(str(list_answer[i]['name']));
  145 + return occupied
  146 +
133 147 def run_instances(self, instance_count, os, disk, cpu, ram):
134   - return self.run_instances_names(self.utils.getFree_dns_names(int(instance_count)), os, disk, cpu, ram)
  148 + occupied = self.get_occupied_dns_names();
  149 + return self.run_instances_names(self.utils.getFree_dns_names(int(instance_count),occupied), os, disk, cpu, ram)
135 150  
136 151 def run_instances_names(self, names, os, disk, cpu, ram):
137 152 instances = []
... ... @@ -55,8 +55,11 @@
55 55 }
56 56 self.free_ips = self.mac_ip_mapping.keys()
57 57  
58   - def getFree_dns_names(self, count):
  58 + def getFree_dns_names(self, count, occupied=[]):
59 59 names = []
  60 + for ip in occupied:
  61 + if ip in self.free_ips:
  62 + self.free_ips.remove(ip)
60 63 if (count <= len(self.free_ips)):
61 64 for i in range(0,count):
62 65 names.append(self.free_ips.pop())