def __init__(self, args): settings, args = SynthesisServer.process_command_line(args) self.dbconn = DBConnector() self.basevm_list = self.check_basevm() Synthesis_Const.LOCAL_IPADDRESS = "0.0.0.0" server_address = (Synthesis_Const.LOCAL_IPADDRESS, Synthesis_Const.SERVER_PORT_NUMBER) self.allow_reuse_address = True try: SocketServer.TCPServer.__init__(self, server_address, SynthesisHandler) except socket.error as e: sys.stderr.write(str(e)) sys.stderr.write("Check IP/Port : %s\n" % (str(server_address))) sys.exit(1) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) LOG.info("* Server configuration") LOG.info(" - Open TCP Server at %s" % (str(server_address))) LOG.info(" - Disable Nagle(No TCP delay) : %s" \ % str(self.socket.getsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY))) LOG.info("-" * 50) # This is cloudlet discovery related part and separated out '''
def __init__(self, port_number=StreamSynthesisConst.SERVER_PORT_NUMBER, timeout=None, handoff_datafile=None): self.port_number = port_number self.timeout = timeout self._handoff_datafile = handoff_datafile if self._handoff_datafile: self.handoff_data = self._load_handoff_data(self._handoff_datafile) self.basevm_list = self.check_basevm( self.handoff_data.base_vm_paths, self.handoff_data.basevm_sha256_hash) else: self.handoff_data = None self.basevm_list = self.check_basevm_from_db(DBConnector()) server_address = ("0.0.0.0", self.port_number) self.allow_reuse_address = True try: SocketServer.TCPServer.__init__(self, server_address, StreamSynthesisHandler) except socket.error as e: sys.stderr.write(str(e)) sys.stderr.write("Check IP/Port : %s\n" % (str(server_address))) sys.exit(1) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) LOG.info("* Server configuration") LOG.info(" - Open TCP Server at %s" % (str(server_address))) LOG.info(" - Time out for waiting: %d" % (self.timeout)) LOG.info(" - Disable Nagle(No TCP delay) : %s" \ % str(self.socket.getsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY))) LOG.info("-" * 50)
def _get_matching_basevm(basedisk_path): dbconn = DBConnector() basedisk_path = os.path.abspath(basedisk_path) basevm_list = dbconn.list_item(BaseVM) ret_basevm = None for item in basevm_list: if basedisk_path == item.disk_path: ret_basevm = item break return dbconn, ret_basevm
def import_basevm(filename): filename = os.path.abspath(filename) (base_hashvalue, disk_name, memory_name, diskhash_name, memoryhash_name) = \ PackagingUtil._get_basevm_attribute(filename) # check directory base_vm_dir = os.path.join(os.path.dirname(Const.BASE_VM_DIR), base_hashvalue) temp_dir = mkdtemp(prefix="cloudlet-base-") disk_tmp_path = os.path.join(temp_dir, disk_name) disk_target_path = os.path.join(base_vm_dir, disk_name) dbconn, matching_basevm = PackagingUtil._get_matching_basevm( disk_target_path) if matching_basevm != None: LOG.info("Base VM is already exists") LOG.info("Delete existing Base VM using command") LOG.info("See more 'cloudlet --help'") return None if not os.path.exists(base_vm_dir): LOG.info("create directory for base VM") os.makedirs(base_vm_dir) # decompress LOG.info("Decompressing Base VM to temp directory at %s" % temp_dir) zipbase = zipfile.ZipFile(_FileFile("file:///%s" % filename), 'r') zipbase.extractall(temp_dir) shutil.move(disk_tmp_path, disk_target_path) (target_diskhash, target_memory, target_memoryhash) = \ Const.get_basepath(disk_target_path, check_exist=False) path_list = { os.path.join(temp_dir, memory_name): target_memory, os.path.join(temp_dir, diskhash_name): target_diskhash, os.path.join(temp_dir, memoryhash_name): target_memoryhash, } LOG.info("Place base VM to the right directory") for (src, dest) in path_list.iteritems(): shutil.move(src, dest) # add to DB dbconn = DBConnector() LOG.info("Register New Base to DB") LOG.info("ID for the new Base VM: %s" % base_hashvalue) new_basevm = BaseVM(disk_target_path, base_hashvalue) LOG.info("Success") dbconn.add_item(new_basevm) return disk_target_path, base_hashvalue