def addBridge(self, brName, dev): bash("ifdown %s" % dev.name) if not os.path.exists(self.brCfgFile): shutil.copy(self.devCfgFile, self.brCfgFile) #config device file at first: disable nm, set onboot=yes if not cfo = configFileOps(self.devCfgFile, self) cfo.addEntry("NM_CONTROLLED", "no") cfo.addEntry("ONBOOT", "yes") if self.syscfg.env.bridgeType == "openvswitch": if cfo.getEntry("IPADDR"): cfo.rmEntry("IPADDR", cfo.getEntry("IPADDR")) cfo.addEntry("DEVICETYPE", "ovs") cfo.addEntry("TYPE", "OVSPort") cfo.addEntry("OVS_BRIDGE", brName) elif self.syscfg.env.bridgeType == "native": cfo.addEntry("BRIDGE", brName) else: raise CloudInternalException("Unknown network.bridge.type %s" % self.syscfg.env.bridgeType) cfo.save() cfo = configFileOps(self.brCfgFile, self) cfo.addEntry("NM_CONTROLLED", "no") cfo.addEntry("ONBOOT", "yes") cfo.addEntry("DEVICE", brName) if self.syscfg.env.bridgeType == "openvswitch": if cfo.getEntry("HWADDR"): cfo.rmEntry("HWADDR", cfo.getEntry("HWADDR")) if cfo.getEntry("UUID"): cfo.rmEntry("UUID", cfo.getEntry("UUID")) cfo.addEntry("STP", "yes") cfo.addEntry("DEVICETYPE", "ovs") cfo.addEntry("TYPE", "OVSBridge") elif self.syscfg.env.bridgeType == "native": cfo.addEntry("TYPE", "Bridge") else: raise CloudInternalException("Unknown network.bridge.type %s" % self.syscfg.env.bridgeType) cfo.save()
def writeToCfgFile(self, brName, dev): self.devCfgFile = "/etc/sysconfig/network-scripts/ifcfg-%s" % dev.name self.brCfgFile = "/etc/sysconfig/network-scripts/ifcfg-%s" % brName isDevExist = os.path.exists(self.devCfgFile) isBrExist = os.path.exists(self.brCfgFile) if isDevExist and isBrExist: logging.debug("%s:%s already configured" % (brName, dev.name)) return True elif isDevExist and not isBrExist: #reconfig bridge self.addBridge(brName, dev) elif not isDevExist and isBrExist: #reconfig dev raise CloudInternalException( "Missing device configuration, Need to add your network configuration into /etc/sysconfig/network-scripts at first" ) else: raise CloudInternalException( "Missing bridge/device network configuration, need to add your network configuration into /etc/sysconfig/network-scripts at first" )
def config(self): try: if super(networkConfigUbuntu, self).isPreConfiged(): return True self.netMgrRunning = self.syscfg.svo.isServiceRunning("network-manager") super(networkConfigUbuntu, self).cfgNetwork() if self.netMgrRunning: self.syscfg.svo.stopService("network-manager") self.syscfg.svo.disableService("network-manager") if not bash("ifup %s"%self.brName).isSuccess(): raise CloudInternalException("Can't start network:%s"%self.brName, bash.getErrMsg(self)) self.syscfg.env.nics.append(self.brName) self.syscfg.env.nics.append(self.brName) self.syscfg.env.nics.append(self.brName) return True except: raise
def checkHostName(): ret = bash("hostname --fqdn") if not ret.isSuccess(): raise CloudInternalException("Cannot get hostname, 'hostname --fqdn failed'")
cfo = configFileOps("/usr/share/cloudstack-management/conf/db.properties", self) dbHost = cfo.getEntry("db.cloud.host") dbPort = cfo.getEntry("db.cloud.port") dbUser = cfo.getEntry("db.cloud.username") dbPass = cfo.getEntry("db.cloud.password") if dbPass.strip() == "": dbPass = None dbName = cfo.getEntry("db.cloud.name") db = Database(dbUser, dbPass, dbHost, dbPort, dbName) try: db.testConnection() except CloudRuntimeException, e: raise e except: raise CloudInternalException("Failed to connect to Mysql server") try: statement = """ UPDATE configuration SET value='%s' WHERE name='%s'""" db.execute(statement % ('true', 'use.local.storage')) db.execute(statement % ('20', 'max.template.iso.size')) statement = """ UPDATE vm_template SET url='%s',checksum='%s' WHERE id='%s' """ db.execute(statement % ('https://rightscale-cloudstack.s3.amazonaws.com/kvm/RightImage_CentOS_5.4_x64_v5.6.28.qcow2.bz2', '90fcd2fa4d3177e31ff296cecb9933b7', '4')) statement = """UPDATE disk_offering set use_local_storage=1""" db.execute(statement) except: raise e
cfo = configFileOps("/usr/share/cloudstack-management/conf/db.properties", self) dbHost = cfo.getEntry("db.cloud.host") dbPort = cfo.getEntry("db.cloud.port") dbUser = cfo.getEntry("db.cloud.username") dbPass = cfo.getEntry("db.cloud.password") if dbPass.strip() == "": dbPass = None dbName = cfo.getEntry("db.cloud.name") db = Database(dbUser, dbPass, dbHost, dbPort, dbName) try: db.testConnection() except CloudRuntimeException, e: raise e except: raise CloudInternalException("Failed to connect to Mysql server") try: statement = """ UPDATE configuration SET value='%s' WHERE name='%s'""" db.execute(statement%('true','use.local.storage')) db.execute(statement%('20','max.template.iso.size')) statement = """ UPDATE vm_template SET url='%s',checksum='%s' WHERE id='%s' """ db.execute(statement%('https://rightscale-cloudstack.s3.amazonaws.com/kvm/RightImage_CentOS_5.4_x64_v5.6.28.qcow2.bz2', '90fcd2fa4d3177e31ff296cecb9933b7', '4')) statement="""UPDATE disk_offering set use_local_storage=1""" db.execute(statement) except: raise e