def write_vdsm_config(engineHost, enginePort): if not os.path.exists(VDSM_CONFIG): system("touch " + VDSM_CONFIG) if os.path.getsize(VDSM_CONFIG) == 0: set_defaults() ovirt_store_config(VDSM_CONFIG) log("@ENGINENAME@ agent configuration files created.") else: log("@ENGINENAME@ agent configuration files already exist.") if system("ping -c 1 " + engineHost): sed_cmd = "sed -i --copy \"s/\(^vdc_host_name=\)\(..*$\)/vdc_host_name=" + engineHost + "/\" " + VDSM_REG_CONFIG if system(sed_cmd): log("The @ENGINENAME@'s address is set: %s\n" % engineHost) if enginePort != "": sed_cmd = "sed -i --copy \"s/\(^vdc_host_port=\)\(..*$\)/vdc_host_port=" + str( enginePort) + "/\" " + VDSM_REG_CONFIG if system(sed_cmd): log("The @ENGINENAME@'s port set: %s\n" % enginePort) fWriteConfig = 1 else: log("Either " + engineHost + " is an invalid address or the @ENGINENAME@ unresponsive.\n") return False if fWriteConfig == 1: log("Saving vdsm-reg.conf\n") if ovirt_store_config(VDSM_REG_CONFIG): log("vdsm-reg.conf Saved\n") return True
def save_ntp_configuration(self): _functions.ovirt_store_config(self.NTP_CONFIG_FILE) ntproot = "/files/etc/ntp.conf" ntpconf = "rm %s\n" % ntproot ntpconf += "set %s/driftfile /var/lib/ntp/drift\n" % ntproot ntpconf += "set %s/includefile /etc/ntp/crypto/pw\n" % ntproot ntpconf += "set %s/keys /etc/ntp/keys" % ntproot ntpconf = ntpconf.split("\n") for line in ntpconf: try: oper, key, value = line.split() _functions.augtool(oper, key, value) except: oper, key = line.split() _functions.augtool(oper, key, "") if "OVIRT_NTP" in OVIRT_VARS: SERVERS = [s for s in OVIRT_VARS["OVIRT_NTP"].split(",") if s] for n in [1, 2]: _functions.augtool("rm", \ "/files/etc/ntp.conf/server[%d]" % n, "") for idx, server in enumerate(SERVERS): n = idx + 1 # Augeas starts at 1 _functions.augtool("set", \ "/files/etc/ntp.conf/server[%d]" % n, server) _functions.system_closefds("service ntpd stop &> /dev/null") _functions.system_closefds("service ntpdate start &> /dev/null") _functions.system_closefds("service ntpd start &> /dev/null")
def enable_snmpd(password): from ovirtnode.ovirtfunctions import ovirt_store_config process.call("service snmpd stop") # get old password # if os.path.exists("/tmp/snmpd.conf"): conf = "/tmp/snmpd.conf" else: conf = snmp_conf cmd = "cat %s|grep createUser|awk '{print $4}'" % conf oldpwd, stderr = process.pipe(cmd) oldpwd = oldpwd.stdout.read().strip() process.call("sed -c -ie '/^createUser root/d' %s" % snmp_conf) f = open(snmp_conf, "a") # create user account f.write("createUser root SHA %s AES\n" % password) f.close() process.check_call("service snmpd start") # change existing password if len(oldpwd) > 0: pwd_change_cmd = (("snmpusm -v 3 -u root -n \"\" -l authNoPriv -a " + "SHA -A %s localhost passwd %s %s -x AES") % (oldpwd, oldpwd, password)) process.check_call(pwd_change_cmd) # Only reached when no excepion occurs process.call("rm -rf /tmp/snmpd.conf") ovirt_store_config(snmp_conf)
def enable_snmpd(password): from ovirtnode.ovirtfunctions import ovirt_store_config system.service("snmpd", "stop") # get old password # if os.path.exists("/tmp/snmpd.conf"): conf = "/tmp/snmpd.conf" else: conf = snmp_conf cmd = "cat %s|grep createUser|awk '{print $4}'" % conf oldpwd, stderr = process.pipe(cmd) oldpwd = oldpwd.stdout.read().strip() process.call("sed -c -ie '/^createUser root/d' %s" % snmp_conf) f = open(snmp_conf, "a") # create user account f.write("createUser root SHA %s AES\n" % password) f.close() system.service("snmpd", "start") # change existing password if len(oldpwd) > 0: pwd_change_cmd = (("snmpusm -v 3 -u root -n \"\" -l authNoPriv -a " + "SHA -A %s localhost passwd %s %s -x AES") % (oldpwd, oldpwd, password)) process.check_call(pwd_change_cmd) # Only reached when no excepion occurs process.call("rm -rf /tmp/snmpd.conf") ovirt_store_config(snmp_conf)
def write_vdsm_config(engineHost, enginePort): if not os.path.exists(VDSM_CONFIG): system("touch " + VDSM_CONFIG) if os.path.getsize(VDSM_CONFIG) == 0: set_defaults() ovirt_store_config(VDSM_CONFIG) log("@ENGINENAME@ agent configuration files created.") else: log("@ENGINENAME@ agent configuration files already exist.") if system("ping -c 1 " + engineHost): sed_cmd = "sed -i --copy \"s/\(^vdc_host_name=\)\(..*$\)/vdc_host_name\ =" + engineHost + "/\" " + VDSM_REG_CONFIG if system(sed_cmd): log("The @ENGINENAME@'s address is set: %s\n" % engineHost) if enginePort != "": sed_cmd = "sed -i --copy \"s/\(^vdc_host_port=\)\(..*$\)/vdc\ _host_port=" + str(enginePort) + "/\" " + VDSM_REG_CONFIG if system(sed_cmd): log("The @ENGINENAME@'s port set: %s\n" % enginePort) fWriteConfig = 1 else: log("Either " + engineHost + " is an invalid address \ or the IMVP unresponsive.\n") return False if fWriteConfig == 1: log("Saving vdsm-reg.conf\n") if ovirt_store_config(VDSM_REG_CONFIG): log("vdsm-reg.conf Saved\n") return True
def enable_snmpd(password): _functions.system("service snmpd stop") # get old password # if os.path.exists("/tmp/snmpd.conf"): conf = "/tmp/snmpd.conf" else: conf = snmp_conf cmd = "cat %s|grep createUser|awk '{print $4}'" % conf oldpwd = _functions.subprocess_closefds(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) oldpwd = oldpwd.stdout.read().strip() _functions.system("sed -c -ie '/^createUser root/d' %s" % snmp_conf) f = open(snmp_conf, "a") # create user account f.write("createUser root SHA %s AES\n" % password) f.close() _functions.system("service snmpd start") # change existing password if len(oldpwd) > 0: pwd_change_cmd = ("snmpusm -v 3 -u root -n \"\" -l authNoPriv -a " + "SHA -A %s localhost passwd %s %s -x AES") % (oldpwd, oldpwd, password) if _functions.system(pwd_change_cmd): _functions.system("rm -rf /tmp/snmpd.conf") _functions.ovirt_store_config(snmp_conf)
def configure_dns(self): OVIRT_VARS = _functions.parse_defaults() if "OVIRT_DNS" in OVIRT_VARS: DNS = OVIRT_VARS["OVIRT_DNS"] try: if DNS is not None: tui_cmt = ("Please make changes through the TUI. " + \ "Manual edits to this file will be " + \ "lost on reboot") _functions.augtool("set", \ "/files/etc/resolv.conf/#comment[1]", \ tui_cmt) DNS = DNS.split(",") i = 1 for server in DNS: logger.debug("Setting DNS server %d: %s" % (i, server)) setting = "/files/etc/resolv.conf/nameserver[%s]" % i _functions.augtool("set", setting, server) i = i + i _functions.ovirt_store_config("/etc/resolv.conf") else: logger.debug("No DNS servers given.") except: logger.warn("Failed to set DNS servers") finally: if len(DNS) < 2: _functions.augtool("rm", \ "/files/etc/resolv.conf/nameserver[2]", "") for nic in glob("/etc/sysconfig/network-scripts/ifcfg-*"): if not "ifcfg-lo" in nic: path = "/files%s/PEERDNS" % nic _functions.augtool("set", path, "no")
def enable_snmpd(password): _functions.system("service snmpd stop") # get old password # if os.path.exists("/tmp/snmpd.conf"): conf = "/tmp/snmpd.conf" else: conf = snmp_conf cmd = "cat %s|grep createUser|awk '{print $4}'" % conf oldpwd = _functions.subprocess_closefds(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) oldpwd = oldpwd.stdout.read().strip() _functions.system("sed -c -ie '/^createUser root/d' %s" % snmp_conf) f = open(snmp_conf, "a") # create user account f.write("createUser root SHA %s AES\n" % password) f.close() _functions.system("service snmpd start") # change existing password if len(oldpwd) > 0: pwd_change_cmd = ("snmpusm -v 3 -u root -n \"\" -l authNoPriv -a " + "SHA -A %s localhost passwd %s %s -x AES") % ( oldpwd, oldpwd, password) if _functions.system(pwd_change_cmd): _functions.system("rm -rf /tmp/snmpd.conf") _functions.ovirt_store_config(snmp_conf)
def write_vdsm_config(rhevm_host, rhevm_port): if not os.path.exists(VDSM_CONFIG): os.system("touch " + VDSM_CONFIG) if os.path.getsize(VDSM_CONFIG) == 0: set_defaults() ovirt_store_config(VDSM_CONFIG) log("RHEV agent configuration files created.") else: log("RHEV agent configuration files already exist.") ret = os.system("ping -c 1 " + rhevm_host + " &> /dev/null") if ret == 0: sed_cmd = "sed -i --copy \"s/\(^vdc_host_name=\)\(..*$\)/vdc_host_name=" + rhevm_host + "/\" " + VDSM_REG_CONFIG ret = os.system(sed_cmd) if ret == 0: log("The RHEV Manager's address is set: %s\n" % rhevm_host) if rhevm_port != "": sed_cmd = "sed -i --copy \"s/\(^vdc_host_port=\)\(..*$\)/vdc_host_port=" + str( rhevm_port) + "/\" " + VDSM_REG_CONFIG os.system(sed_cmd) log("The RHEV Manager's port set: %s\n" % rhevm_port) fWriteConfig = 1 else: log("Either " + rhevm_host + " is an invalid address or the RHEV Manager unresponsive.\n") return False if fWriteConfig == 1: log("Saving vdsm-reg.conf\n") if ovirt_store_config(VDSM_REG_CONFIG): log("vdsm-reg.conf Saved\n") return True
def write_vdsm_config(rhevm_host, rhevm_port): if not os.path.exists(VDSM_CONFIG): os.system("touch " + VDSM_CONFIG) if os.path.getsize(VDSM_CONFIG) == 0: set_defaults() ovirt_store_config(VDSM_CONFIG) log("oVirt agent configuration files created.") else: log("oVirt agent configuration files already exist.") ret = os.system("ping -c 1 " + rhevm_host + " &> /dev/null") if ret == 0: sed_cmd = "sed -i --copy \"s/\(^vdc_host_name=\)\(..*$\)/vdc_host_name="+rhevm_host+"/\" " + VDSM_REG_CONFIG ret = os.system(sed_cmd) if ret == 0: log("The oVirt Engine's address is set: %s\n" % rhevm_host) if rhevm_port != "": sed_cmd = "sed -i --copy \"s/\(^vdc_host_port=\)\(..*$\)/vdc_host_port="+str(rhevm_port)+"/\" " + VDSM_REG_CONFIG os.system(sed_cmd) log("The oVirt Engine's port set: %s\n" % rhevm_port) fWriteConfig=1 else: log("Either " + rhevm_host + " is an invalid address or the oVirt Engine unresponsive.\n") return False if fWriteConfig == 1: log("Saving vdsm-reg.conf\n") if ovirt_store_config(VDSM_REG_CONFIG): log("vdsm-reg.conf Saved\n") return True
def action(self): self.ncs.screen.setColor("BUTTON", "black", "red") self.ncs.screen.setColor("ACTBUTTON", "blue", "white") if self.root_password_1.value() != "" and self.root_password_2.value( ) != "" and self.root_password_1.value() == self.root_password_2.value( ): set_password(self.root_password_1.value(), "root") augtool("set", "/files/etc/ssh/sshd_config/PasswordAuthentication", "yes") dn = file('/dev/null', 'w+') subprocess.Popen(['/sbin/service', 'sshd', 'restart'], stdout=dn, stderr=dn) if len(self.rhevm_server.value()) > 0: deployUtil.nodeCleanup() if self.verify_rhevm_cert.selected(): if deployUtil.getRhevmCert(self.rhevm_server.value(), self.rhevm_server_port.value()): path, dontCare = deployUtil.certPaths('') fp = deployUtil.generateFingerPrint(path) approval = ButtonChoiceWindow( self.ncs.screen, "Certificate Fingerprint:", fp, buttons=['Approve', 'Reject']) if 'reject' == approval: ButtonChoiceWindow(self.ncs.screen, "Fingerprint rejected", "RHEV-M Configuration Failed", buttons=['Ok']) return False else: ovirt_store_config(path) self.ncs.reset_screen_colors() else: ButtonChoiceWindow(self.ncs.screen, "RHEV-M Configuration", "Failed downloading RHEV-M certificate", buttons=['Ok']) self.ncs.reset_screen_colors() # Stopping vdsm-reg may fail but its ok - its in the case when the menus are run after installation deployUtil._logExec([constants.EXT_SERVICE, 'vdsm-reg', 'stop']) if write_vdsm_config(self.rhevm_server.value(), self.rhevm_server_port.value()): deployUtil._logExec( [constants.EXT_SERVICE, 'vdsm-reg', 'start']) ButtonChoiceWindow(self.ncs.screen, "RHEV-M Configuration", "RHEV-M Configuration Successfully Updated", buttons=['Ok']) self.ncs.reset_screen_colors() return True else: ButtonChoiceWindow(self.ncs.screen, "RHEV-M Configuration", "RHEV-M Configuration Failed", buttons=['Ok']) self.ncs.reset_screen_colors() return False
def write_kdump_config(config): kdump_config_file = open("/etc/kdump.conf", "w") kdump_config_file.write("default reboot\n") # adds a 60 sec delay to make sure the nic is up kdump_config_file.write("net " + config + "\n") kdump_config_file.close() _functions.ovirt_store_config("/etc/kdump.conf") return True
def set_password(password, user): admin = libuser.admin() root = admin.lookupUserByName(user) passwd = cryptPassword(password) _functions.unmount_config("/etc/shadow") admin.setpassUser(root, passwd, "is_crypted") _functions.ovirt_store_config("/etc/shadow") return True
def set_logrotate_size(size): try: _functions.augtool("set", \ "/files/etc/logrotate.d/ovirt-node/rule/size", size) _functions.ovirt_store_config("/etc/logrotate.d/ovirt-node") return True except: return False
def toggle_ssh_access(): ssh_config = augeas.Augeas("root=/") ssh_config.set("/files/etc/ssh/sshd_config", _functions.OVIRT_VARS["ssh_pass_enabled"]) ssh_config.save() _functions.ovirt_store_config("/etc/ssh/sshd_config") rc = _functions.system_closefds("service sshd reload") return rc
def imvp_apply(self, obj): from ocsetup.ocsetup import ocs log("enter imvp apply %s") imvp_server_address = ocs.imvp_server_addr_val_Entry.get_text() imvp_server_port = ocs.imvp_serve_port_val_Entry.get_text() compatPort, sslPort = compatiblePort(imvp_server_port) if len(imvp_server_address) > 0: deployUtil.nodeCleanup() if not isHostReachable(host=imvp_server_address, port=imvp_server_port, ssl=sslPort, timeout=TIMEOUT_FIND_HOST_SEC): if compatPort is None: # Try one more time with SSL=False if not isHostReachable(host=imvp_server_address, port=imvp_server_port, ssl=False, timeout=TIMEOUT_FIND_HOST_SEC): msgConn = "Can't connect to oVirt Engine in the specific" \ " port %s" % enginePort resp_id = ConfirmDialog(message=msgConn).run_and_close() return False else: msgConn = "Can't connect to oVirt Engine port %s," \ " trying compatible port %s" % \ (enginePort, compatPort) resp_id = ConfirmDialog(message=msgConn).run_and_close() if not isHostReachable(host=imvp_server_address, port=compatPort, ssl=sslPort, timeout=TIMEOUT_FIND_HOST_SEC): msgConn = "Can't connect to oVirt Engine using" \ " compatible port %s" % compatPort resp_id = ConfirmDialog(message=msgConn).run_and_close() return False else: # compatible port found enginePort = compatPort if True: if deployUtil.getRhevmCert(imvp_server_address, enginePort): path, dontCare = deployUtil.certPaths('') fp = deployUtil.generateFingerPrint(path) ovirt_store_config(path) else: msgConn = "Failed downloading IMVP certificate" resp_id = ConfirmDialog(message=msgConn).run_and_close() # Stopping vdsm-reg may fail but its ok - its in the case when the menus are run after installation deployUtil._logExec([constants.EXT_SERVICE, 'vdsm-reg', 'stop']) if write_vdsm_config(imvp_server_address, enginePort): deployUtil._logExec([constants.EXT_SERVICE, 'vdsm-reg', 'start']) msgConn = "@ENGINENAME@ Configuration Successfully Updated" resp_id = ConfirmDialog(message=msgConn).run_and_close() retWriteConf = True else: msgConn = "@ENGINENAME@ Configuration Failed" resp_id = ConfirmDialog(message=msgConn).run_and_close() retWriteConf = False return retWriteConf
def kdump_apply(self, obj): try: from ocsetup import ocs except ImportError: pass else: page = ocs.page_kernel_dump buttons = page.nfs_ssh_restore_custom.btns val = None for i in range(3): # i == 0 is NFS, i == 1 is SSH, i == 2 is RESTORE if buttons[i].get_active() and i == 0: val = page.nfs_location_custom.entry.get_text() elif buttons[i].get_active() and i == 1: val = page.ssh_location_custom.entry.get_text() elif buttons[i].get_active() and i == 2: restore_kdump_config() if val: write_kdump_config(val) pb = ProgressBar() pb.make_progress(0.1) if '@' in val: if os.path.exists("/usr/bin/kdumpctl"): kdump_prop_cmd = "kdumpctl propagate" else: kdump_prop_cmd = "service kdump propagate" from sshcmd import runcmd runcmd(kdump_prop_cmd) pb.make_progress(0.2) if runcmd: # SSH LOGIN SUCCESS. ovirt_store_config("/root/.ssh/kdump_id_rsa.pub") ovirt_store_config("/root/.ssh/kdump_id_rsa") ovirt_store_config("/root/.ssh/known_hosts") ovirt_store_config("/root/.ssh/config") pb.make_progress(0.5) system('servic kdump restart &') while True: res = check_output('service kdump status') if 'starting' not in res: break pb.make_progress(0.5) time.sleep(3) pb.make_progress(0.8) if 'Kdump is not operational' in res: # restart kdump Failed. unmount_config("/etc/kdump.conf") if os.path.exists("/etc/kdump.conf"): os.remove("/etc/kdump.conf") pb.make_progress(0, 'FAILED!') pb.progress_label.set_label('FAILED!') elif 'Kdump is operational' in res: ovirt_store_config("/etc/kdump.conf") pb.make_progress(1, 'successful!') else: log('kdump start Failed:' + res) pb.make_progress(0, 'FAILED!') pb.progress_label.set_label('FAILED!')
def write_kdump_config(config, type="net"): assert type in ["nfs", "ssh", "net"] kdump_config_file = open("/etc/kdump.conf", "w") kdump_config_file.write("default reboot\n") # adds a 60 sec delay to make sure the nic is up kdump_config_file.write(type + " " + config + "\n") kdump_config_file.close() _functions.ovirt_store_config("/etc/kdump.conf") return True
def kdump_auto(): try: if "OVIRT_KDUMP_NFS" in _functions.OVIRT_VARS: write_kdump_config(_functions.OVIRT_VARS["OVIRT_KDUMP_NFS"], "nfs") _functions.ovirt_store_config("/etc/kdump.conf") _functions.logger.info("Syslog Configuration Completed") return True except: _functions.logger.error("KDump Configuration Failed")
def kdump_auto(): try: if "OVIRT_KDUMP_NFS" in _functions.OVIRT_VARS: write_kdump_config(_functions.OVIRT_VARS["OVIRT_KDUMP_NFS"]) _functions.ovirt_store_config("/etc/kdump.conf") _functions.logger.info("Syslog Configuration Completed") return True except: _functions.logger.error("KDump Configuration Failed")
def convert_to_biosdevname(): if not "BIOSDEVNAMES_CONVERSION" in OVIRT_VARS: # check for appropriate bios version cmd = "dmidecode|grep SMBIOS|awk {'print $2'}" proc = _functions.passthrough(cmd, log_func=logger.debug) ver = proc.stdout.split()[0] if not float(ver) >= 2.6: logger.debug("Skipping biosdevname conversion, SMBIOS too old") _functions.augtool( "set", "/files/etc/default/ovirt/BIOSDEVNAMES_CONVERSION", "y") return nics = {} cmd = "biosdevname -d" biosdevname, err = subprocess.Popen( cmd, shell=True, stdout=subprocess.PIPE).communicate() biosdevname_output = biosdevname.splitlines() for line in biosdevname_output: if line is not None: if "BIOS device:" in line: nic = line.split()[2] if "Permanent" in line: mac = line.split()[2] nics[mac.upper()] = nic logger.debug(nics) scripts_path = "/etc/sysconfig/network-scripts" logger.debug(glob(scripts_path + "/ifcfg-*")) for file in glob(scripts_path + "/ifcfg-*"): logger.debug("Processing %s" % file) # get mac for matching existing_mac = _functions.augtool_get("/files/" + file + "/HWADDR") # check dictionary for mac if not existing_mac is None and existing_mac.upper() in nics: old_nic_script = os.path.basename(file) new_nic_name = nics[existing_mac.upper()] logger.debug("Found %s in %s" % (existing_mac, file)) # change device name within script file logger.debug("Setting to new device name: %s" % new_nic_name) _functions.augtool("set", \ "/files" + file + "/DEVICE", new_nic_name) new_nic_file = "%s/ifcfg-%s" % (scripts_path, new_nic_name) cmd = "cp %s %s" % (file, new_nic_file) _functions.remove_config(file) if _functions.system(cmd): logging.debug("Conversion on %s to %s succeed" % (file, new_nic_file)) _functions.ovirt_store_config(new_nic_file) else: return False _functions.system("service network restart") _functions.augtool("set", \ "/files/etc/default/ovirt/BIOSDEVNAMES_CONVERSION", "y") _functions.ovirt_store_config("/etc/default/ovirt") return True
def password_authentication(self, enable=None): augpath = "/files/etc/ssh/sshd_config/PasswordAuthentication" aug = utils.AugeasWrapper() if enable in [True, False]: import ovirtnode.ovirtfunctions as ofunc value = "yes" if enable else "no" self.logger.debug("Setting SSH PasswordAuthentication to " + "%s" % value) aug.set(augpath, value) ofunc.ovirt_store_config("/etc/ssh/sshd_config") self.restart() return aug.get(augpath)
def convert_to_biosdevname(): if not "BIOSDEVNAMES_CONVERSION" in OVIRT_VARS: # check for appropriate bios version cmd="dmidecode|grep SMBIOS|awk {'print $2'}" proc = _functions.passthrough(cmd, log_func=logger.debug) ver = proc.stdout.split()[0] if not float(ver) >= 2.6: logger.debug("Skipping biosdevname conversion, SMBIOS too old") _functions.augtool("set", "/files/etc/default/ovirt/BIOSDEVNAMES_CONVERSION", "y") return nics = {} cmd = "biosdevname -d" biosdevname, err = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).communicate() biosdevname_output = biosdevname.splitlines() for line in biosdevname_output: if line is not None: if "BIOS device:" in line: nic = line.split()[2] if "Permanent" in line: mac = line.split()[2] nics[mac.upper()] = nic logger.debug(nics) scripts_path = "/etc/sysconfig/network-scripts" logger.debug(glob(scripts_path + "/ifcfg-*")) for file in glob(scripts_path + "/ifcfg-*"): logger.debug("Processing %s" % file) # get mac for matching existing_mac = _functions.augtool_get("/files/" + file + "/HWADDR") # check dictionary for mac if not existing_mac is None and existing_mac.upper() in nics: old_nic_script = os.path.basename(file) new_nic_name = nics[existing_mac.upper()] logger.debug("Found %s in %s" % (existing_mac, file)) # change device name within script file logger.debug("Setting to new device name: %s" % new_nic_name) _functions.augtool("set", \ "/files" + file + "/DEVICE", new_nic_name) new_nic_file = "%s/ifcfg-%s" % (scripts_path, new_nic_name) cmd = "cp %s %s" % (file, new_nic_file) _functions.remove_config(file) if _functions.system(cmd): logging.debug("Conversion on %s to %s succeed" % (file, new_nic_file)) _functions.ovirt_store_config(new_nic_file) else: return False _functions.system("service network restart") _functions.augtool("set", \ "/files/etc/default/ovirt/BIOSDEVNAMES_CONVERSION", "y") _functions.ovirt_store_config("/etc/default/ovirt") return True
def ovirt_rsyslog(server, port, protocol): if server == "": disable = "#" else: disable = "" if protocol == "tcp": DELIM = "@@" else: DELIM = "@" if _functions.is_valid_ipv6(server): server = "[" + server + "]" rsyslog_dict = { "disable": disable, "delim": DELIM, "server": server, "port": port } rsyslog_config_out = RSYSLOG_CONFIG_TEMPLATE % rsyslog_dict rsyslog_config = open(RSYSLOG_FILE, "w") rsyslog_config.write(rsyslog_config_out) rsyslog_config.close() _functions.system_closefds("/sbin/service rsyslog restart &> /dev/null") if _functions.ovirt_store_config("/etc/rsyslog.conf"): logger.info("Syslog Configuration Updated") return True
def configure_dns(self): logger.warn("Configuring DNS") OVIRT_VARS = _functions.parse_defaults() have_peerdns = True DNS = "" if "OVIRT_DNS" in OVIRT_VARS: DNS = OVIRT_VARS["OVIRT_DNS"] logger.debug("Found DNS key with value '%s'" % DNS) try: # Write resolv.conf any way, sometimes without servers tui_cmt = ("Please make changes through the TUI. " + \ "Manual edits to this file will be " + \ "lost on reboot") _functions.augtool("set", \ "/files/etc/resolv.conf/#comment[1]", \ tui_cmt) DNS = [s for s in DNS.split(",") if s] i = 1 for server in DNS: logger.debug("Setting DNS server %d: %s" % (i, server)) setting = "/files/etc/resolv.conf/nameserver[%s]" % i _functions.augtool("set", setting, server) # PEERDNS=no is required with manual DNS servers have_peerdns = False i = i + i _functions.ovirt_store_config("/etc/resolv.conf") except: logger.warn("Failed to set DNS servers") # Remove all spare DNS servers logger.debug("Removing DNS servers") if len(DNS) < 2: _functions.augtool("rm", "/files/etc/resolv.conf/nameserver[2]", "") if len(DNS) < 1: _functions.augtool("rm", "/files/etc/resolv.conf/nameserver[1]", "") # Set or remove PEERDNS for all ifcfg-* for nic in glob("/etc/sysconfig/network-scripts/ifcfg-*"): if "ifcfg-lo" in nic: continue path = "/files%s/PEERDNS" % nic if have_peerdns: _functions.augtool("rm", path, "") else: _functions.augtool("set", path, "no")
def commit(self): from ovirtnode import network as onet, ovirtfunctions network = onet.Network() if self.hostname: network.remove_non_localhost() network.add_localhost_alias(self.hostname) else: network.remove_non_localhost() self.hostname = "localhost.localdomain" config.network.hostname(self.hostname) ovirtfunctions.ovirt_store_config("/etc/sysconfig/network") ovirtfunctions.ovirt_store_config("/etc/hosts") utils.network.reset_resolver()
def ovirt_netconsole(server, port): _functions.augtool("set", \ "/files/etc/sysconfig/netconsole/SYSLOGADDR", server) _functions.augtool("set", \ "/files/etc/sysconfig/netconsole/SYSLOGPORT", port) _functions.system_closefds("/sbin/service netconsole restart &> /dev/null") if _functions.ovirt_store_config("/etc/sysconfig/netconsole"): logger.info("Netconsole Configuration Updated") return True
def commit(self): from ovirtnode.ovirtfunctions import unmount_config, \ ovirt_store_config try: utils.process.check_call("service kdump restart") except utils.process.CalledProcessError as e: self.logger.info("Failure while restarting kdump: %s" % e) unmount_config("/etc/kdump.conf") self.backups.restore("/etc/kdump.conf") utils.process.call("service kdump restart") raise RuntimeError("KDump configuration failed, " + "location unreachable. Previous " + "configuration was restored.") ovirt_store_config("/etc/kdump.conf") self.backups.remove()
def set_iscsi_initiator(initiator_name): iscsi_config = open(INITIATOR_FILE, "w") iscsi_config.write("InitiatorName=" + initiator_name + "\n") iscsi_config.close() if _functions.ovirt_store_config(INITIATOR_FILE): _functions.logger.info("Initiator name set as: " + initiator_name) else: _functions.logger.warning("Setting initiator name failed") _functions.system_closefds("service iscsid restart &> /dev/null")
def __update_profile(self, rng_num_bytes, disable_aes): import ovirtnode.ovirtfunctions as ofunc additional_lines = [] ofunc.unmount_config("/etc/profile") process.check_call("sed -i '/OPENSSL_DISABLE_AES_NI/d' /etc/profile") if disable_aes: additional_lines += ["export OPENSSL_DISABLE_AES_NI=1"] process.check_call("sed -i '/SSH_USE_STRONG_RNG/d' /etc/profile") if rng_num_bytes: additional_lines += ["export SSH_USE_STRONG_RNG=%s" % rng_num_bytes] if additional_lines: self.logger.debug("Updating /etc/profile") lines = "\n" + "\n".join(additional_lines) File("/etc/profile").write(lines, "a") ofunc.ovirt_store_config("/etc/profile") self.restart()
def commit(self): import ovirtnode.kdump as okdump from ovirtnode.ovirtfunctions import ovirt_store_config okdump.write_kdump_config(ssh) if os.path.exists("/usr/bin/kdumpctl"): cmd = "kdumpctl propagate" else: cmd = "service kdump propagate" cmd += "2>&1" try: utils.process.check_call(cmd) ovirt_store_config(["/root/.ssh/kdump_id_rsa.pub", "/root/.ssh/kdump_id_rsa", "/root/.ssh/known_hosts", "/root/.ssh/config"]) except utils.process.CalledProcessError as e: self.logger.warning("Failed to activate KDump with " + "SSH: %s" % e)
def ovirt_netconsole(server, port): _functions.augtool("set", \ "/files/etc/sysconfig/netconsole/SYSLOGADDR", server) _functions.augtool("set", \ "/files/etc/sysconfig/netconsole/SYSLOGPORT", port) try: system.service("netconsole", "restart") except: raise RuntimeError("Failed to restart netconsole service. " "Is the host resolvable?") if _functions.ovirt_store_config("/etc/sysconfig/netconsole"): logger.info("Netconsole Configuration Updated") return True
def __update_profile(self, rng_num_bytes, disable_aes): import ovirtnode.ovirtfunctions as ofunc additional_lines = [] ofunc.unmount_config("/etc/profile") process.check_call("sed -i '/OPENSSL_DISABLE_AES_NI/d' /etc/profile") if disable_aes: additional_lines += ["export OPENSSL_DISABLE_AES_NI=1"] process.check_call("sed -i '/SSH_USE_STRONG_RNG/d' /etc/profile") if rng_num_bytes: additional_lines += [ "export SSH_USE_STRONG_RNG=%s" % rng_num_bytes ] if additional_lines: self.logger.debug("Updating /etc/profile") lines = "\n" + "\n".join(additional_lines) File("/etc/profile").write(lines, "a") ofunc.ovirt_store_config("/etc/profile") self.restart()
def action(self): self.ncs.screen.setColor("BUTTON", "black", "red") self.ncs.screen.setColor("ACTBUTTON", "blue", "white") if self.root_password_1.value() != "" and self.root_password_2.value() != "" and self.root_password_1.value() == self.root_password_2.value(): set_password(self.root_password_1.value(), "root") augtool("set", "/files/etc/ssh/sshd_config/PasswordAuthentication", "yes") dn = file('/dev/null', 'w+') subprocess.Popen(['/sbin/service', 'sshd', 'restart'], stdout=dn, stderr=dn) if len(self.rhevm_server.value()) > 0: deployUtil.nodeCleanup() if self.verify_rhevm_cert.selected(): if deployUtil.getRhevmCert(self.rhevm_server.value(), self.rhevm_server_port.value()): path, dontCare = deployUtil.certPaths('') fp = deployUtil.generateFingerPrint(path) approval = ButtonChoiceWindow(self.ncs.screen, "Certificate Fingerprint:", fp, buttons = ['Approve', 'Reject']) if 'reject' == approval: ButtonChoiceWindow(self.ncs.screen, "Fingerprint rejected", "oVirt Engine Configuration Failed", buttons = ['Ok']) return False else: ovirt_store_config(path) self.ncs.reset_screen_colors() else: ButtonChoiceWindow(self.ncs.screen, "oVirt Engine Configuration", "Failed downloading oVirt Engine certificate", buttons = ['Ok']) self.ncs.reset_screen_colors() # Stopping vdsm-reg may fail but its ok - its in the case when the menus are run after installation deployUtil._logExec([constants.EXT_SERVICE, 'vdsm-reg', 'stop']) if write_vdsm_config(self.rhevm_server.value(), self.rhevm_server_port.value()): deployUtil._logExec([constants.EXT_SERVICE, 'vdsm-reg', 'start']) ButtonChoiceWindow(self.ncs.screen, "oVirt Engine Configuration", "oVirt Engine Configuration Successfully Updated", buttons = ['Ok']) self.ncs.reset_screen_colors() return True else: ButtonChoiceWindow(self.ncs.screen, "oVirt Engine Configuration", "oVirt Engine Configuration Failed", buttons = ['Ok']) self.ncs.reset_screen_colors() return False
def password_authentication(self, enable=None): """Get or set the ssh password authentication Args: enable: (optional) If given the auth is set Returns: True if password authentication is enabled, False otherwise """ augpath = "/files/etc/ssh/sshd_config/PasswordAuthentication" aug = utils.AugeasWrapper() if enable in [True, False]: import ovirtnode.ovirtfunctions as ofunc value = "yes" if enable else "no" self.logger.debug("Setting SSH PasswordAuthentication to " + "%s" % value) aug.set(augpath, value) ofunc.ovirt_store_config("/etc/ssh/sshd_config") self.restart() state = str(aug.get(augpath)).lower() if state not in ["yes", "no"]: raise RuntimeError("Failed to set SSH password authentication" + "(%s)" % state) return state == "yes"
def enable_snmpd(password): from ovirtnode.ovirtfunctions import ovirt_store_config system.service("snmpd", "stop") # get old password # if os.path.exists("/tmp/snmpd.conf"): conf = "/tmp/snmpd.conf" else: conf = snmp_conf cmd = "cat %s|grep createUser|awk '{print $4}'" % conf oldpwd, stderr = process.pipe(cmd, shell=True) oldpwd = oldpwd.stdout.read().strip() process.call("sed -c -ie '/^createUser root/d' %s" % snmp_conf, shell=True) f = open(snmp_conf, "a") # create user account f.write("createUser root SHA %s AES\n" % password) f.close() # change existing password if len(oldpwd) > 0: pwd_change_cmd = (("snmpusm -v 3 -u root -n \"\" -l authNoPriv -a " + "SHA -A %s localhost passwd %s %s -x AES") % (oldpwd, oldpwd, password)) process.check_call(pwd_change_cmd, shell=True) # Only reached when no excepion occurs process.call(["rm", "-rf", "/tmp/snmpd.conf"]) ovirt_store_config(snmp_conf) if not any([x for x in open('/etc/snmp/snmpd.conf').readlines() if 'rwuser root' in x]): with open('/etc/snmp/snmpd.conf', 'a') as f: f.write("rwuser root") ovirt_store_config('/etc/snmp/snmpd.conf') system.service("snmpd", "start")
def set_nfsv4_domain(domain): idmap_conf = "/etc/idmapd.conf" current_domain = get_current_nfsv4_domain() _functions.unmount_config(idmap_conf) if current_domain.startswith("#"): current_domain = "#Domain = %s" % current_domain.replace("# ", "") _functions.system("sed -i 's/%s/Domain = %s/g' %s" \ % (current_domain, domain, idmap_conf)) else: _functions.system("sed -i 's/%s/%s/g' %s" \ % (current_domain, domain, idmap_conf)) if _functions.ovirt_store_config(idmap_conf): logger.info("NFSv4 domain set as: " + domain) else: logger.warning("Setting nfsv4 domain failed") _functions.system_closefds("service rpcidmapd restart") _functions.system_closefds("nfsidmap -c &>/dev/null")
def set_nfsv4_domain(domain): idmap_conf = "/etc/idmapd.conf" current_domain = get_current_nfsv4_domain() _functions.unmount_config(idmap_conf) if current_domain.startswith("#"): current_domain = "#Domain = %s" % current_domain.replace("# ","") _functions.system("sed -i 's/%s/Domain = %s/g' %s" \ % (current_domain, domain, idmap_conf)) else: _functions.system("sed -i '/^Domain/ s/%s/%s/g' %s" \ % (current_domain, domain, idmap_conf)) if _functions.ovirt_store_config(idmap_conf): logger.info("NFSv4 domain set as: " + domain) else: logger.warning("Setting nfsv4 domain failed") _functions.system_closefds("service rpcidmapd restart") _functions.system_closefds("nfsidmap -c &>/dev/null")
def _closeup(self): _persist = None try: # First: Try importing the new code, # this should work most of the time from ovirt.node.utils.fs import Config _persist = lambda f: Config().persist(f) except ImportError: try: # If it failed, then try importing the legacy code from ovirtnode import ovirtfunctions _persist = lambda f: ovirtfunctions.ovirt_store_config(f) except ImportError: raise RuntimeError(_('Cannot resolve persist module.')) for f in ( [odeploycons.FileLocations.VDSM_ID_FILE] + self.environment[otopicons.CoreEnv.MODIFIED_FILES] ): self.logger.debug('persisting: %s' % f) _persist(f)
def perform_partitioning(self): if self.HOSTVGDRIVE is None and not _functions.is_iscsi_install(): logger.error("\nNo storage device selected.") return False if self.BOOTDRIVE is None and _functions.is_iscsi_install(): logger.error("No storage device selected.") return False if not self.cross_check_host_app(): logger.error("Skip disk partitioning, AppVG overlaps with HostVG") return False if _functions.has_fakeraid(self.HOSTVGDRIVE): if not handle_fakeraid(self.HOSTVGDRIVE): return False if _functions.has_fakeraid(self.ROOTDRIVE): if not handle_fakeraid(self.ROOTDRIVE): return False logger.info("Saving parameters") _functions.unmount_config("/etc/default/ovirt") if not self.check_partition_sizes(): return False # Check for still remaining HostVGs this can be the case when # Node was installed on a disk not given in storage_init # rhbz#872114 existing_vgs = str(_functions.passthrough("vgs")) for vg in existing_vgs.split("\n"): vg = vg.strip() if "HostVG" in str(vg): logger.error("An existing installation was found or not " + "all VGs could be removed. " + "Please manually cleanup the storage using " + "standard disk tools.") return False logger.info("Removing old LVM partitions") # HostVG must not exist at this point # we wipe only foreign LVM here logger.info("Wiping LVM on HOSTVGDRIVE %s" % self.HOSTVGDRIVE) if not self.wipe_lvm_on_disk(self.HOSTVGDRIVE): logger.error("Wiping LVM on %s Failed" % self.HOSTVGDRIVE) return False logger.info("Wiping LVM on ROOTDRIVE %s" % self.ROOTDRIVE) if not self.wipe_lvm_on_disk(self.ROOTDRIVE): logger.error("Wiping LVM on %s Failed" % self.ROOTDRIVE) return False logger.info("Wiping LVM on BOOTDRIVE %s" % self.BOOTDRIVE) if not self.wipe_lvm_on_disk(self.BOOTDRIVE): logger.error("Wiping LVM on %s Failed" % self.BOOTDRIVE) return False logger.debug("Old LVM partitions should be gone.") logger.debug(_functions.passthrough("vgdisplay -v")) self.boot_size_si = self.BOOT_SIZE * (1024 * 1024) / (1000 * 1000) if _functions.is_iscsi_install(): if "OVIRT_ISCSI_NAME" in _functions.OVIRT_VARS: iscsi_name = _functions.OVIRT_VARS["OVIRT_ISCSI_NAME"] set_iscsi_initiator(iscsi_name) # login to target and setup disk get_targets = ("iscsiadm -m discovery -p %s:%s -t sendtargets" % (_functions.OVIRT_VARS["OVIRT_ISCSI_TARGET_HOST"], _functions.OVIRT_VARS["OVIRT_ISCSI_TARGET_PORT"])) _functions.system(get_targets) before_login_drvs = self.get_dev_name() logger.debug(before_login_drvs) login_cmd = ("iscsiadm -m node -T %s -p %s:%s -l" % (_functions.OVIRT_VARS["OVIRT_ISCSI_TARGET_NAME"], _functions.OVIRT_VARS["OVIRT_ISCSI_TARGET_HOST"], _functions.OVIRT_VARS["OVIRT_ISCSI_TARGET_PORT"])) _functions.system(login_cmd) _functions.system("multipath -r") after_login_drvs = self.get_dev_name() logger.debug(after_login_drvs) logger.info("iSCSI enabled, partitioning boot drive: %s" % self.BOOTDRIVE) _functions.wipe_partitions(self.BOOTDRIVE) self.reread_partitions(self.BOOTDRIVE) logger.info("Creating boot partition") parted_cmd = "parted %s -s \"mklabel %s\"" % (self.BOOTDRIVE, self.LABEL_TYPE) _functions.system(parted_cmd) self.create_efi_partition() boot_end_mb = self.EFI_SIZE + self.BOOT_SIZE parted_cmd = ("parted \"%s\" -s \"mkpart primary ext2 %sM %sM\"" % (self.BOOTDRIVE, self.EFI_SIZE, boot_end_mb)) _functions.system(parted_cmd) parted_cmd = ("parted \"%s\" -s \"mkpart primary ext2 %sM %sM\"" % (self.BOOTDRIVE , boot_end_mb, boot_end_mb + self.BOOT_SIZE)) _functions.system(parted_cmd) parted_cmd = ("parted \"" + self.BOOTDRIVE + "\" -s \"set 1 " + "boot on\"") _functions.system(parted_cmd) self.reread_partitions(self.BOOTDRIVE) partboot = self.BOOTDRIVE + "2" partbootbackup = self.BOOTDRIVE + "3" if not os.path.exists(partboot): logger.debug("%s does not exist" % partboot) partboot = self.BOOTDRIVE + "p2" partbootbackup = self.BOOTDRIVE + "p3" # sleep to ensure filesystems are created before continuing _functions.system("udevadm settle") _functions.system("mke2fs \"" + str(partboot) + "\" -L Boot") _functions.system("tune2fs -c 0 -i 0 \"" + str(partboot) + "\"") _functions.system("ln -snf \"" + partboot + \ "\" /dev/disk/by-label/Boot") _functions.system("mke2fs \"" + str(partbootbackup) + \ "\" -L BootBackup") _functions.system("tune2fs -c 0 -i 0 \"" + \ str(partbootbackup) + "\"") _functions.system("ln -snf \"" + partbootbackup + "\" /dev/disk/by-label/BootBackup") self.ISCSIDRIVE = _functions.translate_multipath_device( _functions.OVIRT_VARS["OVIRT_ISCSI_INIT"]) logger.debug(self.ISCSIDRIVE) if self.create_iscsiroot(): logger.info("iSCSI Root Partitions Created") if self.create_hostvg(): if len(self.APPVGDRIVE) > 0: self.create_appvg() logger.info("Completed!") return True if ("OVIRT_ROOT_INSTALL" in _functions.OVIRT_VARS and _functions.OVIRT_VARS["OVIRT_ROOT_INSTALL"] == "y" and not \ _functions.is_iscsi_install()): logger.info("Partitioning root drive: " + self.ROOTDRIVE) _functions.wipe_partitions(self.ROOTDRIVE) self.reread_partitions(self.ROOTDRIVE) logger.info("Labeling Drive: " + self.ROOTDRIVE) parted_cmd = ("parted \"" + self.ROOTDRIVE + "\" -s \"mklabel " + self.LABEL_TYPE + "\"") _functions.passthrough(parted_cmd, logger.debug) logger.debug("Creating Root and RootBackup Partitions") if _functions.is_efi_boot(): self.create_efi_partition() else: # create partition labeled bios_grub parted_cmd = ("parted \"" + self.ROOTDRIVE + "\" -s \"mkpart primary 1M " + str(self.EFI_SIZE) + "M\"") _functions.passthrough(parted_cmd, logger.debug) parted_cmd = ("parted \"" + self.ROOTDRIVE + "\" -s \"set 1 bios_grub on\"") _functions.passthrough(parted_cmd, logger.debug) parted_cmd = ("parted \"" + self.ROOTDRIVE + "\" -s \"mkpart primary ext2 " + str(self.EFI_SIZE) + "M " + str(self.Root_end) + "M\"") _functions.passthrough(parted_cmd, logger.debug) parted_cmd = ("parted \"" + self.ROOTDRIVE + "\" -s \"mkpart primary ext2 " + str(self.Root_end) + "M " + str(self.RootBackup_end) + "M\"") logger.debug(parted_cmd) _functions.system(parted_cmd) _functions.system("sync ; udevadm settle ; partprobe") parted_cmd = ("parted \"" + self.ROOTDRIVE + "\" -s \"set 2 boot on\"") logger.debug(parted_cmd) _functions.system(parted_cmd) # force reload some cciss devices will fail to mkfs _functions.system("multipath -r &>/dev/null") self.reread_partitions(self.ROOTDRIVE) partroot = self.ROOTDRIVE + "2" partrootbackup = self.ROOTDRIVE + "3" if not os.path.exists(partroot): partroot = self.ROOTDRIVE + "p2" partrootbackup = self.ROOTDRIVE + "p3" _functions.system("mke2fs \"" + partroot + "\" -L Root") _functions.system("tune2fs -c 0 -i 0 \"" + partroot + "\"") _functions.system("ln -snf \"" + partrootbackup + "\" /dev/disk/by-label/RootBackup") _functions.system("mke2fs \"" + partrootbackup + \ "\" -L RootBackup") _functions.system("tune2fs -c 0 -i 0 \"" + partrootbackup + "\"") hostvg1 = self.HOSTVGDRIVE.split(",")[0] self.reread_partitions(self.ROOTDRIVE) if self.ROOTDRIVE != hostvg1: _functions.system("parted \"" + hostvg1 + "\" -s \"mklabel " + self.LABEL_TYPE + "\"") if self.create_hostvg(): if len(self.APPVGDRIVE) > 0: self.create_appvg() else: return False if ("OVIRT_CRYPT_SWAP2" in _functions.OVIRT_VARS or "OVIRT_CRYPT_SWAP" in _functions.OVIRT_VARS): _functions.ovirt_store_config("/etc/ovirt-crypttab") return True
def create_hostvg(self): logger.info("Creating LVM partition") self.physical_vols = [] for drv in self.HOSTVGDRIVE.strip(",").split(","): drv = _functions.translate_multipath_device(drv) if drv != "": if self.ROOTDRIVE == drv and not _functions.is_iscsi_install(): self.reread_partitions(self.ROOTDRIVE) parted_cmd = ("parted \"" + drv + "\" -s \"mkpart " + "primary ext2 " + str(self.RootBackup_end) + "M -1\"") logger.debug(parted_cmd) _functions.system(parted_cmd) hostvgpart = "4" elif self.BOOTDRIVE == drv: parted_cmd = ("parted \"" + drv + "\" -s \"mkpart " + "primary ext2 " + str(self.boot_size_si * 2) + " -1\"") logger.debug(parted_cmd) _functions.system(parted_cmd) hostvgpart = "3" self.ROOTDRIVE = self.BOOTDRIVE elif self.ISCSIDRIVE == drv: parted_cmd = ("parted \"" + drv + "\" -s \"mkpart " + "primary ext2 " + str(self.ROOT_SIZE * 2) + " -1\"") logger.debug(parted_cmd) _functions.system(parted_cmd) hostvgpart = "3" else: _functions.system("parted \"" + drv + "\" -s \"mklabel " + self.LABEL_TYPE + "\"") parted_cmd = ("parted \"" + drv + "\" -s \"mkpart " + "primary ext2 1M -1 \"") logger.debug(parted_cmd) _functions.system(parted_cmd) hostvgpart = "1" logger.info("Toggling LVM on") parted_cmd = ("parted \"" + drv + "\" -s \"set " + str(hostvgpart) + " lvm on\"") logger.debug(parted_cmd) _functions.system(parted_cmd) _functions.system("parted \"" + self.ROOTDRIVE + \ "\" -s \"print\"") _functions.system("udevadm settle 2> /dev/null || " + \ "udevsettle &>/dev/null") # sync GPT to the legacy MBR partitions if ("OVIRT_INSTALL_ROOT" in _functions.OVIRT_VARS and _functions.OVIRT_VARS["OVIRT_INSTALL_ROOT"] == "y"): if self.LABEL_TYPE == "gpt": logger.info("Running gptsync to create legacy mbr") _functions.system("gptsync \"" + \ self.ROOTDRIVE + "\"") self.physical_vols.append((drv, hostvgpart)) drv_count = 0 logger.debug(self.physical_vols) for drv, hostvgpart in self.physical_vols: partpv = None logger.info("Creating physical volume on (%s, %s)" % (drv, hostvgpart)) for _drv in self.HOSTVGDRIVE.strip(",").split(","): self.reread_partitions(_drv) i = 15 while i > 0 and partpv is None: # e.g. /dev/cciss/c0d0p2 for _partpv in [drv + hostvgpart, drv + "p" + hostvgpart]: if os.path.exists(_partpv): partpv = _partpv break logger.info(_partpv + " is not available!") i -= 1 time.sleep(1) if i is 0: return False assert(partpv is not None) if not _functions.system("dd if=/dev/zero of=\"" + partpv + "\" bs=1024k count=1"): logger.error("Failed to wipe lvm partition") return False if not _functions.system("pvcreate -ff -y \"" + partpv + "\""): logger.error("Failed to pvcreate on " + partpv) return False if drv_count < 1: logger.info("Creating volume group on " + partpv) if not _functions.system("vgcreate /dev/HostVG \"" + \ partpv + "\""): logger.error("Failed to vgcreate /dev/HostVG on " + partpv) return False else: logger.info("Extending volume group on " + partpv) if not _functions.system("vgextend /dev/HostVG \"" + \ partpv + "\""): logger.error("Failed to vgextend /dev/HostVG on " + partpv) return False drv_count = drv_count + 1 if self.SWAP_SIZE > 0: logger.info("Creating swap partition") _functions.system("lvcreate --name Swap --size " + \ str(self.SWAP_SIZE) + "M /dev/HostVG") _functions.system("mkswap -L \"SWAP\" /dev/HostVG/Swap") _functions.system_closefds("echo \"/dev/HostVG/Swap swap swap " + "defaults 0 0\" >> /etc/fstab") if "OVIRT_CRYPT_SWAP" in _functions.OVIRT_VARS: _functions.system_closefds("echo \"SWAP /dev/HostVG/Swap " + "/dev/mapper/ovirt-crypt-swap " + _functions.OVIRT_VARS["OVIRT_CRYPT_SWAP"] + "\" >> /etc/ovirt-crypttab") if self.CONFIG_SIZE > 0: logger.info("Creating config partition") _functions.system("lvcreate --name Config --size " + str(self.CONFIG_SIZE) + "M /dev/HostVG") _functions.system("mke2fs -j -t ext4 /dev/HostVG/Config " + \ "-L \"CONFIG\"") _functions.system("tune2fs -c 0 -i 0 /dev/HostVG/Config") if self.LOGGING_SIZE > 0: logger.info("Creating log partition") _functions.system("lvcreate --name Logging --size " + str(self.LOGGING_SIZE) + "M /dev/HostVG") _functions.system("mke2fs -j -t ext4 /dev/HostVG/Logging " + \ "-L \"LOGGING\"") _functions.system("tune2fs -c 0 -i 0 /dev/HostVG/Logging") _functions.system_closefds("echo \"/dev/HostVG/Logging " + \ "/var/log ext4 defaults,noatime 0 0\" >> " + \ "/etc/fstab") use_data = 1 if self.DATA_SIZE == -1: logger.info("Creating data partition with remaining free space") _functions.system("lvcreate --name Data -l 100%FREE /dev/HostVG") use_data = 0 elif self.DATA_SIZE > 0: logger.info("Creating data partition") _functions.system("lvcreate --name Data --size " + \ str(self.DATA_SIZE) + "M /dev/HostVG") use_data = 0 if use_data == 0: _functions.system("mke2fs -j -t ext4 /dev/HostVG/Data -L \"DATA\"") _functions.system("tune2fs -c 0 -i 0 /dev/HostVG/Data") _functions.system_closefds("echo \"/dev/HostVG/Data /data ext4 " + "defaults,noatime 0 0\" >> /etc/fstab") _functions.system_closefds("echo \"/data/images " + \ "/var/lib/libvirt/images bind bind 0 0\" >> " + \ "/etc/fstab") _functions.system_closefds("echo \"/data/core " + \ "/var/log/core bind bind 0 0\" >> /etc/fstab") logger.info("Mounting config partition") _functions.mount_config() if os.path.ismount("/config"): _functions.ovirt_store_config("/etc/fstab") # remount /var/log from tmpfs to HostVG/Logging _functions.unmount_logging() _functions.mount_logging() if use_data == 0: logger.info("Mounting data partition") _functions.mount_data() logger.info("Completed HostVG Setup!") return True
def persist(self, filename): """Persist a file and bind mount it """ if filename and self.is_enabled(): from ovirtnode import ovirtfunctions return ovirtfunctions.ovirt_store_config(filename)
def imvp_apply(self, obj): from ocsetup.ocsetup import ocs log("enter imvp apply %s") imvp_server_address = ocs.imvp_server_addr_val_Entry.get_text() imvp_server_port = ocs.imvp_serve_port_val_Entry.get_text() compatPort, sslPort = compatiblePort(imvp_server_port) if len(imvp_server_address) > 0: deployUtil.nodeCleanup() if not isHostReachable(host=imvp_server_address, port=imvp_server_port, ssl=sslPort, timeout=TIMEOUT_FIND_HOST_SEC): if compatPort is None: # Try one more time with SSL=False if not isHostReachable(host=imvp_server_address, port=imvp_server_port, ssl=False, timeout=TIMEOUT_FIND_HOST_SEC): msgConn = "Can't connect to oVirt Engine in the specific" \ " port %s" % enginePort resp_id = ConfirmDialog( message=msgConn).run_and_close() return False else: msgConn = "Can't connect to oVirt Engine port %s," \ " trying compatible port %s" % \ (enginePort, compatPort) resp_id = ConfirmDialog(message=msgConn).run_and_close() if not isHostReachable(host=imvp_server_address, port=compatPort, ssl=sslPort, timeout=TIMEOUT_FIND_HOST_SEC): msgConn = "Can't connect to oVirt Engine using" \ " compatible port %s" % compatPort resp_id = ConfirmDialog( message=msgConn).run_and_close() return False else: # compatible port found enginePort = compatPort if True: if deployUtil.getRhevmCert(imvp_server_address, enginePort): path, dontCare = deployUtil.certPaths('') fp = deployUtil.generateFingerPrint(path) ovirt_store_config(path) else: msgConn = "Failed downloading IMVP certificate" resp_id = ConfirmDialog(message=msgConn).run_and_close() # Stopping vdsm-reg may fail but its ok - its in the case when the menus are run after installation deployUtil._logExec([constants.EXT_SERVICE, 'vdsm-reg', 'stop']) if write_vdsm_config(imvp_server_address, enginePort): deployUtil._logExec( [constants.EXT_SERVICE, 'vdsm-reg', 'start']) msgConn = "@ENGINENAME@ Configuration Successfully Updated" resp_id = ConfirmDialog(message=msgConn).run_and_close() retWriteConf = True else: msgConn = "@ENGINENAME@ Configuration Failed" resp_id = ConfirmDialog(message=msgConn).run_and_close() retWriteConf = False return retWriteConf