Skip to content

Commit

Permalink
Merge pull request #17 from nutanix/test
Browse files Browse the repository at this point in the history
fixes to get spec from collection
  • Loading branch information
Gevorg-Khachatryan-97 authored Jan 19, 2022
2 parents 85fd3e6 + aa4a8ac commit 23b4819
Show file tree
Hide file tree
Showing 4 changed files with 282 additions and 6 deletions.
14 changes: 10 additions & 4 deletions nutanix/ncp/plugins/module_utils/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Entity:
"""Basic functionality for Nutanix modules"""

entity_type = "Base"

spec_file = ''
result = dict(
changed=False,
original_message="",
Expand Down Expand Up @@ -186,10 +186,16 @@ def get_action(self):
else:
raise ValueError("Wrong action: "+ self.action)

@staticmethod
def get_spec():
def get_spec(self):
import yaml
with open('testjson_spec.json') as f:
from os.path import join

# Get the current working directory

ncp_dir = self.module.tmpdir.split('/tmp')[0] + '/collections/ansible_collections/nutanix/ncp/'

file_path = join(ncp_dir, self.spec_file)
with open(file_path) as f:
# spec = json.loads(str(f.read()))
spec = yaml.safe_load(f.read())
return spec
Expand Down
2 changes: 1 addition & 1 deletion nutanix/ncp/plugins/module_utils/prism/vms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class VM(Prism):
kind = 'vm'

spec_file = 'vm_spec.json'
entity_type = "NutanixVm"

def get_attr_spec(self, param, param_spec, **kwargs):
Expand Down
271 changes: 271 additions & 0 deletions nutanix/ncp/vm_spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
{
"api_version": "{{api_version}}",
"metadata": {
"kind": "{{metadata__kind}}",
"uuid": "{{metadata__uuid}}",
"name": "{{metadata__name}}",
"spec_version": "{{metadata__spec_version}}",
"spec_hash": "{{metadata__spec_hash}}",
"categories": "{{metadata__categories}}",
"categories_mapping": "{{metadata__categories_mapping}}",
"use_categories_mapping": "{{metadata__use_categories_mapping}}",
"creation_time": "{{metadata__creation_time}}",
"last_update_time": "{{metadata__last_update_time}}",
"owner_reference": {
"kind": "{{metadata__owner_reference__kind}}",
"name": "{{metadata__owner_reference__name}}",
"uuid": "{{metadata__owner_reference__uuid}}",
"required": [
"kind",
"uuid"
]
},
"should_force_translate": "{{metadata__should_force_translate}}",
"entity_version": "{{metadata__entity_version}}",
"required": [
"kind"
]
},
"spec": {
"name": "{{spec__name}}",
"description": "{{spec__description}}",
"resources": {
"num_sockets": "{{spec__resources__num_sockets}}",
"num_vcpus_per_socket": "{{spec__resources__num_vcpus_per_socket}}",
"num_threads_per_core": "{{spec__resources__num_threads_per_core}}",
"memory_size_mib": "{{spec__resources__memory_size_mib}}",
"memory_overcommit_enabled": "{{spec__resources__memory_overcommit_enabled}}",
"gpu_console_enabled": "{{spec__resources__gpu_console_enabled}}",
"guest_os_id": "{{spec__resources__guest_os_id}}",
"is_vcpu_hard_pinned": "{{spec__resources__is_vcpu_hard_pinned}}",
"power_state": "{{spec__resources__power_state}}",
"power_state_mechanism": {
"mechanism": "{{spec__resources__power_state_mechanism__mechanism}}",
"guest_transition_config": {
"enable_script_exec": "{{spec__resources__power_state_mechanism__guest_transition_config__enable_script_exec}}",
"should_fail_on_script_failure": "{{spec__resources__power_state_mechanism__guest_transition_config__should_fail_on_script_failure}}",
"required": []
},
"required": []
},
"hardware_clock_timezone": "{{spec__resources__hardware_clock_timezone}}",
"is_agent_vm": "{{spec__resources__is_agent_vm}}",
"disable_branding": "{{spec__resources__disable_branding}}",
"enable_cpu_passthrough": "{{spec__resources__enable_cpu_passthrough}}",
"machine_type": "{{spec__resources__machine_type}}",
"hardware_virtualization_enabled": "{{spec__resources__hardware_virtualization_enabled}}",
"vtpm_config": {
"vtpm_enabled": "{{spec__resources__vtpm_config__vtpm_enabled}}",
"data_source_reference": {
"kind": "{{spec__resources__vtpm_config__data_source_reference__kind}}",
"uuid": "{{spec__resources__vtpm_config__data_source_reference__uuid}}",
"name": "{{spec__resources__vtpm_config__data_source_reference__name}}",
"url": "{{spec__resources__vtpm_config__data_source_reference__url}}",
"required": []
},
"required": []
},
"disk_list": [
{
"uuid": "{{spec__resources__disk_list__uuid}}",
"device_properties": {
"disk_address": {
"adapter_type": "{{spec__resources__disk_list__device_properties__disk_address__adapter_type}}",
"device_index": "{{spec__resources__disk_list__device_properties__disk_address__device_index}}",
"required": [
"adapter_type",
"device_index"
]
},
"device_type": "{{spec__resources__disk_list__device_properties__device_type}}",
"required": []
},
"disk_size_mib": "{{spec__resources__disk_list__disk_size_mib}}",
"disk_size_bytes": "{{spec__resources__disk_list__disk_size_bytes}}",
"data_source_reference": {
"kind": "{{spec__resources__disk_list__data_source_reference__kind}}",
"uuid": "{{spec__resources__disk_list__data_source_reference__uuid}}",
"name": "{{spec__resources__disk_list__data_source_reference__name}}",
"is_direct_attach": "{{spec__resources__disk_list__data_source_reference__is_direct_attach}}",
"url": "{{spec__resources__disk_list__data_source_reference__url}}",
"required": []
},
"volume_group_reference": {
"kind": "{{spec__resources__disk_list__volume_group_reference__kind}}",
"uuid": "{{spec__resources__disk_list__volume_group_reference__uuid}}",
"name": "{{spec__resources__disk_list__volume_group_reference__name}}",
"url": "{{spec__resources__disk_list__volume_group_reference__url}}",
"required": []
},
"storage_config": {
"storage_container_reference": {
"kind": "{{spec__resources__disk_list__storage_config__storage_container_reference__kind}}",
"uuid": "{{spec__resources__disk_list__storage_config__storage_container_reference__uuid}}",
"name": "{{spec__resources__disk_list__storage_config__storage_container_reference__name}}",
"url": "{{spec__resources__disk_list__storage_config__storage_container_reference__url}}",
"required": []
},
"flash_mode": "{{spec__resources__disk_list__storage_config__flash_mode}}",
"required": []
},
"required": [],
"list_key": "spec__resources__disk_list"
}
],
"nic_list": [
{
"uuid": "{{spec__resources__nic_list__uuid}}",
"nic_type": "{{spec__resources__nic_list__nic_type}}",
"vlan_mode": "{{spec__resources__nic_list__vlan_mode}}",
"trunked_vlan_list": "{{spec__resources__nic_list__trunked_vlan_list}}",
"num_queues": "{{spec__resources__nic_list__num_queues}}",
"mac_address": "{{spec__resources__nic_list__mac_address}}",
"ip_endpoint_list": [
{
"type": "{{spec__resources__nic_list__ip_endpoint_list__type}}",
"ip": "{{spec__resources__nic_list__ip_endpoint_list__ip}}",
"ip_type": "{{spec__resources__nic_list__ip_endpoint_list__ip_type}}",
"prefix_length": "{{spec__resources__nic_list__ip_endpoint_list__prefix_length}}",
"gateway_address_list": "{{spec__resources__nic_list__ip_endpoint_list__gateway_address_list}}",
"required": [],
"list_key": "spec__resources__nic_list__ip_endpoint_list"
}
],
"subnet_reference": {
"kind": "{{spec__resources__nic_list__subnet_reference__kind}}",
"name": "{{spec__resources__nic_list__subnet_reference__name}}",
"uuid": "{{spec__resources__nic_list__subnet_reference__uuid}}",
"required": [
"kind",
"uuid"
]
},
"network_function_chain_reference": {
"kind": "{{spec__resources__nic_list__network_function_chain_reference__kind}}",
"name": "{{spec__resources__nic_list__network_function_chain_reference__name}}",
"uuid": "{{spec__resources__nic_list__network_function_chain_reference__uuid}}",
"required": [
"kind",
"uuid"
]
},
"network_function_nic_type": "{{spec__resources__nic_list__network_function_nic_type}}",
"model": "{{spec__resources__nic_list__model}}",
"is_connected": "{{spec__resources__nic_list__is_connected}}",
"secondary_ip_address_list": "{{spec__resources__nic_list__secondary_ip_address_list}}",
"required": [],
"list_key": "spec__resources__nic_list"
}
],
"gpu_list": [
{
"mode": "{{spec__resources__gpu_list__mode}}",
"device_id": "{{spec__resources__gpu_list__device_id}}",
"vendor": "{{spec__resources__gpu_list__vendor}}",
"required": [],
"list_key": "spec__resources__gpu_list"
}
],
"parent_reference": {
"kind": "{{spec__resources__parent_reference__kind}}",
"uuid": "{{spec__resources__parent_reference__uuid}}",
"name": "{{spec__resources__parent_reference__name}}",
"url": "{{spec__resources__parent_reference__url}}",
"required": []
},
"boot_config": {
"boot_device": {
"disk_address": {
"adapter_type": "{{spec__resources__boot_config__boot_device__disk_address__adapter_type}}",
"device_index": "{{spec__resources__boot_config__boot_device__disk_address__device_index}}",
"required": [
"adapter_type",
"device_index"
]
},
"mac_address": "{{spec__resources__boot_config__boot_device__mac_address}}",
"required": []
},
"boot_device_order_list": "{{spec__resources__boot_config__boot_device_order_list}}",
"boot_type": "{{spec__resources__boot_config__boot_type}}",
"data_source_reference": {
"kind": "{{spec__resources__boot_config__data_source_reference__kind}}",
"uuid": "{{spec__resources__boot_config__data_source_reference__uuid}}",
"name": "{{spec__resources__boot_config__data_source_reference__name}}",
"url": "{{spec__resources__boot_config__data_source_reference__url}}",
"required": []
},
"required": []
},
"guest_customization": "{{spec__resources__guest_customization}}",
"guest_tools": {
"nutanix_guest_tools": {
"ngt_state": "{{spec__resources__guest_tools__nutanix_guest_tools__ngt_state}}",
"credentials": {
"username": "{{spec__resources__guest_tools__nutanix_guest_tools__credentials__username}}",
"password": "{{spec__resources__guest_tools__nutanix_guest_tools__credentials__password}}",
"required": [
"username"
]
},
"state": "{{spec__resources__guest_tools__nutanix_guest_tools__state}}",
"iso_mount_state": "{{spec__resources__guest_tools__nutanix_guest_tools__iso_mount_state}}",
"enabled_capability_list": "{{spec__resources__guest_tools__nutanix_guest_tools__enabled_capability_list}}",
"version": "{{spec__resources__guest_tools__nutanix_guest_tools__version}}",
"required": []
},
"required": []
},
"vga_console_enabled": "{{spec__resources__vga_console_enabled}}",
"vnuma_config": {
"num_vnuma_nodes": "{{spec__resources__vnuma_config__num_vnuma_nodes}}",
"required": []
},
"serial_port_list": [
{
"is_connected": "{{spec__resources__serial_port_list__is_connected}}",
"index": "{{spec__resources__serial_port_list__index}}",
"required": [],
"list_key": "spec__resources__serial_port_list"
}
],
"storage_config": {
"qos_policy": {
"throttled_iops": "{{spec__resources__storage_config__qos_policy__throttled_iops}}",
"required": [
"throttled_iops"
]
},
"flash_mode": "{{spec__resources__storage_config__flash_mode}}",
"required": []
},
"required": []
},
"availability_zone_reference": {
"kind": "{{spec__availability_zone_reference__kind}}",
"name": "{{spec__availability_zone_reference__name}}",
"uuid": "{{spec__availability_zone_reference__uuid}}",
"required": [
"kind",
"uuid"
]
},
"cluster_reference": {
"kind": "{{spec__cluster_reference__kind}}",
"name": "{{spec__cluster_reference__name}}",
"uuid": "{{spec__cluster_reference__uuid}}",
"required": [
"kind",
"uuid"
]
},
"required": [
"name",
"resources"
]
},
"required": [
"metadata",
"spec"
]
}
Loading

0 comments on commit 23b4819

Please sign in to comment.