def setNetworking(self, iurl): """ Create management bridge. This class will try to create a management bridge. Note: expected input format: http://www.redhat.com/a/b/c or: ftp://10.0.0.23/d/e/f """ self.status = "OK" self.rc = True self.message = "Created management bridge." if rhel6based: deployUtil.setService("messagebus", "start") deployUtil.setService("libvirtd", "start") if deployUtil.preventDuplicate(bridgeName=self._bridgeName): self.message = "Bridge management already exists. Skipping " \ "bridge creation." logging.debug(self.message) else: url, port = deployUtil.getAddress(iurl) if url is None: self.message = "Failed to parse manager URL!" self.status = "FAIL" logging.error(self.message) # Do not set rc to allow changes from Engine else: if not self._addNetwork(url, port): self.status = "FAIL" self.rc = False self._xmlOutput('SetNetworking', self.status, None, None, self.message) return self.rc
def verifyServices(self): """ Make sure needed services are on in vdsm relevant runlevels. """ self.message = 'Needed services set' self.rc = True self.status = 'OK' for srv in CONFLICT_SERVICES: deployUtil.setService(srv, "stop") out, err, ret = deployUtil.chkConfig(srv, "off") if ret: message = "VerifyServices: Failed to unset conflicting " \ "service " + srv + "." logging.error(self.message) logging.error("Details: " + str(out) + "\n" + str(err)) self._xmlOutput('VerifyServices', 'WARN', None, None, message) if self.status == 'OK': for srv in NEEDED_SERVICES: out, err, ret = deployUtil.chkConfig(srv, "on", "345") if ret: self.message = "VerifyServices: Failed to set service " + \ srv + "." self.status = 'FAIL' logging.error(self.message) logging.error("Details: " + str(out) + "\n" + str(err)) break self._xmlOutput('VerifyServices', self.status, None, None, self.message) return self.rc
def packagesExplorer(self, iurl, rev_num, usevdcrepo=False): """ Check and install software packages """ self._initPackagesExplorer(iurl, rev_num, usevdcrepo) self._avoidPKGConflict() if len(self.confl_pack) > 0: self.res = "FAIL" self.rc = 1 self.message = "Conflicting packages found: " + str(self.confl_pack) logging.error(self.message) self._xmlOutput('CONFL', self.res, "result", "conflict found", self.message) self._delPKG() if len(self.del_pack) > 0: self.rc = self._delPackages() if not self.rc: self._getAllPackages() deployUtil.setService("vdsmd", "stop") self._installPackages() if self.usevdcrepo: os.unlink(DTV_REPO) return self.rc
def setNetworking(self, iurl): """ Create management bridge. This class will try to create a management bridge. Note: expected input format: http://www.redhat.com/a/b/c or: ftp://10.0.0.23/d/e/f """ self.status = "OK" self.rc = True self.message = "Created management bridge." if rhel6based: deployUtil.setService("messagebus", "start") deployUtil.setService("libvirtd", "start") if deployUtil.preventDuplicate(bridgeName=self._bridgeName): self.message = "Bridge management already exists. Skipping " \ "bridge creation." logging.debug(self.message) else: url, port = deployUtil.getAddress(iurl) if url is None: self.message = "Failed to parse manager URL!" self.status = "FAIL" logging.error(self.message) #Do not set rc to allow changes from Engine else: if not self._addNetwork(url, port): self.status = "FAIL" self.rc = False self._xmlOutput('SetNetworking', self.status, None, None, self.message) return self.rc
def packagesExplorer(self, iurl, rev_num, usevdcrepo=False): """ Check and install software packages """ self._initPackagesExplorer(iurl, rev_num, usevdcrepo) self._avoidPKGConflict() if len(self.confl_pack) > 0: self.res = "FAIL" self.rc = 1 self.message = "Conflicting packages found: " + str( self.confl_pack) logging.error(self.message) self._xmlOutput('CONFL', self.res, "result", "conflict found", self.message) self._delPKG() if len(self.del_pack) > 0: self.rc = self._delPackages() if not self.rc: self._getAllPackages() deployUtil.setService("vdsmd", "stop") self._installPackages() if self.usevdcrepo: os.unlink(DTV_REPO) return self.rc
def main(): """Usage: vds_bootstrap_complete.py [-c vds_config_str] [-v <ver>] [-V] [-g] <random_num> [reboot]""" try: vds_config_str = None # FIXME: these flags are added for near future use installVirtualizationService = True installGlusterService = False opts, args = getopt.getopt(sys.argv[1:], "v:c:Vg") for o, v in opts: if o == "-v": deployUtil.setBootstrapInterfaceVersion(int(v)) if o == "-c": # it should looks like: # 'ssl=true;ksm_nice=5;images=/images/irsd' without white # spaces in it. vds_config_str = v if o == "-V": installVirtualizationService = False if o == "-g": installGlusterService = True logging.debug("installVirtualizationService = '%s', " "installGlusterService = '%s'" % (installVirtualizationService, installGlusterService)) rnum = args[0] except: print main.__doc__ return False try: arg = int(args[1]) except: arg = 1 res = True try: res = deployUtil.instCert(rnum, VDSM_CONF_FILE) if res: res = deployUtil.setCoreDumpPath() if res: res = deployUtil.cleanAll(rnum) if res: try: deployUtil.setVdsConf(vds_config_str, VDSM_CONF_FILE) print "<BSTRAP component='VDS Configuration' status='OK'/>" except Exception, err: res = False print "<BSTRAP component='VDS Configuration' status='FAIL'" \ " message='%s'/>" % deployUtil.escapeXML(str(err)) deployUtil.setService("vdsmd", "reconfigure")
def main(): """Usage: vds_bootstrap_complete.py [-c vds_config_str] [-v <ver>] [-V] [-g] <random_num> [reboot]""" try: vds_config_str = None #FIXME: these flags are added for near future use installVirtualizationService = True installGlusterService = False opts, args = getopt.getopt(sys.argv[1:], "v:c:Vg") for o, v in opts: if o == "-v": deployUtil.setBootstrapInterfaceVersion(int(v)) if o == "-c": # it should looks like: # 'ssl=true;ksm_nice=5;images=/images/irsd' without white # spaces in it. vds_config_str = v if o == "-V": installVirtualizationService = False if o == "-g": installGlusterService = True logging.debug("installVirtualizationService = '%s', " "installGlusterService = '%s'" % (installVirtualizationService, installGlusterService)) rnum = args[0] except: print main.__doc__ return False try: arg = int(args[1]) except: arg = 1 res = True try: res = deployUtil.instCert(rnum, VDSM_CONF_FILE) if res: res = deployUtil.setCoreDumpPath() if res: res = deployUtil.cleanAll(rnum) if res: try: deployUtil.setVdsConf(vds_config_str, VDSM_CONF_FILE) print "<BSTRAP component='VDS Configuration' status='OK'/>" except Exception, err: res = False print "<BSTRAP component='VDS Configuration' status='FAIL'" \ " message='%s'/>" % deployUtil.escapeXML(str(err)) deployUtil.setService("vdsmd", "reconfigure")
def main(): """Usage: vds_bootstrap_complete.py [-c vds_config_str] [-v] [-g] <random_num> [reboot]""" try: vds_config_str = None #FIXME: these flags are added for near future use installVirtualizationService = False installGlusterService = False opts, args = getopt.getopt(sys.argv[1:], "c:vg") for o,v in opts: if o == "-c": # it should looks like: 'ssl=true;ksm_nice=5;images=/images/irsd' # without white spaces in it. vds_config_str = v if o == "-v": installVirtualizationService = True if o == "-g": installGlusterService = True logging.debug("installVirtualizationService = '%s', installGlusterService = '%s'"%(installVirtualizationService, installGlusterService)) rnum = args[0] except: print main.__doc__ return 0 try: arg = int(args[1]) except: arg = 1 res = True try: res = deployUtil.instCert(rnum, VDSM_CONF_FILE) if res: res = deployUtil.setCoreDumpPath() if res: res = deployUtil.cleanAll(rnum) if res: res = deployUtil.setVdsConf(vds_config_str, VDSM_CONF_FILE) deployUtil.setService("vdsmd", "reconfigure") except: logging.error('bootstrap complete failed', exc_info=True) res = False if res: print "<BSTRAP component='RHEV_INSTALL' status='OK'/>" sys.stdout.flush() Reboot(arg) else: print "<BSTRAP component='RHEV_INSTALL' status='FAIL'/>" sys.stdout.flush()
def main(): """Usage: vds_bootstrap_complete.py [-c vds_config_str] <random_num> [reboot]""" try: vds_config_str = None opts, args = getopt.getopt(sys.argv[1:], "c:") for o,v in opts: if o == "-c": # it should looks like: 'ssl=true;ksm_nice=5;images=/images/irsd' # without white spaces in it. vds_config_str = v rnum = args[0] except: print main.__doc__ return 0 try: arg = args[1] except: arg = 1 res = True try: res = deployUtil.instCert(rnum, VDSM_CONF_FILE) if res: res = deployUtil.setCoreDumpPath() if res: res = deployUtil.cleanAll(rnum) if res: res = deployUtil.setVdsConf(vds_config_str, VDSM_CONF_FILE) deployUtil.setService("vdsmd", "reconfigure") Reboot(arg) except: logging.error('bootstrap complete failed', exc_info=True) res = False if res: print "<BSTRAP component='RHEV_INSTALL' status='OK'/>" else: print "<BSTRAP component='RHEV_INSTALL' status='FAIL'/>" sys.stdout.flush()
def main(): """Usage: vds_bootstrap_complete.py [-c vds_config_str] <random_num> [reboot]""" try: vds_config_str = None opts, args = getopt.getopt(sys.argv[1:], "c:") for o, v in opts: if o == "-c": # it should looks like: 'ssl=true;ksm_nice=5;images=/images/irsd' # without white spaces in it. vds_config_str = v rnum = args[0] except: print main.__doc__ return 0 try: arg = args[1] except: arg = 1 res = True try: res = deployUtil.instCert(rnum, VDSM_CONF_FILE) if res: res = deployUtil.setCoreDumpPath() if res: res = deployUtil.cleanAll(rnum) if res: res = deployUtil.setVdsConf(vds_config_str, VDSM_CONF_FILE) deployUtil.setService("vdsmd", "reconfigure") Reboot(arg) except: logging.error('bootstrap complete failed', exc_info=True) res = False if res: print "<BSTRAP component='RHEV_INSTALL' status='OK'/>" else: print "<BSTRAP component='RHEV_INSTALL' status='FAIL'/>" sys.stdout.flush()
def Reboot(act=1): """ Reboot: Either reboots the machine or restarts the vdsmd service. """ logging.debug("Reboot: started.") action = 'Reboot' message = 'Rebooting machine' if (act==1): deployUtil.reboot() else: action = 'Restart' message = 'Restarting vdsmd service' deployUtil.setService("vdsmd", "restart") result = "<BSTRAP component='" + action + "' status='OK' message='" + message + "' />" logging.debug(result) print result sys.stdout.flush() logging.debug("Reboot: ended.")
def Reboot(act=1): """ Reboot: Either reboots the machine or restarts the vdsmd service. """ logging.debug("Reboot: started.") action = 'Reboot' message = 'Rebooting machine' if (act == 1): deployUtil.reboot() else: action = 'Restart' message = 'Restarting vdsmd service' deployUtil.setService("vdsmd", "restart") result = "<BSTRAP component='" + action + "' status='OK' message='" + \ message + "' />" logging.debug(result) print result sys.stdout.flush() logging.debug("Reboot: ended.")
def update_and_restart_vdsm_reg(url_bs, engine_port, ticket): from urlparse import urlparse try: import deployUtil except: printNlog( "<BSTRAP component='INIT' status='FAIL' message='Error trying to deploy library.'/>" ) logging.error(traceback.format_exc()) return False return_value = False if not os.path.exists(vdsm_reg_conf_file): message = "Error trying to configure registration service." printNlog( "<BSTRAP component='UPDATE_VDSM_REG_CONF' status='FAIL' message='%s'/>" % (message)) logging.debug("file %s does not exist", vdsm_reg_conf_file) else: vdc_url = urlparse(url_bs) if engine_port is None: if vdc_url.port is not None: engine_port = str(vdc_url.port) if engine_port is not None: deployUtil._updateFileLine(vdsm_reg_conf_file, "vdc_host_port", str(engine_port), True) deployUtil._updateFileLine(vdsm_reg_conf_file, "vdc_host_name", str(vdc_url.hostname), True) deployUtil._updateFileLine(vdsm_reg_conf_file, "ticket", str(ticket), True) deployUtil.ovirtfunctions.ovirt_store_config(vdsm_reg_conf_file) if handle_ssh_key(vdc_url.hostname, str(engine_port)): out, err, return_code = deployUtil.setService( 'vdsm-reg', 'restart') else: return_code = None if not return_code: return_value = True return return_value
def update_and_restart_vdsm_reg(url_bs, engine_port, ticket): from urlparse import urlparse try: import deployUtil except: printNlog("<BSTRAP component='INIT' status='FAIL' message='Error trying to deploy library.'/>") logging.error(traceback.format_exc()) return False return_value = False if not os.path.exists(vdsm_reg_conf_file): message = "Error trying to configure registration service." printNlog("<BSTRAP component='UPDATE_VDSM_REG_CONF' status='FAIL' message='%s'/>" % (message) ) logging.debug("file %s does not exist", vdsm_reg_conf_file) else: vdc_url = urlparse(url_bs) if engine_port is None: if vdc_url.port is not None: engine_port = str(vdc_url.port) if engine_port is not None: deployUtil._updateFileLine(vdsm_reg_conf_file, "vdc_host_port", str(engine_port), True) deployUtil._updateFileLine(vdsm_reg_conf_file, "vdc_host_name", str(vdc_url.hostname), True) deployUtil._updateFileLine(vdsm_reg_conf_file, "ticket", str(ticket), True) deployUtil.ovirtfunctions.ovirt_store_config(vdsm_reg_conf_file) if handle_ssh_key(vdc_url.hostname, str(engine_port)): out, err, return_code = deployUtil.setService('vdsm-reg', 'restart') else: return_code = None if not return_code: return_value = True return return_value
def VdsValidation(iurl, subject, random_num, rev_num, orgName, systime, firewallRulesFile, engine_ssh_key, installVirtualizationService, installGlusterService, bridgeName, miniyum): """ --- Check VDS Compatibility. """ logging.debug("Entered VdsValidation(subject = '%s', random_num = '%s', " "rev_num = '%s', installVirtualizationService = '%s', " "installGlusterService = '%s', bridgeName = '%s')" % (subject, random_num, rev_num, installVirtualizationService, installGlusterService, bridgeName)) if installGlusterService: if not rhel6based: logging.error('unsupported system for Gluster service') return False oDeploy = Deploy(bridgeName=bridgeName) if systime: if not oDeploy.setSystemTime(systime): logging.error('setSystemTime failed') return False if not oDeploy.checkRegistration(): logging.error('checkRegistration test failed') return False if not oDeploy.checkMajorVersion(): logging.error('checkMajorVersion test failed') return False if installVirtualizationService: logging.debug('virtExplorer testing') if not oDeploy.virtExplorer(random_num): logging.error('virtExplorer test failed') return False if not oDeploy.osExplorer(): logging.error('osExplorer test failed') return False if not oDeploy.kernelArgs(): logging.error('kernelArgs failed') return False # # stop vdsm at this point, # before any setting is changed. # # stopping vdsm at installation is important # so master will not connect to the old instance # before reboot. # deployUtil.setService("vdsmd", "stop") if miniyum is not None: try: with miniyum.transaction(): miniyum.clean(['expire-cache']) with miniyum.transaction(): miniyum.install(('qemu-kvm-tools',)) miniyum.installUpdate(('vdsm', 'vdsm-cli')) if installGlusterService: miniyum.install(('glusterfs-rdma', 'glusterfs-geo-replication')) miniyum.installUpdate(('vdsm-gluster',)) if miniyum.buildTransaction(): miniyum.processTransaction() except: logging.error('package installation failed', exc_info=True) return False else: if oDeploy.packagesExplorer(): logging.error('packagesExplorer test failed') return False if installGlusterService: if oDeploy.installGlusterPackages(): logging.error('installGlusterPackages failed') return False if not oDeploy.createConf(): logging.error('createConf failed') return False if rhel6based: if not oDeploy.checkLocalHostname(): logging.error('checkLocalHostname test failed') return False if not oDeploy.setNetworking(iurl): logging.error('setNetworking test failed') return False if not oDeploy.setSSHAccess(iurl, engine_ssh_key): logging.error('setSSHAccess test failed') return False if firewallRulesFile: if not oDeploy.overrideFirewall(firewallRulesFile): logging.error('Failed to set default firewall') return False if not oDeploy.verifyServices(): logging.error('verifyServices failed') return False oDeploy.setCertificates(subject, random_num, orgName) return True
def main(): """ Usage: register-to-engine.py [-f | --force] [-p PORT | --port PORT] OVIRT_ENGINE """ port = None force = False try: opts, args = getopt.getopt(sys.argv[1:], "hfp:", ["help", "force", "port="]) if len(args) != 1: usage() sys.exit(USAGE_ERROR) newVdcHostName = args[0] for o, v in opts: if o in ("-h", "--help"): usage() sys.exit(SUCCESS) elif o in ("-p", "--port"): try: port = int(v) except ValueError: sys.stderr.write('invalid port: %s\n' % v) sys.exit(INVALID_PORT_ERROR) elif o in ("-f", "--force"): force = True except getopt.GetoptError as e: sys.stderr.write("ERROR: %s\n" % (e.msg)) usage() sys.exit(USAGE_ERROR) config.read(VDSM_REG_CONF_FILE) if not port: try: port = config.get('vars', 'vdc_host_port') except ConfigParser.NoOptionError: sys.stderr.write("Failed to retrieve port number " "from config file: %s\n" % VDSM_REG_CONF_FILE) sys.exit(CONF_FILE_READ_ERROR) try: vdcHostName = config.get('vars', 'vdc_host_name') except ConfigParser.NoOptionError: vdcHostName = None if not force and vdcHostName and "NONE" != vdcHostName.upper(): sys.stdout.write('Node already configured to Engine %s\n' % vdcHostName) sys.stdout.write('Do you want to reset and use %s (yes/NO): ' % newVdcHostName) ans = sys.stdin.readline() if "YES" != ans.strip().upper(): sys.exit(0) if not isHostReachable(newVdcHostName, port): if not isHostReachable(newVdcHostName, port, ssl=False): sys.stderr.write('Engine %s ' % newVdcHostName + ' is not reachable by HTTP or HTTPS\n') sys.exit(OVIRT_ENGINE_NOT_REACHABLE_ERROR) if not deployUtil.setVdsConf("vdc_host_name=%s" % newVdcHostName, VDSM_REG_CONF_FILE): sys.exit(CONF_FILE_WRITE_ERROR) if not deployUtil.setVdsConf("vdc_host_port=%s" % port, VDSM_REG_CONF_FILE): sys.exit(CONF_FILE_WRITE_ERROR) out, err, rv = deployUtil.setService("vdsm-reg", "restart") if rv != 0: sys.stderr.write("Failed to restart vdsm-reg service: ") sys.stderr.write("(%s, %s, %s)\n" % (rv, out, err)) sys.exit(VDSM_REG_RESTART_FAILED_ERROR) sys.exit(SUCCESS)
def VdsValidation(iurl, subject, random_num, rev_num, orgName, systime, firewallRulesFile, engine_ssh_key, installVirtualizationService, installGlusterService, bridgeName, miniyum): """ --- Check VDS Compatibility. """ logging.debug("Entered VdsValidation(subject = '%s', random_num = '%s', " "rev_num = '%s', installVirtualizationService = '%s', " "installGlusterService = '%s', bridgeName = '%s')" % (subject, random_num, rev_num, installVirtualizationService, installGlusterService, bridgeName)) if installGlusterService: if not rhel6based: logging.error('unsupported system for Gluster service') return False oDeploy = Deploy(bridgeName=bridgeName) if systime: if not oDeploy.setSystemTime(systime): logging.error('setSystemTime failed') return False if not oDeploy.checkRegistration(): logging.error('checkRegistration test failed') return False if not oDeploy.checkMajorVersion(): logging.error('checkMajorVersion test failed') return False if installVirtualizationService: logging.debug('virtExplorer testing') if not oDeploy.virtExplorer(random_num): logging.error('virtExplorer test failed') return False if not oDeploy.osExplorer(): logging.error('osExplorer test failed') return False if not oDeploy.kernelArgs(): logging.error('kernelArgs failed') return False # # stop vdsm at this point, # before any setting is changed. # # stopping vdsm at installation is important # so master will not connect to the old instance # before reboot. # deployUtil.setService("vdsmd", "stop") if miniyum is not None: try: with miniyum.transaction(): miniyum.clean(['expire-cache']) with miniyum.transaction(): miniyum.install(('qemu-kvm-tools', )) miniyum.installUpdate(('vdsm', 'vdsm-cli')) if installGlusterService: miniyum.install( ('glusterfs-rdma', 'glusterfs-geo-replication')) miniyum.installUpdate(('vdsm-gluster', )) if miniyum.buildTransaction(): miniyum.processTransaction() except: logging.error('package installation failed', exc_info=True) return False else: if oDeploy.packagesExplorer(): logging.error('packagesExplorer test failed') return False if installGlusterService: if oDeploy.installGlusterPackages(): logging.error('installGlusterPackages failed') return False if not oDeploy.createConf(): logging.error('createConf failed') return False if rhel6based: if not oDeploy.checkLocalHostname(): logging.error('checkLocalHostname test failed') return False if not oDeploy.setNetworking(iurl): logging.error('setNetworking test failed') return False if not oDeploy.setSSHAccess(iurl, engine_ssh_key): logging.error('setSSHAccess test failed') return False if firewallRulesFile: if not oDeploy.overrideFirewall(firewallRulesFile): logging.error('Failed to set default firewall') return False if not oDeploy.verifyServices(): logging.error('verifyServices failed') return False oDeploy.setCertificates(subject, random_num, orgName) return True