Support tags on Xen objects.

This commit is contained in:
Olivier Lambert 2015-09-11 19:30:11 +02:00 committed by Julien Fontanet
parent fd97541417
commit 37250a6f48
4 changed files with 61 additions and 1 deletions

View File

@ -11,16 +11,17 @@ export * as group from './group'
export * as host from './host'
export * as job from './job'
export * as message from './message'
export * as remote from './remote'
export * as pbd from './pbd'
export * as pif from './pif'
export * as pool from './pool'
export * as remote from './remote'
export * as role from './role'
export * as schedule from './schedule'
export * as scheduler from './scheduler'
export * as server from './server'
export * as session from './session'
export * as sr from './sr'
export * as tag from './tag'
export * as task from './task'
export * as test from './test'
export * as token from './token'

31
src/api/tag.js Normal file
View File

@ -0,0 +1,31 @@
export async function add ({tag, id}) {
await this.getXAPI(id).addTag(id, tag)
}
add.description = 'add a new tag to an object'
add.resolve = {
object: ['id', null, 'administrate']
}
add.params = {
tag: { type: 'string' },
id: { type: 'string' }
}
// -------------------------------------------------------------------
export async function remove ({tag, id}) {
await this.getXAPI(id).removeTag(id, tag)
}
remove.description = 'remove an existing tag from an object'
remove.resolve = {
object: ['id', null, 'administrate']
}
remove.params = {
tag: { type: 'string' },
id: { type: 'string' }
}

View File

@ -55,6 +55,7 @@ export function pool (obj) {
default_SR: link(obj, 'default_SR'),
HA_enabled: Boolean(obj.ha_enabled),
master: link(obj, 'master'),
tags: obj.tags,
name_description: obj.name_description,
name_label: obj.name_label || obj.$master.name_label
@ -111,6 +112,7 @@ export function host (obj) {
patches: link(obj, 'patches'),
powerOnMode: obj.power_on_mode,
power_state: isRunning ? 'Running' : 'Halted',
tags: obj.tags,
version: obj.software_version.product_version,
// TODO: dedupe.
@ -225,6 +227,7 @@ export function vm (obj) {
PV_drivers_up_to_date: Boolean(guestMetrics && guestMetrics.PV_drivers_up_to_date),
snapshot_time: toTimestamp(obj.snapshot_time),
snapshots: link(obj, 'snapshots'),
tags: obj.tags,
VIFs: link(obj, 'VIFs'),
$container: (
@ -290,6 +293,7 @@ export function sr (obj) {
physical_usage: +obj.physical_utilisation,
size: +obj.physical_size,
SR_type: obj.type,
tags: obj.tags,
usage: +obj.virtual_allocation,
VDIs: link(obj, 'VDIs'),
@ -357,6 +361,7 @@ export function vdi (obj) {
size: +obj.virtual_size,
snapshots: link(obj, 'snapshots'),
snapshot_time: toTimestamp(obj.snapshot_time),
tags: obj.tags,
usage: +obj.physical_utilisation,
$snapshot_of: link(obj, 'snapshot_of'),
@ -405,6 +410,7 @@ export function network (obj) {
MTU: +obj.MTU,
name_description: obj.name_description,
name_label: obj.name_label,
tags: obj.tags,
PIFs: link(obj, 'PIFs'),
VIFs: link(obj, 'VIFs')
}

View File

@ -242,6 +242,28 @@ export default class Xapi extends XapiBase {
// =================================================================
async addTag (id, tag) {
const {
$ref: ref,
$type: type
} = this.getObject(id)
const namespace = getNamespaceForType(type)
await this.call(`${namespace}.add_tags`, ref, tag)
}
async removeTag (id, tag) {
const {
$ref: ref,
$type: type
} = this.getObject(id)
const namespace = getNamespaceForType(type)
await this.call(`${namespace}.remove_tags`, ref, tag)
}
// =================================================================
// FIXME: should be static
@debounce(24 * 60 * 60 * 1000)
async _getXenUpdates () {