Skip to content

Commit

Permalink
CA-400243: Convert Ref to UUID in data source output (#85)
Browse files Browse the repository at this point in the history
Signed-off-by: xueqingz <[email protected]>
  • Loading branch information
xueqingz authored Jan 15, 2025
1 parent 9661695 commit 39f7934
Show file tree
Hide file tree
Showing 19 changed files with 938 additions and 228 deletions.
8 changes: 4 additions & 4 deletions docs/data-sources/network.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ output "network_output" {
Read-Only:

- `allowed_operations` (List of String) The list of the operations allowed in this state.
- `assigned_ips` (Map of String) The IP addresses assigned to VIFs on networks that have active [xapi-managed](https://github.com/xapi-project/xen-api) DHCP.
- `blobs` (Map of String) The binary blobs associated with this SR.
- `assigned_ips` (Map of String) The IP addresses assigned to VIFs(UUID) on networks that have active [xapi-managed](https://github.com/xapi-project/xen-api) DHCP.
- `blobs` (Map of String) The binary blobs(UUID) associated with this SR.
- `bridge` (String) The name of the bridge corresponding to this network on the local host.
- `current_operations` (Map of String) The links each of the running tasks using this object (by reference) to a current_operation enum which describes the nature of the task.
- `default_locking_mode` (String) The network will use this value to determine the behavior of all VIFs where `locking_mode = default`.
Expand All @@ -50,8 +50,8 @@ Read-Only:
- `name_description` (String) The human-readable description of the network.
- `name_label` (String) The name of the network.
- `other_config` (Map of String) The additional configuration.
- `pifs` (List of String) The list of connected PIFs.
- `pifs` (List of String) The list of connected PIFs(UUID).
- `purpose` (List of String) Set of purposes for which the server will use this network.
- `tags` (List of String) The user-specified tags for categorization purposes.
- `uuid` (String) The UUID of the network.
- `vifs` (List of String) The list of connected VIFs.
- `vifs` (List of String) The list of connected VIFs(UUID).
18 changes: 9 additions & 9 deletions docs/data-sources/pif.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ output "pif_data_out" {

Read-Only:

- `bond_master_of` (List of String) Indicates this PIF represents the results of a bond.
- `bond_slave_of` (String) Indicates which bond this interface is part of.
- `bond_master_of` (List of String) Indicates this PIF represents the results of a bond(UUID).
- `bond_slave_of` (String) Indicates which bond(UUID) this interface is part of.
- `capabilities` (List of String) Additional capabilities on the interface.
- `currently_attached` (Boolean) True if this interface is online.
- `device` (String) The machine-readable name of the physical interface (PIF). (For example, `"eth0"`)
Expand All @@ -63,15 +63,15 @@ Read-Only:
- `netmask` (String) IP netmask.
- `network` (String) The UUID of the virtual network to which this PIF is connected.
- `other_config` (Map of String) Additional configuration.
- `pci` (String) Link to underlying PCI device.
- `pci` (String) Link to underlying PCI(UUID) device.
- `physical` (Boolean) True if this represents a physical network interface.
- `primary_address_type` (String) Which protocol should define the primary address of this interface.
- `properties` (Map of String) Additional configuration properties for the interface.
- `sriov_logical_pif_of` (List of String) Indicates which network_sriov this interface is the logical PIF of.
- `sriov_physical_pif_of` (List of String) Indicates which network_sriov this interface is the physical PIF of.
- `tunnel_access_pif_of` (List of String) Indicates to which tunnel this PIF gives access.
- `tunnel_transport_pif_of` (List of String) Indicates to which tunnel this PIF provides transport.
- `sriov_logical_pif_of` (List of String) Indicates which network_sriov(UUID) this interface is the logical PIF of.
- `sriov_physical_pif_of` (List of String) Indicates which network_sriov(UUID) this interface is the physical PIF of.
- `tunnel_access_pif_of` (List of String) Indicates to which tunnel(UUID) this PIF gives access.
- `tunnel_transport_pif_of` (List of String) Indicates to which tunnel(UUID) this PIF provides transport.
- `uuid` (String) The UUID of the storage repository.
- `vlan` (Number) VLAN tag for all traffic passing through this interface.
- `vlan_master_of` (String) Indicates which VLAN this interface receives untagged traffic from.
- `vlan_slave_of` (List of String) Indicates which VLANs this interface transmits tagged traffic to.
- `vlan_master_of` (String) Indicates which VLAN(UUID) this interface receives untagged traffic from.
- `vlan_slave_of` (List of String) Indicates which VLANs(UUID) this interface transmits tagged traffic to.
8 changes: 4 additions & 4 deletions docs/data-sources/sr.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@ output "local_storage_output" {
Read-Only:

- `allowed_operations` (List of String) The list of the operations allowed in this state.
- `blobs` (Map of String) The binary blobs associated with this SR.
- `blobs` (Map of String) The binary blobs(UUID) associated with this SR.
- `clustered` (Boolean) True if the SR is using aggregated local storage.
- `content_type` (String) The type of the SR's content, if required (for example, "ISOs").
- `current_operations` (Map of String) The links each of the running tasks using this object (by reference) to a current_operation enum which describes the nature of the task.
- `introduced_by` (String) The disaster recovery task which introduced this SR.
- `introduced_by` (String) The UUID of disaster recovery task which introduced this SR.
- `is_tools_sr` (Boolean) True if this is the SR that contains the Tools ISO VDIs.
- `local_cache_enabled` (Boolean) True if this SR is assigned to be the local cache for its host.
- `name_description` (String) The human-readable description of the storage repository.
- `name_label` (String) The name of the storage repository.
- `other_config` (Map of String) The additional configuration.
- `pbds` (List of String) Describes how particular hosts can see this storage repository.
- `pbds` (List of String) The UUID list of PBDs. Describes how particular hosts can see this storage repository.
- `physical_size` (Number) The total physical size of the storage repository (in bytes).
- `physical_utilisation` (Number) The physical space currently utilized on this storage repository (in bytes).
- `shared` (Boolean) True if this SR is (capable of being) shared between multiple hosts.
- `sm_config` (Map of String) The SM dependent data.
- `tags` (List of String) The user-specified tags for categorization purposes.
- `type` (String) The type of the storage repository.
- `uuid` (String) The UUID of the storage repository.
- `vdis` (List of String) The all virtual disks known to this storage repository.
- `vdis` (List of String) The UUID list of all virtual disks known to this storage repository.
- `virtual_allocation` (Number) The sum of virtual_sizes of all VDIs in this storage repository (in bytes).
45 changes: 23 additions & 22 deletions docs/data-sources/vm.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,21 @@ Read-Only:
- `actions_after_softreboot` (String) Action to take after soft reboot.
- `affinity` (String) A host which the VM has some affinity for (or NULL). This is used as a hint to the start call when it decides where to run the VM. Resource constraints may cause the VM to be started elsewhere.
- `allowed_operations` (List of String) The list of the operations allowed in this state.
- `appliance` (String) The appliance to which this VM belongs.
- `attached_pcis` (List of String) Currently passed-through PCI devices.
- `appliance` (String) The appliance(UUID) to which this VM belongs.
- `attached_pcis` (List of String) The UUID list of currently passed-through PCI devices.
- `bios_strings` (Map of String) BIOS strings.
- `blobs` (Map of String) Binary blobs associated with this VM.
- `blobs` (Map of String) Binary blobs(UUID) associated with this VM.
- `blocked_operations` (Map of String) List of operations which have been explicitly blocked and an error code.
- `children` (List of String) List pointing to all the children of this VM.
- `consoles` (List of String) Virtual console devices.
- `crash_dumps` (List of String) Crash dumps associated with this VM.
- `children` (List of String) UUID list pointing to all the children of this VM.
- `consoles` (List of String) The UUID list of virtual console devices.
- `crash_dumps` (List of String) The UUID list of crash dumps associated with this VM.
- `current_operations` (Map of String) The links each of the running tasks using this object (by reference) to a current_operation enum which describes the nature of the task.
- `domain_type` (String) The type of domain that will be created when the VM is started.
- `domarch` (String) Domain architecture (if available, null string otherwise).
- `domid` (Number) Domain ID (if available, -1 otherwise).
- `generation_id` (String) Generation ID of the VM.
- `guest_metrics` (String) Metrics associated with the running guest.
- `groups` (List of String) The UUID list of VM groups associated with the VM.
- `guest_metrics` (String) Metrics(UUID) associated with the running guest.
- `ha_always_run` (Boolean) If true then the system will attempt to keep the VM running as much as possible.
- `ha_restart_priority` (String) Has possible values: 'best-effort' meaning 'try to restart this VM if possible but don't consider the pool to be overcommitted if this is not possible'; 'restart' meaning 'this VM should be restarted'; '' meaning 'do not try to restart this VM'.
- `hardware_platform_version` (Number) The host virtual hardware platform version the VM can run on.
Expand All @@ -78,20 +79,20 @@ Read-Only:
- `memory_static_max` (Number) Statically-set (absolute) maximum (bytes). The value of this field at VM start time acts as a hard limit of the amount of memory a guest can use. New values only take effect on reboot.
- `memory_static_min` (Number) Statically-set (absolute) mininum (bytes). The value of this field indicates the least amount of memory this VM can boot with without crashing.
- `memory_target` (Number) Dynamically-set memory target (bytes). The value of this field indicates the current target for memory available to this VM.
- `metrics` (String) Metrics associated with this VM.
- `metrics` (String) Metrics(UUID) associated with this VM.
- `name_description` (String) The description of the virtual machine.
- `name_label` (String) The name of the virtual machine.
- `nvram` (Map of String) Initial value for guest NVRAM (containing UEFI variables, and so on). Cannot be changed while the VM is running.
- `order` (Number) The point in the startup or shutdown sequence at which this VM will be started.
- `other_config` (Map of String) Additional configuration.
- `parent` (String) Ref pointing to the parent of this VM.
- `parent` (String) UUID pointing to the parent of this VM.
- `pci_bus` (String) PCI bus path for pass-through devices.
- `pending_guidances` (List of String) The set of pending mandatory guidances after applying updates, which must be applied, as otherwise there may be, for example, VM failures.
- `pending_guidances_full` (List of String) The set of pending full guidances after applying updates, which a user should follow to make some updates, for example, specific hardware drivers or CPU features, fully effective, but the 'average user' doesn't need to.
- `pending_guidances_recommended` (List of String) The set of pending recommended guidances after applying updates, which most users should follow to make the updates effective, but if not followed, will not cause a failure.
- `platform` (Map of String) Platform-specific configuration.
- `power_state` (String) The current power state of the virtual machine.
- `protection_policy` (String) Ref pointing to a protection policy for this VM.
- `protection_policy` (String) UUID pointing to a protection policy for this VM.
- `pv_args` (String) Kernel command-line arguments
- `pv_bootloader` (String) Name of or path to bootloader.
- `pv_bootloader_args` (String) Miscellaneous arguments for the bootloader.
Expand All @@ -101,29 +102,29 @@ Read-Only:
- `recommendations` (String) An XML specification of recommended values and ranges for properties of this VM.
- `reference_label` (String) Textual reference to the template used to create a VM. This can be used by clients in need of an immutable reference to the template since the latter's uuid and name_label may change, for example, after a package installation or upgrade.
- `requires_reboot` (Boolean) Indicates whether a VM requires a reboot in order to update its configuration, for example, its memory allocation.
- `resident_on` (String) The host the VM is currently resident on.
- `scheduled_to_be_resident_on` (String) The host on which the VM is due to be started/resumed/migrated. This acts as a memory reservation indicator.
- `resident_on` (String) The host(UUID) the VM is currently resident on.
- `scheduled_to_be_resident_on` (String) The host(UUID) on which the VM is due to be started/resumed/migrated. This acts as a memory reservation indicator.
- `shutdown_delay` (Number) The delay to wait before proceeding to the next order in the shutdown sequence (seconds).
- `snapshot_info` (Map of String) Human-readable information concerning this snapshot.
- `snapshot_metadata` (String) Metadata concerning this snapshot.
- `snapshot_of` (String) Ref pointing to the VM this snapshot is of.
- `snapshot_schedule` (String) Ref pointing to a snapshot schedule for this VM.
- `snapshot_of` (String) UUID pointing to the VM this snapshot is of.
- `snapshot_schedule` (String) UUID pointing to a snapshot schedule for this VM.
- `snapshot_time` (String) Date/time when this snapshot was created.
- `snapshots` (List of String) List pointing to all the VM snapshots.
- `snapshots` (List of String) UUID list pointing to all the VM snapshots.
- `start_delay` (Number) The delay to wait before proceeding to the next order in the startup sequence (seconds).
- `suspend_sr` (String) The SR on which a suspend image is stored.
- `suspend_vdi` (String) The VDI that a suspend image is stored on. Only has meaning if VM is currently suspended.
- `suspend_sr` (String) The SR(UUID) on which a suspend image is stored.
- `suspend_vdi` (String) The VDI(UUID) that a suspend image is stored on. Only has meaning if VM is currently suspended.
- `tags` (List of String) User-specified tags for categorization purposes.
- `transportable_snapshot_id` (String) Transportable ID of the snapshot VM.
- `user_version` (Number) Creators of VMs and templates may store version information here.
- `uuid` (String) The UUID of the virtual machine.
- `vbds` (List of String) Virtual block devices.
- `vbds` (List of String) The UUID list of virtual block devices.
- `vcpus_at_startup` (Number) Boot number of VCPUs.
- `vcpus_max` (Number) Max number of VCPUs.
- `vcpus_params` (Map of String) Configuration parameters for the selected VCPU policy.
- `version` (Number) The number of times this VM has been recovered.
- `vgpus` (List of String) Virtual GPUs.
- `vifs` (List of String) Virtual network interfaces.
- `vtpms` (List of String) Virtual TPMs.
- `vusbs` (List of String) Virtual USB devices.
- `vgpus` (List of String) The UUID list of virtual GPUs.
- `vifs` (List of String) The UUID list of virtual network interfaces.
- `vtpms` (List of String) The UUID list of virtual TPMs.
- `vusbs` (List of String) The UUID list of virtual USB devices.
- `xenstore_data` (Map of String) Data to be inserted into the xenstore tree (/local/domain/<domid>/vm-data) after the VM is created.
55 changes: 55 additions & 0 deletions examples/test-data-sources/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
locals {
env_vars = { for tuple in regexall("export\\s*(\\S*)\\s*=\\s*(\\S*)\\s*", file("../../.env")) : tuple[0] => tuple[1] }
}

terraform {
required_providers {
xenserver = {
source = "xenserver/xenserver"
}
}
}

provider "xenserver" {
host = local.env_vars["XENSERVER_HOST"]
username = local.env_vars["XENSERVER_USERNAME"]
password = local.env_vars["XENSERVER_PASSWORD"]
}

data "xenserver_host" "host" {}

output "host_output" {
value = data.xenserver_host.host.data_items
}

data "xenserver_network" "network" {}

output "network_output" {
value = data.xenserver_network.network.data_items
}

data "xenserver_nic" "nic" {}

output "nic_output" {
value = data.xenserver_nic.nic.data_items
}

data "xenserver_pif" "pif" {}

output "pif_data_out" {
value = data.xenserver_pif.pif.data_items
}

data "xenserver_sr" "sr" {}

output "local_storage_output" {
value = data.xenserver_sr.sr.data_items
}

data "xenserver_vm" "vm_data" {
name_label = "TestVM"
}

output "vm_data_out" {
value = data.xenserver_vm.vm_data.data_items
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,16 @@ provider "xenserver" {
password = local.env_vars["XENSERVER_PASSWORD"]
}

data "xenserver_vm" "vm_data" {
}

output "vm_data_out" {
value = data.xenserver_vm.vm_data.data_items
}

data "xenserver_pif" "pif" {
device = "eth0"
management = true
}

output "pif_data_out" {
value = data.xenserver_pif.pif.data_items
}

data "xenserver_sr" "sr" {
name_label = "Local storage"
}

output "local_storage_output" {
value = data.xenserver_sr.sr.data_items
}

resource "xenserver_sr" "local" {
name_label = "Test Local SR"
type = "dummy"
shared = false
}

output "sr_local_out" {
value = xenserver_sr.local
}

resource "xenserver_sr_smb" "smb_test" {
name_label = "SMB storage"
name_description = "A test SMB storage repository"
Expand Down Expand Up @@ -124,22 +100,10 @@ output "vdi_out2" {
value = xenserver_vdi.vdi2
}

data "xenserver_network" "network" {
name_label = "Pool-wide network associated with eth0"
}

output "network_output" {
value = data.xenserver_network.network.data_items
}

data "xenserver_nic" "nic" {
network_type = "vlan"
}

output "nic_output" {
value = data.xenserver_nic.nic.data_items
}

resource "xenserver_network_vlan" "vlan" {
name_label = "test external network"
mtu = 1600
Expand Down
12 changes: 3 additions & 9 deletions xenserver/host_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,9 @@ func updateHostRecordData(ctx context.Context, session *xenapi.Session, record x
data.NameDescription = types.StringValue(record.NameDescription)
data.Hostname = types.StringValue(record.Hostname)
data.Address = types.StringValue(record.Address)
residentVMs := []string{}
for _, vmRef := range record.ResidentVMs {
if vmRef != record.ControlDomain {
vmUUID, err := xenapi.VM.GetUUID(session, vmRef)
if err != nil {
return errors.New(err.Error())
}
residentVMs = append(residentVMs, vmUUID)
}
residentVMs, err := getVMUUIDs(session, record.ResidentVMs, record.ControlDomain)
if err != nil {
return err
}
var diags diag.Diagnostics
data.ResidentVMs, diags = types.ListValueFrom(ctx, types.StringType, residentVMs)
Expand Down
Loading

0 comments on commit 39f7934

Please sign in to comment.