Skip to content

Commit 571ad4b

Browse files
feat(@xen-orchestra/rest-api): expose get networks and get network
1 parent dba08f0 commit 571ad4b

File tree

4 files changed

+115
-0
lines changed

4 files changed

+115
-0
lines changed

Diff for: @vates/types/src/xo.mts

+14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
DOMAIN_TYPE,
66
HOST_ALLOWED_OPERATIONS,
77
HOST_POWER_STATE,
8+
NETWORK_OPERATIONS,
89
STORAGE_OPERATIONS,
910
VDI_OPERATIONS,
1011
VDI_TYPE,
@@ -211,8 +212,21 @@ export type XoHostPatch = BaseXapiXo & {
211212
}
212213

213214
export type XoNetwork = BaseXapiXo & {
215+
automatic: boolean
216+
bridge: string
217+
current_operations?: Record<string, NETWORK_OPERATIONS>
218+
defaultIsLocked: boolean
214219
id: Branded<'network'>
220+
insecureNbd: boolean
221+
MTU: number
222+
name_description: string
223+
name_label: string
224+
nbd: boolean
225+
other_config: Record<string, string>
226+
PIFs: XoPif['id'][]
227+
tags: string[]
215228
type: 'network'
229+
VIFs: XoVif['id'][]
216230
}
217231

218232
export type XoPbd = BaseXapiXo & {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { Example, Get, Path, Query, Response, Request, Route, Security, Tags } from 'tsoa'
2+
import { inject } from 'inversify'
3+
import { provide } from 'inversify-binding-decorators'
4+
import { Request as ExRequest } from 'express'
5+
import type { XoNetwork } from '@vates/types'
6+
import { RestApi } from '../../rest-api/rest-api.mjs'
7+
import { notFoundResp, unauthorizedResp, Unbrand } from '../common/response.common.mjs'
8+
import { WithHref } from '../../helpers/helper.type.mjs'
9+
import { XapiXoController } from '../../abstract-classes/xapi-xo-controller.mjs'
10+
import { network, networkIds, partialNetworks } from '../oa-examples/network.oa-example.mjs'
11+
12+
@Route('networks')
13+
@Response(unauthorizedResp.status, unauthorizedResp.description)
14+
@Tags('networks')
15+
@provide(NetworkController)
16+
export class NetworkController extends XapiXoController<XoNetwork> {
17+
constructor(@inject(RestApi) restApi: RestApi) {
18+
super('network', restApi)
19+
}
20+
21+
/**
22+
* @example fields "name_label,id"
23+
* @example filter "nbd?"
24+
* @example limit 42
25+
*/
26+
@Example(networkIds)
27+
@Example(partialNetworks)
28+
@Get('')
29+
getNewtorks(
30+
@Request() req: ExRequest,
31+
@Query() fields?: string,
32+
@Query() filter?: string,
33+
@Query() limit?: number
34+
): string[] | WithHref<Partial<Unbrand<XoNetwork>>>[] {
35+
return this.sendObjects(Object.values(this.getObjects({ filter, limit })), req)
36+
}
37+
38+
/**
39+
* @example id "9fe12ca3-d75d-cfb0-492e-cfd2bc6c568f"
40+
*/
41+
@Example(network)
42+
@Get('{id}')
43+
@Response(notFoundResp.status, notFoundResp.description)
44+
getNewtork(@Path() id: string): Unbrand<XoNetwork> {
45+
return this.getObject(id as XoNetwork['id'])
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
export const networkIds = [
2+
'/rest/v0/networks/9fe12ca3-d75d-cfb0-492e-cfd2bc6c568f',
3+
'/rest/v0/networks/6b6ca0f5-6611-0636-4b0a-1fb1c8e96414',
4+
]
5+
6+
export const partialNetworks = [
7+
{
8+
name_label: 'Host internal management network',
9+
id: '9fe12ca3-d75d-cfb0-492e-cfd2bc6c568f',
10+
href: '/rest/v0/networks/9fe12ca3-d75d-cfb0-492e-cfd2bc6c568f',
11+
},
12+
{
13+
name_label: 'Lab v2 (VLAN 11)',
14+
id: '6b6ca0f5-6611-0636-4b0a-1fb1c8e96414',
15+
href: '/rest/v0/networks/6b6ca0f5-6611-0636-4b0a-1fb1c8e96414',
16+
},
17+
]
18+
19+
export const network = {
20+
automatic: false,
21+
bridge: 'xenapi',
22+
current_operations: {},
23+
defaultIsLocked: false,
24+
MTU: 1500,
25+
name_description:
26+
'Network on which guests will be assigned a private link-local IP address which can be used to talk XenAPI',
27+
name_label: 'Host internal management network',
28+
other_config: {
29+
is_guest_installer_network: 'true',
30+
is_host_internal_management_network: 'true',
31+
ip_begin: '169.254.0.1',
32+
ip_end: '169.254.255.254',
33+
netmask: '255.255.0.0',
34+
},
35+
tags: [],
36+
PIFs: [],
37+
VIFs: [
38+
'2d039fc8-e522-75db-34c9-536b9553bd5a',
39+
'38623621-d30e-0307-dcef-eb7ed6c69f0c',
40+
'cc4b090f-5ff1-254b-558f-f7ac237e6fc5',
41+
'a9f3d042-a2e1-102f-74fc-ff1df41c6eb3',
42+
],
43+
nbd: false,
44+
insecureNbd: false,
45+
id: '9fe12ca3-d75d-cfb0-492e-cfd2bc6c568f',
46+
type: 'network',
47+
uuid: '9fe12ca3-d75d-cfb0-492e-cfd2bc6c568f',
48+
$pool: 'b7569d99-30f8-178a-7d94-801de3e29b5b',
49+
$poolId: 'b7569d99-30f8-178a-7d94-801de3e29b5b',
50+
_xapiRef: 'OpaqueRef:eb906e77-2221-5399-4a26-60f0ad069b61',
51+
messages_href: '/rest/v0/networks/9fe12ca3-d75d-cfb0-492e-cfd2bc6c568f/messages',
52+
alarms_href: '/rest/v0/networks/9fe12ca3-d75d-cfb0-492e-cfd2bc6c568f/alarms',
53+
}

Diff for: packages/xo-server/src/xo-mixins/rest-api.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ export default class RestApi {
607607
// add migrated collections to maintain their discoverability
608608
const swaggerEndpoints = {
609609
docs: {},
610+
networks: {},
610611
vifs: {},
611612
vms: {
612613
actions: {

0 commit comments

Comments
 (0)