diff --git a/GanetiCluster.py b/GanetiCluster.py index 9c35a3d..821b8b5 100755 --- a/GanetiCluster.py +++ b/GanetiCluster.py @@ -130,8 +130,23 @@ class GanetiCluster(object): images = json.loads(r.content) return images + def get_occupied_dns_names(self): + occupied = [] + kwargs = { + "headers": headers, + "auth": (self.username, self.password), + "verify": False, + "params":"bulk=1" + } + r = requests.request("get", self.base_url+"instances", **kwargs) + list_answer = json.loads(r.content) + for i in range(0,len(list_answer)): + occupied.append(str(list_answer[i]['name'])); + return occupied + def run_instances(self, instance_count, os, disk, cpu, ram): - return self.run_instances_names(self.utils.getFree_dns_names(int(instance_count)), os, disk, cpu, ram) + occupied = self.get_occupied_dns_names(); + return self.run_instances_names(self.utils.getFree_dns_names(int(instance_count),occupied), os, disk, cpu, ram) def run_instances_names(self, names, os, disk, cpu, ram): instances = [] diff --git a/Utils.py b/Utils.py index 4faa0e3..0abfc2d 100644 --- a/Utils.py +++ b/Utils.py @@ -55,8 +55,11 @@ class Utils(object): } self.free_ips = self.mac_ip_mapping.keys() - def getFree_dns_names(self, count): + def getFree_dns_names(self, count, occupied=[]): names = [] + for ip in occupied: + if ip in self.free_ips: + self.free_ips.remove(ip) if (count <= len(self.free_ips)): for i in range(0,count): names.append(self.free_ips.pop())