Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data/ovirt_vms: Export IP configurations of VM #174

Merged
merged 1 commit into from
Sep 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions ovirt/data_source_ovirt_vms.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,62 @@ func dataSourceOvirtVMs() *schema.Resource {
Type: schema.TypeInt,
Computed: true,
},
"reported_devices": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"mac_address": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"comment": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"ips": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"address": {
Type: schema.TypeString,
Computed: true,
},
"gateway": {
Type: schema.TypeString,
Computed: true,
},
"netmask": {
Type: schema.TypeString,
Computed: true,
},
"version": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
},
},
},
},
},
Expand Down Expand Up @@ -151,6 +207,8 @@ func dataSourceOvirtVMsRead(d *schema.ResourceData, meta interface{}) error {
}

func vmsDescriptionAttributes(d *schema.ResourceData, vms []*ovirtsdk4.Vm, meta interface{}) error {
conn := meta.(*ovirtsdk4.Connection)

var s []map[string]interface{}

for _, v := range vms {
Expand All @@ -166,6 +224,20 @@ func vmsDescriptionAttributes(d *schema.ResourceData, vms []*ovirtsdk4.Vm, meta
"sockets": v.MustCpu().MustTopology().MustSockets(),
"threads": v.MustCpu().MustTopology().MustThreads(),
}

devicesResp, err := conn.SystemService().
VmsService().
VmService(v.MustId()).
ReportedDevicesService().
List().
Send()
if err != nil {
return err
}
if devices, ok := devicesResp.ReportedDevice(); ok && len(devices.Slice()) > 0 {
mapping["reported_devices"] = flattenOvirtNicReportedDevices(devices.Slice())
}

s = append(s, mapping)
}
d.SetId(resource.UniqueId())
Expand Down
5 changes: 5 additions & 0 deletions ovirt/data_source_ovirt_vms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ func TestAccOvirtVMsDataSource_searchFilter(t *testing.T) {
testAccCheckOvirtDataSourceID("data.ovirt_vms.search_filtered_vm"),
resource.TestCheckResourceAttr("data.ovirt_vms.search_filtered_vm", "vms.#", "1"),
resource.TestCheckResourceAttr("data.ovirt_vms.search_filtered_vm", "vms.0.name", "HostedEngine"),
resource.TestCheckResourceAttr("data.ovirt_vms.search_filtered_vm", "vms.0.reported_devices.#", "1"),
resource.TestCheckResourceAttr("data.ovirt_vms.search_filtered_vm", "vms.0.reported_devices.0.name", "eth0"),
resource.TestCheckResourceAttr("data.ovirt_vms.search_filtered_vm", "vms.0.reported_devices.0.ips.#", "3"),
resource.TestCheckResourceAttr("data.ovirt_vms.search_filtered_vm", "vms.0.reported_devices.0.ips.0.address", "10.1.111.64"),
resource.TestCheckResourceAttr("data.ovirt_vms.search_filtered_vm", "vms.0.reported_devices.0.ips.0.version", "v4"),
),
},
},
Expand Down
64 changes: 64 additions & 0 deletions website/docs/d/vms.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
layout: "ovirt"
page_title: "oVirt: ovirt_vms"
sidebar_current: "docs-ovirt-datasource-vms"
description: |-
Provides details about oVirt VMs
---

# Data Source: ovirt\_vms

The oVirt VMs data source allows access to details of list of VMs within oVirt.

## Example Usage

```hcl
data "ovirt_vms" "filtered_vms" {
name_regex = "^HostedEngine*"

search = {
criteria = "name = HostedEngine and status = up"
max = 2
case_sensitive = false
}
}
```

## Argument Reference

The following arguments are supported:

* `name_regex` - (Optional) The fully functional regular expression for name
* `search` - (Optional) The general search criteria representation, fitting the rules of [Searching](http://ovirt.github.io/ovirt-engine-api-model/master/#_searching)
* criteria - (Optional) The criteria for searching, using the same syntax as the oVirt query language
* max - (Optional) The maximum amount of objects returned. If not specified, the search will return all the objects.
* case_sensitive - (Optional) If the search are case sensitive, default value is `false`

> The `search.criteria` also supports asterisk for searching by name, to indicate that any string matches, including the empty string. For example, the criteria `search=name=myobj*` will return all the objects with names beginning with `myobj`, such as `myobj2`, `myobj-test`. So, you could use `name_regex` for searching by complicated regular expression, and `search.criteria` for simple case accordingly.

## Attributes Reference

`vms` is set to the wrapper of the found VMs. Each item of `vms` contains the following attributes exported:

* `id` - The ID of oVirt VM
* `name` - The name of oVirt VM
* `cluster_id` - The ID of oVirt Cluster the VM belongs to
* `status` - The current status of the VM
* `template_id` - The ID of oVirt Template the VM creates from
* `high_availability` - Defines if the HA is enabled
* `memory` - The VM's memory, in Megabytes(MB)
* `cores` - The CPU cores of the VM
* `sockets` - The CPU sockets of the VM
* `threads` - The CPU threads of the VM
* `reported_devices` - A collection of reported devices that are associated with the network interface of the VM
* `id` - The ID of the reported device
* `name` - The name of the reported device
* `mac_address` - The MAC address of the reported device
* `description` - A human-readable description in plain text about the reported device
* `comment` - Free text containing comments about the reported device
* `type` - The type of the reported device
* `ips` - A list of IP configurations of the reported device
* `address` - The text representation of the IP address
* `gateway` - The address of the default gateway
* `netmask` - The network mask
* `version` - The version of the IP protocol