def umount(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = UnmountResponse() if linux.is_mounted(path=cmd.mountPath): ret = linux.umount(cmd.mountPath) if not ret: logger.warn(http.path_msg(self.UNMOUNT_PATH, 'unmount %s from %s failed' % (cmd.mountPath, cmd.url))) logger.debug(http.path_msg(self.UNMOUNT_PATH, 'umounted %s from %s' % (cmd.mountPath, cmd.url))) return jsonobject.dumps(rsp)
def connect(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = ConnectResponse() # page table extension if shell.run('lscpu | grep -q -w GenuineIntel') == 0: new_ept = False if cmd.pageTableExtensionDisabled else True rsp.error = self._set_intel_ept(new_ept) if rsp.error is not None: rsp.success = False return jsonobject.dumps(rsp) self.host_uuid = cmd.hostUuid self.config[kvmagent.HOST_UUID] = self.host_uuid self.config[kvmagent.SEND_COMMAND_URL] = cmd.sendCommandUrl Report.serverUuid = self.host_uuid Report.url = cmd.sendCommandUrl logger.debug(http.path_msg(self.CONNECT_PATH, 'host[uuid: %s] connected' % cmd.hostUuid)) rsp.libvirtVersion = self.libvirt_version rsp.qemuVersion = self.qemu_version # create udev rule self.handle_usb_device_events() ignore_msrs = 1 if cmd.ignoreMsrs else 0 shell.run("/bin/echo %s > /sys/module/kvm/parameters/ignore_msrs" % ignore_msrs) vm_plugin.cleanup_stale_vnc_iptable_chains() apply_iptables_result = self.apply_iptables_rules(cmd.iptablesRules) rsp.iptablesSucc = apply_iptables_result return jsonobject.dumps(rsp)
def connect(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) self.host_uuid = cmd.hostUuid logger.debug(http.path_msg(self.CONNECT_PATH, 'host[uuid: %s] connected' % cmd.hostUuid)) rsp = ConnectResponse() rsp.libvirtVersion = self.libvirt_version rsp.qemuVersion = self.qemu_version return jsonobject.dumps(rsp)
def connect(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) self.host_uuid = cmd.hostUuid logger.debug( http.path_msg(self.CONNECT_PATH, 'host[uuid: %s] connected' % cmd.hostUuid)) rsp = ConnectResponse() rsp.libvirtVersion = self.libvirt_version rsp.qemuVersion = self.qemu_version return jsonobject.dumps(rsp)
def connect(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) self.host_uuid = cmd.hostUuid self.config[kvmagent.HOST_UUID] = self.host_uuid self.config[kvmagent.SEND_COMMAND_URL] = cmd.sendCommandUrl logger.debug(http.path_msg(self.CONNECT_PATH, 'host[uuid: %s] connected' % cmd.hostUuid)) rsp = ConnectResponse() rsp.libvirtVersion = self.libvirt_version rsp.qemuVersion = self.qemu_version return jsonobject.dumps(rsp)
def check_physical_network_interface(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) presented_ifaces = self._get_presented_interfaces() failed_ifaces = [i for i in cmd.interfaceNames if i not in presented_ifaces] rsp = CheckPhysicalNetworkInterfaceResponse() if failed_ifaces: rsp.failedInterfaceNames = failed_ifaces rsp.success = False logger.debug(http.path_msg(CHECK_PHYSICAL_NETWORK_INTERFACE_PATH, 'checked physical interfaces: %s, failed interfaces: %s' % (cmd.interfaceNames, failed_ifaces))) return jsonobject.dumps(rsp)
def mountdata(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = AliyunNasResponse() naslinux.createCommonPath(cmd.mountPath, cmd.basePath) if not naslinux.is_mounted(cmd.dataPath, cmd.url): linux.mount(cmd.url, cmd.dataPath, cmd.options) logger.debug(http.path_msg(self.MOUNT_DATA_PATH, 'mounted %s on %s' % (cmd.url, cmd.dataPath))) rsp.mounted = True self._set_capacity_to_response(cmd.uuid, rsp) return jsonobject.dumps(rsp)
def mount(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = MountResponse() linux.is_valid_nfs_url(cmd.url) if not linux.is_mounted(cmd.mountPath, cmd.url): linux.mount(cmd.url, cmd.mountPath, cmd.options, "nfs4") self.mount_path[cmd.uuid] = cmd.mountPath logger.debug(http.path_msg(self.MOUNT_PATH, 'mounted %s on %s' % (cmd.url, cmd.mountPath))) self._set_capacity_to_response(cmd.uuid, rsp) return jsonobject.dumps(rsp)
def mount(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = MountResponse() linux.is_valid_nfs_url(cmd.url) if not linux.is_mounted(cmd.mountPath, cmd.url): linux.mount(cmd.url, cmd.mountPath, cmd.options) self.mount_path[cmd.uuid] = cmd.mountPath logger.debug(http.path_msg(self.MOUNT_PATH, 'mounted %s on %s' % (cmd.url, cmd.mountPath))) self._set_capacity_to_response(cmd.uuid, rsp) return jsonobject.dumps(rsp)
def connect(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) self.host_uuid = cmd.hostUuid self.config[kvmagent.HOST_UUID] = self.host_uuid self.config[kvmagent.SEND_COMMAND_URL] = cmd.sendCommandUrl logger.debug(http.path_msg(self.CONNECT_PATH, 'host[uuid: %s] connected' % cmd.hostUuid)) rsp = ConnectResponse() rsp.libvirtVersion = self.libvirt_version rsp.qemuVersion = self.qemu_version vm_plugin.cleanup_stale_vnc_iptable_chains() return jsonobject.dumps(rsp)
def connect(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) self.storage_path = cmd.storagePath if os.path.isfile(self.storage_path): raise Exception('storage path: %s is a file' % self.storage_path) if not os.path.exists(self.storage_path): os.makedirs(self.storage_path) (total, avail) = self.get_capacity() logger.debug(http.path_msg(self.CONNECT_PATH, 'connected, [storage path:%s, total capacity: %s bytes, available capacity: %s size]' % (self.storage_path, total, avail))) rsp = ConnectResponse() rsp.totalCapacity = total rsp.availableCapacity = avail return jsonobject.dumps(rsp)
def check_physical_network_interface(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = CheckPhysicalNetworkInterfaceResponse() for i in cmd.interfaceNames: shell_cmd = shell.ShellCmd("ip link | grep '%s'" % i) shell_cmd(False) if shell_cmd.return_code != 0: rsp.failedInterfaceNames = [i] rsp.success = False return jsonobject.dumps(rsp) logger.debug(http.path_msg(CHECK_PHYSICAL_NETWORK_INTERFACE_PATH, 'checked physical interfaces: %s' % cmd.interfaceNames)) return jsonobject.dumps(rsp)
def check_physical_network_interface(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = CheckPhysicalNetworkInterfaceResponse() for i in cmd.interfaceNames: if shell.run("ip link | grep -q -w '%s'" % i) != 0: rsp.failedInterfaceNames = [i] rsp.success = False return jsonobject.dumps(rsp) for i in cmd.interfaceNames: self._ifup_device_if_down(i) logger.debug(http.path_msg(CHECK_PHYSICAL_NETWORK_INTERFACE_PATH, 'checked physical interfaces: %s' % cmd.interfaceNames)) return jsonobject.dumps(rsp)
def check_physical_network_interface(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) presented_ifaces = self._get_presented_interfaces() failed_ifaces = [ i for i in cmd.interfaceNames if i not in presented_ifaces ] rsp = CheckPhysicalNetworkInterfaceResponse() if failed_ifaces: rsp.failedInterfaceNames = failed_ifaces rsp.success = False logger.debug( http.path_msg( CHECK_PHYSICAL_NETWORK_INTERFACE_PATH, 'checked physical interfaces: %s, failed interfaces: %s' % (cmd.interfaceNames, failed_ifaces))) return jsonobject.dumps(rsp)
def connect(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) self.host_uuid = cmd.hostUuid self.config[kvmagent.HOST_UUID] = self.host_uuid self.config[kvmagent.SEND_COMMAND_URL] = cmd.sendCommandUrl Report.serverUuid = self.host_uuid Report.url = cmd.sendCommandUrl logger.debug(http.path_msg(self.CONNECT_PATH, 'host[uuid: %s] connected' % cmd.hostUuid)) rsp = ConnectResponse() rsp.libvirtVersion = self.libvirt_version rsp.qemuVersion = self.qemu_version vm_plugin.cleanup_stale_vnc_iptable_chains() apply_iptables_result = self.apply_iptables_rules(cmd.iptablesRules) rsp.iptablesSucc = apply_iptables_result return jsonobject.dumps(rsp)
def connect(self, req): cmd = json_object.loads(req[http.REQUEST_BODY]) rsp = AgentResponse() self.uuid = cmd.uuid self.storage_path = cmd.storagePath # check storage path if os.path.isfile(self.storage_path): raise PxeServerError('storage path: %s is a file' % self.storage_path) if not os.path.exists(self.storage_path): os.makedirs(self.storage_path, 0777) total, avail = self._get_capacity() logger.debug(http.path_msg(self.CONNECT_PATH, 'connected, [storage path:%s, total capacity: %s bytes, ' 'available capacity: %s size]' % (self.storage_path, total, avail))) rsp.totalCapacity = total rsp.availableCapacity = avail return json_object.dumps(rsp)
def connect(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) self.host_uuid = cmd.hostUuid self.config[kvmagent.HOST_UUID] = self.host_uuid self.config[kvmagent.SEND_COMMAND_URL] = cmd.sendCommandUrl Report.serverUuid = self.host_uuid Report.url = cmd.sendCommandUrl logger.debug( http.path_msg(self.CONNECT_PATH, 'host[uuid: %s] connected' % cmd.hostUuid)) rsp = ConnectResponse() rsp.libvirtVersion = self.libvirt_version rsp.qemuVersion = self.qemu_version # create udev rule self.handle_usb_device_events() vm_plugin.cleanup_stale_vnc_iptable_chains() apply_iptables_result = self.apply_iptables_rules(cmd.iptablesRules) rsp.iptablesSucc = apply_iptables_result return jsonobject.dumps(rsp)
def mount(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = MountResponse() linux.is_valid_nfs_url(cmd.url) if not linux.is_mounted(cmd.mountPath, cmd.url): linux.mount(cmd.url, cmd.mountPath, cmd.options, "nfs4") with tempfile.TemporaryFile(dir=cmd.mountPath) as f: try: fcntl.flock(f.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB) except IOError: linux.umount(cmd.mountPath) raise Exception( 'File lock unavailable on NFS: {}, mount options: {}'. format(cmd.url, cmd.options)) self.mount_path[cmd.uuid] = cmd.mountPath logger.debug( http.path_msg(self.MOUNT_PATH, 'mounted %s on %s' % (cmd.url, cmd.mountPath))) self._set_capacity_to_response(cmd.uuid, rsp) return jsonobject.dumps(rsp)