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