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

Revert 410 imprv/issue#401 #425

Closed
wants to merge 8 commits into from
Closed
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
8 changes: 7 additions & 1 deletion examples/vm_info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@
kind: vm
register: result
ignore_errors: True


- name: List vms using FIQL filter string
ntnx_vms_info:
filter_string: "vm_name=={{vm.name}};power_state==off"
register: result
ignore_errors: True

- name: List vms using length, offset and ascending vm_name sorting
ntnx_vms_info:
length: 10
Expand Down
3 changes: 1 addition & 2 deletions examples/vm_operations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@

- name: hard power off the vm
ntnx_vms:
state: present
state: hard_poweroff
vm_uuid: "{{ vm_uuid }}"
operation: hard_poweroff
register: result
ignore_errors: true

Expand Down
8 changes: 6 additions & 2 deletions plugins/doc_fragments/ntnx_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ class ModuleDocFragment(object):
type: int
filter:
description:
- The filter in FIQL syntax used for the results
- The filter in key-value syntax used for the results
type: dict
custom_filter:
description:
- The filter in FIQL syntax used for the results
- The filter in key-value syntax used for the results
type: dict
filter_string:
description:
- The filter in FIQL syntax used for the results
type: str
"""
15 changes: 15 additions & 0 deletions plugins/doc_fragments/ntnx_vms_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,19 @@ class ModuleDocFragment(object):
- CDROM
- DISK
- NETWORK
owner:
description: Name or UUID of the owner
required: false
type: dict
suboptions:
name:
description:
- Owner Name
- Mutually exclusive with C(uuid)
type: str
uuid:
description:
- Owner UUID
- Mutually exclusive with C(name)
type: str
"""
9 changes: 9 additions & 0 deletions plugins/module_utils/base_info_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,21 @@ class BaseInfoModule(BaseModule):
length=dict(type="int"),
filter=dict(type="dict"),
custom_filter=dict(type="dict"),
filter_string=dict(type="str"),
)

info_args_mutually_exclusive = [
("filter", "filter_string"),
]

def __init__(self, skip_info_args=False, **kwargs):
self.argument_spec = deepcopy(BaseModule.argument_spec)
self.argument_spec.pop("state")
self.argument_spec.pop("wait")
if not skip_info_args:
self.argument_spec.update(self.info_argument_spec)
info_args_mutually_exclusive = deepcopy(self.info_args_mutually_exclusive)
if kwargs.get("mutually_exclusive"):
info_args_mutually_exclusive.extend(kwargs["mutually_exclusive"])
kwargs["mutually_exclusive"] = info_args_mutually_exclusive
super(BaseInfoModule, self).__init__(**kwargs)
10 changes: 7 additions & 3 deletions plugins/module_utils/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,14 @@ def get_info_spec(self):
else:
spec.pop(key)

if params.get("filter", {}).get("name") and params.get("kind") == "vm":
spec["filter"]["vm_name"] = spec["filter"].pop("name")
if params.get("filter"):
if params.get("filter", {}).get("name") and params.get("kind") == "vm":
spec["filter"]["vm_name"] = spec["filter"].pop("name")

spec["filter"] = self._parse_filters(params.get("filter", {}))
spec["filter"] = self._parse_filters(params.get("filter", {}))

elif params.get("filter_string"):
spec["filter"] = params["filter_string"]

return spec, None

Expand Down
8 changes: 6 additions & 2 deletions plugins/module_utils/ndb/database_clones.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,12 @@ def get_clone_refresh_spec(self):
payload["snapshotId"] = self.module.params.get("snapshot_uuid")
elif self.module.params.get("pitr_timestamp"):
payload["userPitrTimestamp"] = self.module.params.get("pitr_timestamp")
elif self.module.params.get("latest_snapshot", False):
payload["latestSnapshot"] = True
else:
return (
None,
"snapshot_uuid or pitr_timestamp is required for database clone refresh",
"One of snapshot_uuid, pitr_timestamp or latest_snapshot is required for database clone refresh",
)

payload["timeZone"] = self.module.params.get("timezone")
Expand Down Expand Up @@ -237,10 +239,12 @@ def _build_spec_time_machine(self, payload, time_machine):
payload["snapshotId"] = time_machine.get("snapshot_uuid")
elif time_machine.get("pitr_timestamp"):
payload["userPitrTimestamp"] = time_machine.get("pitr_timestamp")
elif time_machine.get("latest_snapshot", False):
payload["latestSnapshot"] = True
else:
return (
None,
"Required snapshot_uuid or pitr_timestamp for source of db clone",
"Required one of snapshot_uuid, pitr_timestamp or latest_snapshot for source of db clone",
)

payload["timeZone"] = time_machine.get("timezone")
Expand Down
7 changes: 5 additions & 2 deletions plugins/module_utils/ndb/time_machines.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ def get_time_machine(self, uuid=None, name=None, query=None):
if uuid:
resp = self.read(uuid=uuid, query=query)
elif name:
endpoint = "{0}/{1}".format("name", name)
resp = self.read(endpoint=endpoint, query=query)
if not query:
query = {}
query["value_type"] = "name"
query["value"] = name
resp = self.read(query=query)
if isinstance(resp, list):
if not resp:
return None, "Time machine with name {0} not found".format(name)
Expand Down
3 changes: 3 additions & 0 deletions plugins/module_utils/prism/spec/vms.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class DefaultVMSpec:
project=dict(
type="dict", options=entity_by_spec, mutually_exclusive=mutually_exclusive
),
owner=dict(
type="dict", options=entity_by_spec, mutually_exclusive=mutually_exclusive
),
cluster=dict(
type="dict", options=entity_by_spec, mutually_exclusive=mutually_exclusive
),
Expand Down
17 changes: 17 additions & 0 deletions plugins/module_utils/prism/vms.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from .projects import Project
from .spec.categories_mapping import CategoriesMapping
from .subnets import get_subnet_uuid
from .users import User


class VM(Prism):
Expand All @@ -32,6 +33,7 @@ def __init__(self, module):
"name": self._build_spec_name,
"desc": self._build_spec_desc,
"project": self._build_spec_project,
"owner": self._build_spec_owner,
"cluster": self._build_spec_cluster,
"vcpus": self._build_spec_vcpus,
"cores_per_vcpu": self._build_spec_cores,
Expand Down Expand Up @@ -220,6 +222,21 @@ def _build_spec_project(self, payload, param):
)
return payload, None

def _build_spec_owner(self, payload, param):
if "name" in param:
owner = User(self.module)
name = param["name"]
uuid = owner.get_uuid(name, key="username")
if not uuid:
error = "Owner {0} not found.".format(name)
return None, error

elif "uuid" in param:
uuid = param["uuid"]

payload["metadata"].update({"owner_reference": {"uuid": uuid, "kind": "user"}})
return payload, None

def _build_spec_cluster(self, payload, param):
uuid, err = get_cluster_uuid(param, self.module)
if err:
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/ntnx_foundation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
description: 'Nutanix module to image nodes and optionally create clusters'
options:
hypervisor_nameserver:
description: to-write
description: name server for hypervisors
type: str
required: false
cvm_gateway:
Expand Down Expand Up @@ -1244,7 +1244,7 @@ def image_nodes(module, result):

# add cluster urls if any cluster created
cluster_urls = []
if spec["clusters"]:
if spec.get("clusters"):
for cluster in spec["clusters"]:
cluster_urls.append(
{
Expand Down
5 changes: 3 additions & 2 deletions plugins/modules/ntnx_ndb_database_clone_refresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ def get_module_spec():
snapshot_uuid=dict(type="str", required=False),
timezone=dict(type="str", default="Asia/Calcutta", required=False),
pitr_timestamp=dict(type="str", required=False),
latest_snapshot=dict(type="bool", required=False)
)
return module_args

Expand Down Expand Up @@ -340,12 +341,12 @@ def refresh_clone(module, result):

def run_module():
mutually_exclusive_list = [
("snapshot_uuid", "pitr_timestamp"),
("snapshot_uuid", "pitr_timestamp", "latest_snapshot"),
]
module = NdbBaseModule(
argument_spec=get_module_spec(),
supports_check_mode=True,
required_if=[("state", "present", ("snapshot_uuid", "pitr_timestamp"), True)],
required_if=[("state", "present", ("snapshot_uuid", "pitr_timestamp", "latest_snapshot"), True)],
mutually_exclusive=mutually_exclusive_list,
)
remove_param_with_none_value(module.params)
Expand Down
3 changes: 2 additions & 1 deletion plugins/modules/ntnx_ndb_database_clones.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ def get_module_spec():
uuid=dict(type="str", required=False),
snapshot_uuid=dict(type="str", required=False),
pitr_timestamp=dict(type="str", required=False),
latest_snapshot=dict(type="bool", required=False),
timezone=dict(type="str", default="Asia/Calcutta", required=False),
)

Expand Down Expand Up @@ -700,7 +701,7 @@ def get_module_spec():
time_machine=dict(
type="dict",
options=time_machine,
mutually_exclusive=[("snapshot_uuid", "pitr_timestamp")],
mutually_exclusive=[("snapshot_uuid", "pitr_timestamp", "latest_snapshot")],
required=False,
),
postgres=dict(type="dict", options=postgres, required=False),
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/ntnx_ndb_time_machines_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def get_time_machine(module, result):
resp, err = tm.get_time_machine(uuid=uuid, name=name, query=query_params)
if err:
result["error"] = err
module.fail_json(msg="Failed fetching sla info", **result)
module.fail_json(msg="Failed fetching time machine info", **result)
result["response"] = resp


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,43 @@
fail_msg: " Fail : unable to create spec for imaging nodes"
success_msg: "Succes: spec generated successfully"

- name: Image nodes without cluster creation
ntnx_foundation:
timeout: 4500
cvm_gateway: "{{cvm_gateway}}"
cvm_netmask: "{{cvm_netmask}}"
hypervisor_gateway: "{{hypervisor_gateway}}"
hypervisor_netmask: "{{hypervisor_netmask}}"
default_ipmi_user: "{{default_ipmi_user}}"
current_cvm_vlan_tag: "{{nodes.current_cvm_vlan_tag}}"
nos_package: "{{images.aos_packages[0]}}"
blocks:
- block_id: "{{nodes.block_id}}"
nodes:
- manual_mode:
cvm_ip: "{{nodes.node2.cvm_ip}}"
cvm_gb_ram: 50
hypervisor_hostname: "{{nodes.node2.hypervisor_hostname}}"
ipmi_netmask: "{{nodes.node2.ipmi_netmask}}"
ipmi_gateway: "{{nodes.node2.ipmi_gateway}}"
ipmi_ip: "{{nodes.node2.ipmi_ip}}"
ipmi_password: "{{nodes.node2.ipmi_password}}"
hypervisor: "{{nodes.node2.hypervisor}}"
hypervisor_ip: "{{nodes.node2.hypervisor_ip}}"
node_position: "{{nodes.node2.node_position}}"
register: result
no_log: true
ignore_errors: True

- name: Creation Status
assert:
that:
- result.response is defined
- result.failed==false
- result.changed==true
fail_msg: " Fail : unable to image nodes"
success_msg: "Succes: node imaging done successfully"

- name: Image nodes and create cluster out of it
ntnx_foundation:
timeout: 4500
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,22 @@
- set_fact:
db_uuid: "{{result.db_uuid}}"

- name: create properties map
set_fact:
properties: "{{ properties | default({}) | combine ({ item['name'] : item['value'] }) }}"
loop: "{{result.response.properties}}"
- name: Ensure properties is defined
set_fact:
properties: "{}"
when: properties is undefined

- name: Combine properties
block:
- set_fact:
temp_dict: "{ '{{' }} item['name']: item['value'] {{ '}}' }}"
- set_fact:
properties: "{{ properties | combine(temp_dict) }}"
loop: "{{ result.response.properties }}"
no_log: true



- name: Creation Status
assert:
that:
Expand Down
35 changes: 35 additions & 0 deletions tests/integration/targets/nutanix_vms/tasks/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,41 @@
fail_msg: 'Unable to Create VM with none values '
success_msg: 'VM with none values created successfully '

- set_fact:
todelete: '{{ todelete + [ result["response"]["metadata"]["uuid"] ] }}'
# ##################################################################################
- name: VM with owner name
ntnx_vms:
state: present
name: none
timezone: GMT
project:
uuid: "{{ project.uuid }}"
cluster:
name: "{{ cluster.name }}"
categories:
AppType:
- Apache_Spark
owner:
name: "{{ vm_owner.name }}"
disks:
- type: DISK
size_gb: 5
bus: SCSI
register: result
ignore_errors: true

- name: Creation Status
assert:
that:
- result.response is defined
- result.response.status.state == 'COMPLETE'
- result.response.metadata.owner_reference.name == "{{ vm_owner.name }}"
- result.response.metadata.owner_reference.uuid == "{{ vm_owner.uuid }}"
- result.response.metadata.owner_reference.kind == "user"
fail_msg: 'Unable to Create VM with owner'
success_msg: 'VM with owner created successfully '

- set_fact:
todelete: '{{ todelete + [ result["response"]["metadata"]["uuid"] ] }}'
##################################################################################
Expand Down
Loading
Loading