def __create_instances(self, dep_id, common_section, config_sections): emailid = common_section.emailid instance_user_name = common_section.instance_user_name # Launch instances for section in config_sections: section_name = section.section_name count = int(section.count) tag = section.tag machinetype = section.machinetype disk1image = section.disk1image disk2image = section.disk2image disk1type = section.disk1type disk2type = section.disk2type disk1size = section.disk1size disk2size = section.disk2size for num in range(count): instance_name = emailid + "-" + dep_id + "-" + section_name + "-" + tag + "-" + str(num) disk1 = Disk(instance_name + "-d1", disk1image, disk1size, disk1type) disk2 = Disk(instance_name + "-d2", disk2image, disk2size, disk2type) disk1.create() disk2.create() disk_list = [disk1, disk2] instance = Instance(instance_name, disk_list, machinetype, instance_user_name) instance.create(common_section) if section_name == "master": self.master_instances.append(instance) else: self.slave_instances.append(instance) self.instances.append(instance)
def __create_instances(self, dep_id, common_section, config_sections): emailid = common_section.emailid instance_user_name = common_section.instance_user_name # Launch instances for section in config_sections: section_name = section.section_name count = int(section.count) tag = section.tag machinetype = section.machinetype disk1image = section.disk1image disk2image = section.disk2image disk1type = section.disk1type disk2type = section.disk2type disk1size = section.disk1size disk2size = section.disk2size for num in range(count): instance_name = emailid + "-" + dep_id + "-" + section_name + "-" + tag + "-" + str( num) disk1 = Disk(instance_name + "-d1", disk1image, disk1size, disk1type) disk2 = Disk(instance_name + "-d2", disk2image, disk2size, disk2type) disk1.create() disk2.create() disk_list = [disk1, disk2] instance = Instance(instance_name, disk_list, machinetype, instance_user_name) instance.create(common_section) if section_name == "master": self.master_instances.append(instance) else: self.slave_instances.append(instance) self.instances.append(instance)
def create(self, image=None, flavor_type=None, ssh_access=None, nics=None, az=None, management_network_name=None, sec_group=None, init_file_name=None): '''Create an instance :return: True on success, False on error ''' rc = Instance.create(self, image, flavor_type, ssh_access, nics, az, management_network_name, sec_group, init_file_name) if not rc: return False if self.tp_tool and not self.tp_tool.install(): return False self.add_multicast_route() if not self.is_server: return True if self.tp_tool and not self.tp_tool.start_server(): return False return True
def create( self, image=None, flavor_type=None, ssh_access=None, nics=None, az=None, management_network_name=None, sec_group=None, init_file_name=None, ): """Create an instance :return: True on success, False on error """ rc = Instance.create( self, image, flavor_type, ssh_access, nics, az, management_network_name, sec_group, init_file_name ) if not rc: return False if self.tp_tool and not self.tp_tool.install(): return False self.add_multicast_route() if not self.is_server: return True if self.tp_tool and not self.tp_tool.start_server(): return False return True
def create(self, image=None, flavor_type=None, keypair=None, nics=None, az=None, management_network_name=None, sec_group=None, init_file_name=None): '''Create an instance :return: True on success, False on error ''' rc = Instance.create(self, image, flavor_type, keypair, nics, az, management_network_name, sec_group, init_file_name) if not rc: return False if self.tp_tool and not self.tp_tool.install(): return False if not self.is_server: return True if self.tp_tool and not self.tp_tool.start_server(): return False return True
def __createVM(self, request): user_name = request.get("user_name") instance_id = "%s-%s" % (user_name, request.get("instance_id")) memory = request.get("memory") # MiB disk_size = request.get("disk_size") linux = request.get("OSType") passwd = request.get("passwd") vcpu = request.get("vcpu") network = user_name # get vm sequence col = self.db[user_name] vnet = col.find_one({"name": user_name, "type": "vnet"}) gateway = vnet.get('gateway') gateway_int = utils.htoi(gateway) seq = vnet.get('seq') private_ip = utils.itoh(gateway_int + seq) nameserver = utils.itoh(gateway_int) net_segment = utils.itoh(gateway_int - 1) broadcast = utils.itoh(gateway_int + 254) col = self.db["system_info"] ip_info = col.find_one({"type": "ip_info"}) ip_start = ip_info.get("ip_start") ip_current = ip_info.get("current") + 1 public_ip = utils.itoh(utils.htoi(ip_start) + ip_current) cloud_init_dict = { "instance_id": instance_id, "passwd": passwd, "private_ip": private_ip, "net_segment": net_segment, "nameserver": nameserver, "broadcast": broadcast, "gateway": gateway } img = self.__createDisk(linux, instance_id, disk_size) cloud_init = self.__createCloudInit(cloud_init_dict) instance_dict = { "user_name": user_name, "instance_id": instance_id, "network": network, "vcpu": vcpu, "os": linux, "img": img, "memory": memory, "private_ip": private_ip, "public_ip": public_ip, "cloud_init": cloud_init, "gateway": gateway } instance = Instance() instance.create(instance_dict) mongo_dict = { "name": instance_id, "instance_id": instance_id, "user_name": user_name, "network": network, "vcpu": vcpu, "memory": memory, "cloud_init": cloud_init, "gateway": gateway, "type": "VM", "private_ip": private_ip, "img": img, "os": linux } print user_name query = {"name": user_name, "type": "vnet"} new_value = {"$set": {"seq": seq + 1}} col = self.db[user_name] col.insert(mongo_dict) col.update(query, new_value) col = self.db["system_info"] col.update({"type": "ip_info"}, {"$set": {"current": ip_current}}) col = self.db["route"] route = { "public": public_ip, "private": private_ip, "instance_id": instance_id } col.insert(route) command1 = "iptables -t nat -A PREROUTING -s %s -j DNAT --to-destination %s" % ( public_ip, private_ip) command2 = "iptables -t nat -A POSTROUTING -d %s -j SNAT --to %s" % ( private_ip, public_ip) os.system(command1) os.system(command2) pass