def read_ini(self, device, filename, required=False): filepath = os.path.join(device.zOpenStackNeutronConfigDir, filename) log.info("Retrieving %s", filepath) # host based installation cmd = "cat %s" % filepath if device.zOpenStackRunNeutronCommonInContainer: # container based installation cmd = container_cmd_wrapper( device.zOpenStackRunNeutronCommonInContainer, "cat %s" % \ filepath ) d = yield self.client.run(cmd, timeout=self.timeout) if d.exitCode != 0 or d.stderr: if required: log.error("Unable to access required file %s (%s)" % (filepath, d.stderr.strip())) self.sendFileErrorEvent(device, filepath, d.stderr) else: log.info("Unable to access optional file %s (%s)" % (filepath, d.stderr.strip())) defer.returnValue(None) return self.sendFileClearEvent(device, filepath) ini = ConfigParser.RawConfigParser(allow_no_value=True) ini.readfp(io.BytesIO(d.output)) defer.returnValue(ini) return
def collect(self, device, log): manageIp = str(device.manageIp) log.info('Connecting to ssh://%s@%s:%d' % ( device.zCommandUsername, manageIp, device.zCommandPort )) client = SSHClient({ 'hostname': manageIp, 'port': device.zCommandPort, 'user': device.zCommandUsername, 'password': device.zCommandPassword, 'identities': [device.zKeyPath], 'buffersize': 32768}) client.connect() timeout = device.zCommandCommandTimeout # host based installation cmd = "nova-manage --version 2>&1" if device.zOpenStackRunNovaManageInContainer: # container based installation cmd = container_cmd_wrapper( device.zOpenStackRunNovaManageInContainer, "nova-manage --version 2>&1" ) log.info("Running %s" % cmd) try: d = yield client.run(cmd, timeout=timeout) if d.exitCode != 0 or d.stderr: # nova conduct isn't running on this host, and should be ignored. log.info("nova conduct not running on host- not collecting nova version") return except Exception: raise finally: client.disconnect() returnValue(d.output)
def collect(self, device, log): manageIp = str(device.manageIp) log.info('Connecting to ssh://%s@%s:%d' % (device.zCommandUsername, manageIp, device.zCommandPort)) client = SSHClient({ 'hostname': manageIp, 'port': device.zCommandPort, 'user': device.zCommandUsername, 'password': device.zCommandPassword, 'identities': [device.zKeyPath], 'buffersize': 32768 }) client.connect() timeout = device.zCommandCommandTimeout # host based installation cmd = "nova-manage --version 2>&1" if device.zOpenStackRunNovaManageInContainer: # container based installation cmd = container_cmd_wrapper( device.zOpenStackRunNovaManageInContainer, "nova-manage --version 2>&1") log.info("Running %s" % cmd) try: d = yield client.run(cmd, timeout=timeout) if d.exitCode != 0 or d.stderr: # nova conduct isn't running on this host, and should be ignored. log.info( "nova conduct not running on host- not collecting nova version" ) return except Exception: raise finally: client.disconnect() returnValue(d.output)
def collect(self, device, log): manageIp = str(device.manageIp) log.info('Connecting to ssh://%s@%s:%d' % ( device.zCommandUsername, manageIp, device.zCommandPort )) client = SSHClient({ 'hostname': manageIp, 'port': device.zCommandPort, 'user': device.zCommandUsername, 'password': device.zCommandPassword, 'identities': [device.zKeyPath], 'buffersize': 32768}) client.connect() timeout = device.zCommandCommandTimeout data = {} try: for instanceId, instanceUUID in device.openstack_instanceList: # host based installation cmd = "virsh --readonly -c 'qemu:///system' dumpxml '%s'" % \ instanceUUID if device.zOpenStackRunVirshQemuInContainer: # container based installation cmd = container_cmd_wrapper( device.zOpenStackRunVirshQemuInContainer, "virsh --readonly -c 'qemu:///system' dumpxml '%s'" % \ instanceUUID) log.info("Running %s" % cmd) d = yield client.run(cmd, timeout=timeout) if d.exitCode != 0 or d.stderr: if 'Domain not found' in d.stderr: log.debug("Domain not found while running virsh (rc=%s, stderr='%s')" % (d.exitCode, d.stderr)) elif 'docker: command not found' in d.stderr: msg = 'Check zOpenStackRunNeutronCommonInContainer value' stderr = ' '.join(list(set(d.stderr.split('\n')))).lstrip() log.error("Error running virsh (rc=%s, stderr='%s'); %s" % (d.exitCode, stderr, msg)) else: log.error("Error running virsh (rc=%s, stderr='%s')" % (d.exitCode, d.stderr)) continue try: tree = etree.fromstring(d.output) instanceName = str(tree.xpath("/domain/name/text()")[0]) zenossInstanceId = 'server-%s' % (instanceUUID) data[instanceUUID] = { 'id': zenossInstanceId, 'serialNumber': str(tree.xpath("/domain/sysinfo/system/entry[@name='serial']/text()")[0]), 'biosUuid': str(tree.xpath("/domain/sysinfo/system/entry[@name='uuid']/text()")[0]) } except Exception: log.error("Invalid XML Received from (%s):\n%s\n\n" % (cmd, d.output)) raise LibvirtXMLError('Incomplete or invalid XML returned from virsh command. Consult log for more details.') vnics = [] for interface in tree.xpath("/domain/devices/interface"): target = interface.find("target/[@dev]") mac = interface.find("mac/[@address]") if target is None or mac is None: # unrecognized interface type continue # compute the resourceId in the same way that ceilometer's # net pollster does. vnicName = str(target.get('dev')) zenossVnicId = 'vnic-%s-%s' % (instanceUUID, vnicName) ceilometerResourceId = '%s-%s-%s' % (instanceName, instanceUUID, vnicName) vnics.append({ 'id': zenossVnicId, 'name': vnicName, 'macaddress': str(mac.get('address')), 'resourceId': ceilometerResourceId }) data[instanceUUID]['vnics'] = vnics finally: client.disconnect() returnValue(data)
def collect(self, device, log): manageIp = str(device.manageIp) log.info('Connecting to ssh://%s@%s:%d' % ( device.zCommandUsername, manageIp, device.zCommandPort )) self.client = SSHClient({ 'hostname': manageIp, 'port': device.zCommandPort, 'user': device.zCommandUsername, 'password': device.zCommandPassword, 'identities': [device.zKeyPath], 'buffersize': 32768}) self.client.connect() self.timeout = device.zCommandCommandTimeout data = {} required_files = ['neutron.conf'] optional_files = ['plugins/ml2/ml2_conf.ini'] plugin_names = set() try: # Check if neutron-server runs on this machine # host based installation cmd = "pgrep neutron-server" if device.zOpenStackRunNeutronCommonInContainer: # container based installation cmd = container_cmd_wrapper( device.zOpenStackRunNeutronCommonInContainer, "pgrep neutron-server" ) d = yield self.client.run(cmd, timeout=self.timeout) if d.exitCode != 0: # neutron isn't running on this host, so its config # files are suspect, and should be ignored. log.info("neutron-server not running on host- not collecting ini files") defer.returnValue(data) return # Collect ini files for filename in required_files: if filename not in data: data[filename] = yield self.read_ini(device, filename, required=True) for filename in optional_files: if filename not in data: data[filename] = yield self.read_ini(device, filename) required_files = [] optional_files = [] if data.get('neutron.conf'): ini = data['neutron.conf'] neutron_core_plugin = self.ini_get(device, filename, ini, 'DEFAULT', 'core_plugin', required=True) plugin_names.add(neutron_core_plugin) if data.get('plugins/ml2/ml2_conf.ini'): mechanism_drivers = split_list(self.ini_get( device, filename, data['plugins/ml2/ml2_conf.ini'], 'ml2', 'mechanism_drivers', required=False) or '') for mechanism_driver in mechanism_drivers: plugin_names.add("ml2." + mechanism_driver) data['plugin_names'] = set() for plugin_name in plugin_names: plugin = zope.component.queryUtility(INeutronImplementationPlugin, plugin_name) if not plugin: continue plugin_class = plugin.__class__.__name__ log.info("Checking for additinal ini requirements in neutron implementation plugin '%s': %s" % (plugin_name, plugin_class)) data['plugin_names'].add(plugin_name) for filename, section, option in plugin.ini_required(): required_files.append(filename) for filename, section, option in plugin.ini_optional(): optional_files.append(filename) for filename in required_files: if filename not in data: data[filename] = yield self.read_ini(device, filename, required=True) for filename in optional_files: if filename not in data: data[filename] = yield self.read_ini(device, filename) except Exception: raise finally: self.client.disconnect() defer.returnValue(data)
def collect(self, device, log): manageIp = str(device.manageIp) log.info('Connecting to ssh://%s@%s:%d' % (device.zCommandUsername, manageIp, device.zCommandPort)) client = SSHClient({ 'hostname': manageIp, 'port': device.zCommandPort, 'user': device.zCommandUsername, 'password': device.zCommandPassword, 'identities': [device.zKeyPath], 'buffersize': 32768 }) client.connect() timeout = device.zCommandCommandTimeout data = {} try: for instanceId, instanceUUID in device.openstack_instanceList: # host based installation cmd = "virsh --readonly -c 'qemu:///system' dumpxml '%s'" % \ instanceUUID if device.zOpenStackRunVirshQemuInContainer: # container based installation cmd = container_cmd_wrapper( device.zOpenStackRunVirshQemuInContainer, "virsh --readonly -c 'qemu:///system' dumpxml '%s'" % \ instanceUUID) log.info("Running %s" % cmd) d = yield client.run(cmd, timeout=timeout) if d.exitCode != 0 or d.stderr: if 'Domain not found' in d.stderr: log.debug( "Domain not found while running virsh (rc=%s, stderr='%s')" % (d.exitCode, d.stderr)) elif 'docker: command not found' in d.stderr: msg = 'Check zOpenStackRunNeutronCommonInContainer value' stderr = ' '.join(list(set( d.stderr.split('\n')))).lstrip() log.error( "Error running virsh (rc=%s, stderr='%s'); %s" % (d.exitCode, stderr, msg)) else: log.error("Error running virsh (rc=%s, stderr='%s')" % (d.exitCode, d.stderr)) continue try: tree = etree.fromstring(d.output) instanceName = str(tree.xpath("/domain/name/text()")[0]) zenossInstanceId = 'server-%s' % (instanceUUID) data[instanceUUID] = { 'id': zenossInstanceId, 'serialNumber': str( tree.xpath( "/domain/sysinfo/system/entry[@name='serial']/text()" )[0]), 'biosUuid': str( tree.xpath( "/domain/sysinfo/system/entry[@name='uuid']/text()" )[0]) } except Exception: log.error("Invalid XML Received from (%s):\n%s\n\n" % (cmd, d.output)) raise LibvirtXMLError( 'Incomplete or invalid XML returned from virsh command. Consult log for more details.' ) vnics = [] for interface in tree.xpath("/domain/devices/interface"): target = interface.find("target/[@dev]") mac = interface.find("mac/[@address]") if target is None or mac is None: # unrecognized interface type continue # compute the resourceId in the same way that ceilometer's # net pollster does. vnicName = str(target.get('dev')) zenossVnicId = 'vnic-%s-%s' % (instanceUUID, vnicName) ceilometerResourceId = '%s-%s-%s' % ( instanceName, instanceUUID, vnicName) vnics.append({ 'id': zenossVnicId, 'name': vnicName, 'macaddress': str(mac.get('address')), 'resourceId': ceilometerResourceId }) data[instanceUUID]['vnics'] = vnics finally: client.disconnect() returnValue(data)