chore(xo-server-sdn-controller): various cleaning in the code (#4699)
This commit is contained in:
parent
549ce6fbf9
commit
f9a10d8932
@ -260,7 +260,7 @@ async function createTunnel(host, network) {
|
||||
}
|
||||
|
||||
function getHostTunnelForNetwork(host, networkRef) {
|
||||
const pif = find(host.$PIFs, { network: networkRef })
|
||||
const pif = host.$PIFs.find(_ => _.network === networkRef)
|
||||
if (pif === undefined) {
|
||||
return
|
||||
}
|
||||
@ -368,7 +368,7 @@ class SDNController extends EventEmitter {
|
||||
await Promise.all(
|
||||
map(this._privateNetworks, async privateNetworks => {
|
||||
await Promise.all(
|
||||
map(privateNetworks.getPools(), async pool => {
|
||||
privateNetworks.getPools().map(async pool => {
|
||||
if (!updatedPools.includes(pool)) {
|
||||
const xapi = this._xo.getXapi(pool)
|
||||
await this._installCaCertificateIfNeeded(xapi)
|
||||
@ -621,7 +621,7 @@ class SDNController extends EventEmitter {
|
||||
|
||||
await this._setPoolControllerIfNeeded(pool)
|
||||
|
||||
const pifId = find(pifIds, id => {
|
||||
const pifId = pifIds.find(id => {
|
||||
const pif = this._xo.getXapiObject(this._xo.getObject(id, 'PIF'))
|
||||
return pif.$pool.$ref === pool.$ref
|
||||
})
|
||||
@ -704,7 +704,7 @@ class SDNController extends EventEmitter {
|
||||
pool: object.$pool.name_label,
|
||||
})
|
||||
|
||||
if (find(this._newHosts, { $ref: object.$ref }) === undefined) {
|
||||
if (!this._newHosts.some(_ => _.$ref === object.$ref)) {
|
||||
this._newHosts.push(object)
|
||||
}
|
||||
this._createOvsdbClient(object)
|
||||
@ -831,8 +831,12 @@ class SDNController extends EventEmitter {
|
||||
}
|
||||
|
||||
async _hostUpdated(host) {
|
||||
const newHost = find(this._newHosts, { $ref: host.$ref })
|
||||
if (!host.enabled || host.PIFs.length === 0 || newHost === undefined) {
|
||||
let newHost
|
||||
if (
|
||||
!host.enabled ||
|
||||
host.PIFs.length === 0 ||
|
||||
(newHost = this._newHosts.find(_ => _.$ref === host.$ref)) === undefined
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
@ -1070,9 +1074,8 @@ class SDNController extends EventEmitter {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
_createOvsdbClient(host) {
|
||||
const foundClient = this.ovsdbClients[host.$ref]
|
||||
if (foundClient !== undefined) {
|
||||
return foundClient
|
||||
if (this.ovsdbClients[host.$ref] !== undefined) {
|
||||
return
|
||||
}
|
||||
|
||||
const client = new OvsdbClient(
|
||||
@ -1082,7 +1085,6 @@ class SDNController extends EventEmitter {
|
||||
this._caCert
|
||||
)
|
||||
this.ovsdbClients[host.$ref] = client
|
||||
return client
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import createLogger from '@xen-orchestra/log'
|
||||
import { filter, find, forOwn, map, sample } from 'lodash'
|
||||
import { filter, forOwn, sample } from 'lodash'
|
||||
|
||||
// =============================================================================
|
||||
|
||||
@ -111,7 +111,7 @@ export class PrivateNetwork {
|
||||
|
||||
const hosts = filter(network.$pool.$xapi.objects.all, { $type: 'host' })
|
||||
return Promise.all(
|
||||
map(hosts, async host => {
|
||||
hosts.map(async host => {
|
||||
const hostClient = this.controller.ovsdbClients[host.$ref]
|
||||
const network = this.networks[host.$pool.uuid]
|
||||
await hostClient.resetForNetwork(network, this.uuid)
|
||||
@ -126,9 +126,9 @@ export class PrivateNetwork {
|
||||
// TODO: make it random
|
||||
const hosts = this._getHosts()
|
||||
for (const host of hosts) {
|
||||
const pif = find(host.$PIFs, {
|
||||
network: this.networks[host.$pool.uuid].$ref,
|
||||
})
|
||||
const pif = host.$PIFs.find(
|
||||
_ => _.network === this.networks[host.$pool.uuid].$ref
|
||||
)
|
||||
if (pif?.currently_attached && host.$metrics.live) {
|
||||
this.center = host
|
||||
break
|
||||
@ -145,7 +145,7 @@ export class PrivateNetwork {
|
||||
await this._reset()
|
||||
|
||||
// Recreate star topology
|
||||
await Promise.all(map(hosts, host => this.addHost(host)))
|
||||
await Promise.all(hosts.map(host => this.addHost(host)))
|
||||
|
||||
log.info('New star-center elected', {
|
||||
center: this.center.name_label,
|
||||
@ -167,7 +167,7 @@ export class PrivateNetwork {
|
||||
|
||||
_reset() {
|
||||
return Promise.all(
|
||||
map(this._getHosts(), async host => {
|
||||
this._getHosts().map(async host => {
|
||||
// Clean old ports and interfaces
|
||||
const hostClient = this.controller.ovsdbClients[host.$ref]
|
||||
if (hostClient === undefined) {
|
||||
|
@ -487,7 +487,7 @@ export class OvsdbClient {
|
||||
let resultRequestId
|
||||
do {
|
||||
try {
|
||||
result = await fromEvent(stream, 'data', {})
|
||||
result = await fromEvent(stream, 'data')
|
||||
} catch (error) {
|
||||
log.error('Error while waiting for stream data', {
|
||||
error,
|
||||
@ -518,7 +518,7 @@ export class OvsdbClient {
|
||||
const socket = connect(options)
|
||||
|
||||
try {
|
||||
await fromEvent(socket, 'secureConnect', {})
|
||||
await fromEvent(socket, 'secureConnect')
|
||||
} catch (error) {
|
||||
log.error('TLS connection failed', {
|
||||
error,
|
||||
|
@ -1802,8 +1802,7 @@ const messages = {
|
||||
newNetworkEncrypted: 'Encrypted',
|
||||
encryptionWarning:
|
||||
'A pool can have 1 encrypted GRE network and 1 encrypted VxLAN network max',
|
||||
newNetworkSdnControllerTip:
|
||||
'Private networks work on up-to-date XCP-ng hosts, for other scenarios please see the requirements',
|
||||
newNetworkSdnControllerTip: 'Please see the requirements',
|
||||
deleteNetwork: 'Delete network',
|
||||
deleteNetworkConfirm: 'Are you sure you want to delete this network?',
|
||||
networkInUse: 'This network is currently in use',
|
||||
|
Loading…
Reference in New Issue
Block a user