def _killMachine(self): self._printStep('Killing machine') if self.vmId: self.cloud.vmKill(self.vmId) else: Util.printWarning('Undefined VM ID, when trying to kill machine.')
def _getConfSubnets(): subnetTemplate = """ subnet %(subnet)s netmask %(netmask)s { option routers %(routers)s; } """ subnet = '' # All net types are defined together with NATing. Assuming NATing for # Local net type. Need to create a shared network. if Util.isTrueConfVal(self.nat) and _isAllDhcpGroupsDefined(dhcpGroups): subnet = """ shared-network StratusLab-LAN { """ for _type in self.NET_TYPES_DHCP: subnet += subnetTemplate % { 'subnet' : getattr(self, self._assembleDhcpAttributeName('%sSubnet' % _type)), 'netmask' : getattr(self, self._assembleDhcpAttributeName('%sNetmask' % _type)), 'routers' : getattr(self, self._assembleDhcpAttributeName('%sRouters' % _type))} subnet += "}\n" elif Util.isTrueConfVal(self.nat) and dhcpGroups['OneLocalNetwork']: subnet = """ shared-network StratusLab-LAN { """ # main interface subnet += """ subnet %(subnet)s netmask %(netmask)s { } """ % {'subnet' : self.dhcpSubnet, 'netmask' : self.dhcpNetmask} # virtual interface natGateway = getattr(self, 'natGateway', '') if not natGateway: natGateway = Util.gatewayIpFromNetAddress(self.natNetwork) subnet += subnetTemplate % {'subnet' : self.natNetwork, 'netmask' : self.natNetmask, 'routers' : natGateway} subnet += "}\n" elif dhcpGroups['OnePublicNetwork']: # main interface subnet += """ subnet %(subnet)s netmask %(netmask)s { } """ % {'subnet' : self.dhcpSubnet, 'netmask' : self.dhcpNetmask} elif dhcpGroups['OneLocalNetwork']: # virtual interface subnet = subnetTemplate % { 'subnet' : self.dhcpOneLocalNetworkSubnet, 'netmask' : self.dhcpOneLocalNetworkNetmask, 'routers' : self.dhcpOneLocalNetworkRouters} else: Util.printWarning('Invalid parameters combination to configure DHCP.') return subnet
def _configureDbUser(self, username, password): mysqlCommand = "/usr/bin/mysql -uroot -p%s" % self.oneDbRootPassword userCreate = "CREATE USER '%s'@'localhost' IDENTIFIED BY '%s'" % (username, password) userGrant = "GRANT CREATE, DROP, SELECT, INSERT, DELETE, UPDATE, INDEX ON opennebula.* TO '%s'@'localhost'" % username rc, output = self._execute("%s -e \"%s\"" % (mysqlCommand, userCreate), withOutput=True, shell=True) if rc != 0: Util.printWarning("Couldn't create user '%s'. Already exists?\n%s" % (username, output)) rc, output = self._execute("%s -e \"%s\"" % (mysqlCommand, userGrant), withOutput=True, shell=True) if rc != 0: Util.printError("Error granting permission for user '%s'.\n%s" % (username, output))
def addElementToManifest(root, elementName, value): elems = root.findall('.//{%s}%s' % (ManifestInfo.NS_SLTERMS, elementName)) if elems: # Check if already present. If yes, do nothing. for elem in elems: if elem.text and elem.text == value: Util.printWarning( "Element '%s' with value '%s' already defined in the manifest. Skipping addition of the element." % \ (elementName, elem.text)) return elem = etree.Element('{%s}%s' % (ManifestInfo.NS_SLTERMS, elementName)) elem.text = value descriptionElement = root.find('.//{%s}Description' % ManifestInfo.NS_RDF) descriptionElement.append(elem)
def _persistRemoteBridgeConfig(self, iface, bridge): netScriptsDir = '/etc/sysconfig/network-scripts/' ifaceFile = '%s/ifcfg-%s' % (netScriptsDir, iface) bridgeFile = '%s/ifcfg-%s' % (netScriptsDir, bridge) if self._nodeShell('[ -f %s ]' % bridgeFile, shell=True) == 0: Util.printWarning(('Bridge configuration already present (%s:%s).' % (self.nodeAddr, bridgeFile)) + \ ' Please update it manually if required.') return cmd = 'cat %s' % ifaceFile rc, output = self._nodeShell(cmd, withOutput=True, shell=True) if rc != 0: Util.printWarning('Failed to get content of %s:%s:\n%s' % (self.nodeAddr, ifaceFile, output)) return ifaceConfOrig = output try: bridgeConf, ifaceConf = self._buildBridgeAndIfaceConfig(ifaceConfOrig, iface, bridge) except Exceptions.ConfigurationException, ex: Util.printWarning('Failed to build config for %s and %s.\n%s' % (iface, bridge, str(ex))) return
def checkOptions(self): if len(self.args) != 1: self.parser.error('Please specify an image') self.image = self.args[0] if not os.path.isfile(self.image): self.parser.error('Image does not exist: ' + self.image) if not self.options.locations: self.options.__dict__.update({'locations': []}) Util.printWarning("Image physical location (URL) was not provided. " "You'll have to set it manually in the resulting manifest.") else: self.options.__dict__.update({'locations': [self.options.__dict__['locations']]}) if not self.options.compression: # Guess compression from file name if not given explicitly. compression = Compressor.getCompressionFormat(self.image) self.options.__dict__.update({'compression': compression}) if self.options.disksbus not in VmManager.DISKS_BUS_AVAILABLE: self.parser.error("Unknown disks bus type %s. Available types: %s" % (self.options.disksbus, ', '.join(VmManager.DISKS_BUS_AVAILABLE)))
def _compressFile(self, filename, fmt): if fmt.lower() == 'none': return filename if Compressor.getCompressionFormat(filename) != '': Util.printWarning('skipping compression; file appears to already be compressed') return filename compressionCmd = Compressor._getCompressionCommandByFormat(fmt) compressedFilename = '%s.%s' % (filename, fmt) if os.path.isfile(compressedFilename): Util.printWarning('Compressed file %s already exists, skipping' % compressedFilename) return compressedFilename if not os.path.exists(filename): Util.printError('Missing file: ' + filename, exit=True) ret = self._execute([compressionCmd, filename]) if ret != 0: Util.printError('Error compressing file: %s' % compressedFilename, exit=True) return compressedFilename
def printWarning(self, msg): Util.printWarning(msg)
def _configureRootDbUser(self, password): rc, output = self._execute(["/usr/bin/mysqladmin", "-uroot", "password", "%s" % password], withOutput=True) if rc != 0: Util.printWarning("Couldn't set root password. Already set?\n%s" % output)
def _addCompressionFormatToManifest(self): if self.compressionFormat.lower() != 'none': ManifestInfo.addElementToManifestFile(self.manifestFile, 'compression', self.compressionFormat) else: Util.printWarning("'none' specified for compression; manifest compression element NOT updated")