Skip to content

Commit

Permalink
Release v1.3 features (#220)
Browse files Browse the repository at this point in the history
* security rules basic structure #207

* security rules spec

* security rules create and delete functionality

* Fix sanity and doc

* security rules update functionality

* security rules info module

* add integraioson test

* security rules spec fixes

* security rules spec fixes

* security rules spec fixes

* security rules spec fixes, rule update functionality

* security rules requirements fixes

* fix sanity

* security rules requirements and spec generation fixes

* security rules requirements and spec generation fixes

* Add integration test

* sanity fix

* Add integration tests

* security rules requirements and spec generation fixes

* sanity fix

* Add integration test

* ad_rule -> vdi_rule

* update protocols spec, ability to delete rule

* update protocols spec

* updates for protocols spec

* updates for protocols spec

* Fix integration test

* updates for isolation rule

* updates for app, ad quarantine rules

* fix integraton

* Nutanix Image Module (#211)

* Image ansible module for creating images in PC

* Image placement policy module and its info module  (#214)

* Image placement policy module

* Add functionality to deattach all the categories from vm using flag remove_categories (#216)

* Add functionality to remove all categories from vm

* Update docs

* Vm example minor fix

* list functionality for address/service groups

* black and isort fixes

* black and isort fixes

* black and isort fixes

* black and isort fixes

* update requirements

* fixes

* ADGroup fixes

* ADGroup fixes

* remove default values for fields which are updatable

* Doc fix

* allow all updates

* allow all updates

* Common spec for categories mapping

* Formatting

* Formatting changes

* formatting

* formatting

* flake8 changes

* Sanity fix

* config changes

* Update categories in tests

* categories mapping

* categories mapping optimizations

* default_internal_policy fixes

* default_internal_policy fixes

* fixes for target categories updating

* Fix tests

* fixes for rules description

* remove categories mapping and prject reference

* Fix tests

* fix integration

* flake8 fix

* black and isort fixes

* black and isort fixes

* examples fixes

* isolation rule docs fixes

* fix sanity

* galaxy file changes

* sanity fix

* docs fixes

* vm's create ova and clone example fixes

* fix sanity

* fix sanity

* doc fixes

* doc fixes

* Setup config changes

* fix test

* Security info module fix

* doc fix

* Lint fixes

* setup config changes

* quarantine rule uuid changes

* sanity fix

* Update and info module for static routes  (#221)

Static routes module and info module

* UUID changes

* Changes for sanity and config

* sanity fix

* static routes minor formatting

* setup config changes

* formatting

* Fix bug dynamic inventory bug due to load_params

* changelog and readme updates

* Docs changes

* Change log changes

* Update docs

* Docs update

* Minor fix

Co-authored-by: Gevorg-Khachatryaan <Gevorg1050.1>
Co-authored-by: alaa-bish <[email protected]>
Co-authored-by: Gevorg Khachatryan <[email protected]>
Co-authored-by: Yannick Struyf <[email protected]>
  • Loading branch information
4 people authored Jul 4, 2022
1 parent 8a8f0e5 commit f4174ea
Show file tree
Hide file tree
Showing 75 changed files with 6,147 additions and 61 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## v1.3.0 (4 July 2022)

**Features**

**Prism Central**
- Ansible module for Image Management
- Ansible info module for Image Management
- Ansible module for Image Placement Policy
- Ansible info module for Image Placement Policies
- Ansible module for Network Security Rules
- Ansible info module for Network Security Rules
- Ansible module for VPC Static Routes
- Ansible info module for VPC Static Routes

## v1.2.0 (3 June 2022)

**Features**
Expand Down
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ It is designed keeping simplicity as the core value. Hence it is
## Prism Cenral
> For the 1.1.0 release of the ansible plugin it will have N-2 compatibility with the Prism Central APIs. This release was tested against Prism Central versions pc2022.1.0.2, pc.2021.9.0.5 and pc.2021.8.0.1.
> For the 1.2.0 release of the ansible plugin it will have N-2 compatibility with the Prism Central APIs. This release was tested against Prism Central versions pc.2022.4, pc2022.1.0.2 and pc.2021.9.0.5.
> For the 1.3.0 release of the ansible plugin it will have N-2 compatibility with the Prism Central APIs. This release was tested against Prism Central versions pc.2022.4, pc2022.1.0.2 and pc.2021.9.0.4. Static routes module (ntnx_static_routes) is only supported for PC versions >= pc.2022.1.
Prism Central based examples: https://github.com/nutanix/nutanix.ansible/tree/main/examples/

Expand Down Expand Up @@ -98,24 +99,32 @@ ansible-playbook examples/iaas/iaas.yml

| Name | Description |
| --- | --- |
| ntnx_floating_ips | Create or delete a Floating Ip. |
| ntnx_floating_ips_info | List existing Floating_Ips. |
| ntnx_images | Create, update or delete a image. |
| ntnx_images_info | List existing images. |
| ntnx_image_placement_policy | Create, update or delete a image placement policy. |
| ntnx_image_placement_policies_info | List existing image placement policies. |
| ntnx_pbrs | Create or delete a PBR. |
| ntnx_pbrs_info | List existing PBRs. |
| ntnx_security_rules | Create, update or delete a Security Rule. |
| ntnx_security_rules_info | List existing Security Rules. |
| ntnx_static_routes | Update static routes of a vpc. |
| ntnx_static_routes_info | List existing static routes of a vpc. |
| ntnx_subnets | Create or delete a Subnet. |
| ntnx_subnets_info | List existing Subnets. |
| ntnx_vms | Create or delete a VM. |
| ntnx_vms_clone | Clone VM. |
| ntnx_vms_ova | Create OVA image from VM. |
| ntnx_vms_info | List existing VMs. |
| ntnx_vpcs | Create or delete a VPC. |
| ntnx_vpcs_info | List existing VPCs. |
| ntnx_subnets | Create or delete a Subnet. |
| ntnx_subnets_info | List existing Subnets. |
| ntnx_floating_ips | Create or delete a Floating Ip. |
| ntnx_floating_ips_info | List existing Floating_Ips. |
| ntnx_pbrs | Create or delete a PBR. |
| ntnx_pbrs_info | List existing PBRs. |
| ntnx_foundation | Image nodes and create new cluster. |
| ntnx_foundation_bmc_ipmi_config | Configure IPMI IP address on BMC of nodes. |
| ntnx_foundation_image_upload | Upload hypervisor or AOS image to Foundation VM. |
| ntnx_foundation_aos_packages_info | List the AOS packages uploaded to Foundation. |
| ntnx_foundation_bmc_ipmi_config | Configure IPMI IP address on BMC of nodes. |
| ntnx_foundation_discover_nodes_info | List the nodes discovered by Foundation. |
| ntnx_foundation_hypervisor_images_info | List the hypervisor images uploaded to Foundation. |
| ntnx_foundation_image_upload | Upload hypervisor or AOS image to Foundation VM. |
| ntnx_foundation_node_network_info | Get node network information discovered by Foundation. |
| ntnx_foundation_central | Create a cluster out of nodes registered with Foundation Central. |
| ntnx_foundation_central_api_keys | Create a new api key which will be used by remote nodes to authenticate with Foundation Central. |
Expand All @@ -127,7 +136,7 @@ ansible-playbook examples/iaas/iaas.yml

| Name | Description |
| --- | --- |
| ntnx_vms_inventory | Nutanix VMs inventory source |
| ntnx_prism_vm_inventory | Nutanix VMs inventory source |

# Module documentation and examples
```
Expand Down
3 changes: 1 addition & 2 deletions examples/vm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,11 @@
is_overridable: True
register: output

- name: output of list Subnets
- name: output of vm created
debug:
msg: '{{ output }}'

- name: delete VM
ntnx_vms:
state: absent
vm_uuid: "{{output.vm_uuid}}"
register: output
14 changes: 6 additions & 8 deletions examples/vm_operations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,19 @@
ignore_errors: true

- name: create_ova_image while vm is on
ntnx_vms:
ntnx_vms_ova:
state: present
vm_uuid: "{{ vm_uuid }}"
operation: create_ova_image
ova_name: integration_test_VMDK_ova
ova_file_format: VMDK
src_vm_uuid: "{{ vm_uuid }}"
name: integration_test_VMDK_ova
file_format: VMDK
wait: true
register: result
ignore_errors: true

- name: clone vm while it's off also add network and script
ntnx_vms:
ntnx_vms_clone:
state: present
vm_uuid: "{{ vm_uuid }}"
operation: clone
src_vm_uuid: "{{ vm_uuid }}"
networks:
- is_connected: true
subnet:
Expand Down
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace: "nutanix"
name: "ncp"
version: "1.2.0"
version: "1.3.0"
readme: "README.md"
authors:
- "Abhishek Chaudhary (@abhimutant)"
Expand Down
14 changes: 11 additions & 3 deletions meta/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@ requires_ansible: '>=2.11.6'
action_groups:
ntnx:
- ntnx_floating_ips
- ntnx_images
- ntnx_image_placement_policy
- ntnx_pbrs
- ntnx_vms
- ntnx_vpcs
- ntnx_security_rules
- ntnx_static_routes
- ntnx_subnets
- ntnx_vms_ova
- ntnx_vms_clone
- ntnx_vms
- ntnx_vpcs
- ntnx_floating_ips_info
- ntnx_images_info
- ntnx_image_placement_policies_info
- ntnx_pbrs_info
- ntnx_security_rules_info
- ntnx_static_routes_info
- ntnx_subnets_info
- ntnx_vms_info
- ntnx_vpcs_info
- ntnx_subnets_info
- ntnx_foundation_aos_packages_info
- ntnx_foundation_bmc_ipmi_config
- ntnx_foundation_discover_nodes_info
Expand Down
3 changes: 2 additions & 1 deletion plugins/inventory/ntnx_prism_vm_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def __init__(self, host, port, username, password, validate_certs=False):
"nutanix_username": username,
"nutanix_password": password,
"validate_certs": validate_certs,
"load_params_without_defaults": False,
}

def jsonify(self, data):
Expand Down Expand Up @@ -150,7 +151,7 @@ def parse(self, inventory, loader, path, cache=True):
for nics in entity["status"]["resources"]["nic_list"]:
if nics["nic_type"] == "NORMAL_NIC" and nic_count == 0:
for endpoint in nics["ip_endpoint_list"]:
if endpoint["type"] == "ASSIGNED":
if endpoint["type"] in ["ASSIGNED", "LEARNED"]:
vm_ip = endpoint["ip"]
nic_count += 1
continue
Expand Down
17 changes: 13 additions & 4 deletions plugins/module_utils/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def upload(
self,
source,
endpoint=None,
method="POST",
query=None,
raise_error=True,
no_response=False,
Expand All @@ -125,7 +126,7 @@ def upload(
return self._upload_file(
url,
source,
method="POST",
method=method,
raise_error=raise_error,
no_response=no_response,
timeout=timeout,
Expand Down Expand Up @@ -353,13 +354,15 @@ def _fetch_url(
def _upload_file(
self, url, source, method, raise_error=True, no_response=False, timeout=30
):

file_chunks_iterator = FileChunksIterator(source)
headers = copy.deepcopy(self.headers)
headers["Content-Length"] = file_chunks_iterator.length
resp, info = fetch_url(
self.module,
url,
data=FileChunksIterator(source),
data=file_chunks_iterator,
method=method,
headers=self.headers,
headers=headers,
cookies=self.cookies,
timeout=timeout,
)
Expand All @@ -372,6 +375,12 @@ def _upload_file(
resp_json = None

if not raise_error:
# Add error details and status details if any
if not resp_json:
resp_json = {}
if status_code >= 300:
resp_json["error"] = body
resp_json["status_code"] = status_code
return resp_json

if status_code >= 300:
Expand Down
43 changes: 43 additions & 0 deletions plugins/module_utils/prism/address_groups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This file is part of Ansible
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function

__metaclass__ = type

from .prism import Prism


class AddressGroup(Prism):
def __init__(self, module):
resource_type = "/address_groups"
super(AddressGroup, self).__init__(module, resource_type=resource_type)

def get_uuid(self, value, key="name", raise_error=True, no_response=False):
data = {"filter": "{0}=={1}".format(key, value), "length": 1}
resp = self.list(data, raise_error=raise_error, no_response=no_response)
entities = resp.get("entities") if resp else None
if entities:
for entity in entities:
if entity["address_group"]["name"] == value:
return entity["uuid"]
return None


# Helper functions


def get_address_uuid(config, module):
if "name" in config:
address_group = AddressGroup(module)
name = config["name"]
uuid = address_group.get_uuid(name)
if not uuid:
error = "Address {0} not found.".format(name)
return None, error
elif "uuid" in config:
uuid = config["uuid"]
else:
error = "Config {0} doesn't have name or uuid key".format(config)
return None, error

return uuid, None
75 changes: 75 additions & 0 deletions plugins/module_utils/prism/image_placement_policy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# This file is part of Ansible
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function

from copy import deepcopy

from .prism import Prism
from .spec.categories_mapping import CategoriesMapping

__metaclass__ = type


class ImagePlacementPolicy(Prism):
def __init__(self, module):
resource_type = "/images/placement_policies"
super(ImagePlacementPolicy, self).__init__(module, resource_type=resource_type)
self.build_spec_methods = {
"name": self._build_spec_name,
"desc": self._build_spec_desc,
"categories": CategoriesMapping.build_categories_mapping_spec,
"remove_categories": CategoriesMapping.build_remove_all_categories_spec,
"placement_type": self._build_spec_placement_type,
"image_categories": self._build_spec_image_categories,
"cluster_categories": self._build_spec_cluster_categories,
}

def _get_default_spec(self):
return deepcopy(
{
"api_version": "3.1.0",
"metadata": {
"kind": "image_placement_policy",
},
"spec": {
"name": None,
"resources": {
"image_entity_filter": {
"params": {},
"type": "CATEGORIES_MATCH_ANY",
},
"cluster_entity_filter": {
"params": {},
"type": "CATEGORIES_MATCH_ANY",
},
},
},
}
)

def _build_spec_name(self, payload, name):
payload["spec"]["name"] = name
return payload, None

def _build_spec_desc(self, payload, desc):
payload["spec"]["description"] = desc
return payload, None

def _build_spec_placement_type(self, payload, type):
if type == "hard":
payload["spec"]["resources"]["placement_type"] = "EXACTLY"
else:
payload["spec"]["resources"]["placement_type"] = "AT_LEAST"
return payload, None

def _build_spec_image_categories(self, payload, category_mappings):
payload["spec"]["resources"]["image_entity_filter"][
"params"
] = category_mappings
return payload, None

def _build_spec_cluster_categories(self, payload, category_mappings):
payload["spec"]["resources"]["cluster_entity_filter"][
"params"
] = category_mappings
return payload, None
Loading

0 comments on commit f4174ea

Please sign in to comment.