Skip to content

Commit

Permalink
B #389: manage cluster membership from cluster resource
Browse files Browse the repository at this point in the history
  • Loading branch information
treywelsh authored and frousselet committed Jan 12, 2023
1 parent cec6131 commit 3f196ff
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 12 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ BUG FIXES:
* resources/opennebula_virtual_router_instance_template: import more sections and attributes: `os`, `graphics`, `cpu_model`, `features`, `sched_requirements`, `sched_ds_requirements`, `description` (#377)
* resources/opennebula_virtual_machine: set empty values instead of null for `template_disk`, `template_nic`, `template_tags` (#312, #369)
* resources/opennebula_virtual_router_instance: set empty values instead of null for `template_disk`, `template_nic`, `template_tags` (#312, #369)
* resources/opennebula_host: add computed `cluster` attribute. (#389)
* resources/opennebula_datastore: add computed `clusters` attribute. (#389)

DEPRECATION:

* resources/opennebula_host: deprecate `cluster_id` (#389)
* resources/opennebula_datastore: deprecate `cluster_id` (#389)
* resources/opennebula_virtual_network: deprecate `clusters` (#389)


# 1.1.0 (December 6th, 2022)

Expand Down
10 changes: 10 additions & 0 deletions opennebula/resource_opennebula_datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ func resourceOpennebulaDatastore() *schema.Resource {
Optional: true,
Default: -1,
Description: "ID of the cluster",
Deprecated: "manage membership from the datastores attribute of the cluster",
},
"clusters": {
Type: schema.TypeSet,
Computed: true,
Description: "List of cluster IDs hosting the datastore",
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"restricted_directories": {
Type: schema.TypeString,
Expand Down Expand Up @@ -450,6 +459,7 @@ func resourceOpennebulaDatastoreRead(ctx context.Context, d *schema.ResourceData
}
d.Set("cluster_id", id)
}
d.Set("clusters", datastoreInfos.Clusters.ID)

restrictedDirs, err := datastoreInfos.Template.Get(dsKey.RestrictedDirs)
if err == nil {
Expand Down
7 changes: 7 additions & 0 deletions opennebula/resource_opennebula_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ func resourceOpennebulaHost() *schema.Resource {
Optional: true,
Default: -1,
Description: "ID of the cluster",
Deprecated: "manage membership from the hosts attribute of the cluster",
},
"cluster": {
Type: schema.TypeInt,
Computed: true,
Description: "Cluster IDs hosting the host",
},
"tags": tagsSchema(),
"default_tags": defaultTagsSchemaComputed(),
Expand Down Expand Up @@ -312,6 +318,7 @@ func resourceOpennebulaHostRead(ctx context.Context, d *schema.ResourceData, met

d.SetId(fmt.Sprintf("%v", hostInfos.ID))
d.Set("name", hostInfos.Name)
d.Set("cluster", hostInfos.ClusterID)

tags := make(map[string]interface{})
tagsAll := make(map[string]interface{})
Expand Down
6 changes: 0 additions & 6 deletions opennebula/resource_opennebula_host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func TestAccHost(t *testing.T) {
"virtualization": "dummy",
"information": "dummy",
}),
resource.TestCheckResourceAttr("opennebula_host.test1", "cluster_id", "0"),
resource.TestCheckResourceAttr("opennebula_host.test1", "tags.%", "2"),
resource.TestCheckResourceAttr("opennebula_host.test1", "tags.environment", "example"),
resource.TestCheckResourceAttr("opennebula_host.test1", "tags.test", "test"),
Expand All @@ -35,7 +34,6 @@ func TestAccHost(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("opennebula_host.test1", "name", "test-updated"),
resource.TestCheckResourceAttr("opennebula_host.test1", "type", "custom"),
resource.TestCheckResourceAttr("opennebula_host.test1", "cluster_id", "0"),
resource.TestCheckTypeSetElemNestedAttrs("opennebula_host.test1", "custom.*", map[string]string{
"virtualization": "dummy",
"information": "dummy",
Expand All @@ -54,7 +52,6 @@ func TestAccHost(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("opennebula_host.test1", "name", "test-updated"),
resource.TestCheckResourceAttr("opennebula_host.test1", "type", "custom"),
resource.TestCheckResourceAttr("opennebula_host.test1", "cluster_id", "0"),
resource.TestCheckTypeSetElemNestedAttrs("opennebula_host.test1", "custom.*", map[string]string{
"virtualization": "dummy",
"information": "dummy",
Expand Down Expand Up @@ -95,7 +92,6 @@ var testAccHostConfig = `
resource "opennebula_host" "test1" {
name = "test-custom"
type = "custom"
cluster_id = 0
custom {
virtualization = "dummy"
Expand All @@ -113,7 +109,6 @@ var testAccHostConfigAddOvercommit = `
resource "opennebula_host" "test1" {
name = "test-updated"
type = "custom"
cluster_id = 0
custom {
virtualization = "dummy"
Expand All @@ -136,7 +131,6 @@ var testAccHostConfigUpdate = `
resource "opennebula_host" "test1" {
name = "test-updated"
type = "custom"
cluster_id = 0
custom {
virtualization = "dummy"
Expand Down
3 changes: 2 additions & 1 deletion opennebula/resource_opennebula_virtual_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,12 @@ func resourceOpennebulaVirtualNetwork() *schema.Resource {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Description: "List of cluster IDs hosting the virtual Network, if not set it uses the default cluster",
Description: "List of cluster IDs hosting the virtual Network",
ConflictsWith: []string{"reservation_vnet", "reservation_size", "reservation_ar_id", "reservation_first_ip"},
Elem: &schema.Schema{
Type: schema.TypeInt,
},
Deprecated: "manage membership from the virtual_networks attribute of the cluster",
},
"vlan_id": {
Type: schema.TypeString,
Expand Down
3 changes: 2 additions & 1 deletion website/docs/r/datastore.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The following arguments are supported:

* `name` - (Required) The name of the datastore.
* `type` - (Required) Type of the new datastore: image, system, file.
* `cluster_id` - (Optional) ID of the cluster the datastore is part of.
* `cluster_id` - (Deprecated) ID of the cluster the datastore is part of.
* `restricted_directories` - (Optional) Paths that cannot be used to register images. A space separated list of paths.
* `safe_directories` - (Optional) If you need to allow a directory listed under RESTRICTED_DIRS. A space separated list of paths.
* `no_decompress` - (Optional) Boolean, do not try to untar or decompress the file to be registered.
Expand Down Expand Up @@ -86,6 +86,7 @@ The following attributes are exported:
* `id` - ID of the datastore.
* `tags_all` - Result of the applied `default_tags` and then resource `tags`.
* `default_tags` - Default tags defined in the provider configuration.
* `clusters` - List of cluster IDs hosting the datastore. Manager cluster membership from `datastores` fields of the `cluster` resource instead.

## Import

Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/host.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ Create a custom host:
resource "opennebula_host" "example" {
name = "test-kvm"
type = "custom"
cluster_id = 0
custom = {
virtualization = "custom"
Expand All @@ -60,7 +59,7 @@ The following arguments are supported:

* `name` - (Required) The name of the host.
* `type` - (Required) Type of the new host: kvm, qemu, lxd, lxc, firecracker, custom. For now vcenter type is not managed by the provider.
* `cluster_id` - (Optional) ID of the cluster the host is part of.
* `cluster_id` - (Deprecated) ID of the cluster the host is part of.
* `custom` - (Optional) If `type="custom"` this section should be defined, see [Custom](#custom) section for details.
* `overcommit` - (Optional) This section allow to increase the allocatable capacity of the host. See [Overcommit](#overcommit)
* `tags` - (Optional) Host tags (Key = value)
Expand All @@ -84,6 +83,7 @@ The following attributes are exported:
* `id` - ID of the host.
* `tags_all` - Result of the applied `default_tags` and then resource `tags`.
* `default_tags` - Default tags defined in the provider configuration.
* `cluster` - ID of the cluster hosting the host. Manager cluster membership from `hosts` fields of the `cluster` resource instead.

## Import

Expand Down
3 changes: 1 addition & 2 deletions website/docs/r/virtual_network.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ resource "opennebula_virtual_network" "example" {
dns = "172.16.100.1"
gateway = "172.16.100.1"
security_groups = [0]
clusters = [0]
ar {
ar_type = "IP4"
Expand Down Expand Up @@ -81,7 +80,7 @@ The following arguments are supported:
* `bridge` - (Optional) Name of the bridge interface to which the virtual network should be associated. Conflicts with `reservation_vnet` and `reservation_size`.
* `physical_device` - (Optional) Name of the physical device interface to which the virtual network should be associated. Conflicts with `reservation_vnet` and `reservation_size`.
* `type` - (Optional) Virtual network type. One of these: `dummy`, `bridge`'`fw`, `ebtables`, `802.1Q`, `vxlan` or `ovswitch`. Defaults to `bridge`. Conflicts with `reservation_vnet` and `reservation_size`.
* `clusters` - (Optional) List of cluster IDs where the virtual network can be use. Conflicts with `reservation_vnet` and `reservation_size`.
* `clusters` - (Deprecated) List of cluster IDs where the virtual network can be use. Conflicts with `reservation_vnet` and `reservation_size`. Manager cluster membership from `virtual_networks` fields of the `cluster` resource instead.
* `vlan_id` - (Optional) ID of VLAN. Only if `type` is `802.1Q`, `vxlan` or `ovswitch`. Conflicts with `reservation_vnet`, `reservation_size` and `automatic_vlan_id`.
* `automatic_vlan_id` - (Optional) Flag to let OpenNebula scheduler to attribute the VLAN ID. Conflicts with `reservation_vnet`, `reservation_size` and `vlan_id`.
* `mtu` - (Optional) Virtual network MTU. Defaults to `1500`. Conflicts with `reservation_vnet` and `reservation_size`.
Expand Down

0 comments on commit 3f196ff

Please sign in to comment.