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

Fixes #43 so that ipv6 is not required for ip pools and adds example … #44

Merged
merged 1 commit into from
Sep 19, 2024
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
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace: cisco
name: ucs

# The version of the collection. Must be compatible with semantic versioning
version: 1.11.0
version: 1.12.0

# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
readme: README.md
Expand Down
71 changes: 71 additions & 0 deletions playbooks/ucs_ipv4_pool_only.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
# Example Playbook: cisco.ucs.ucs_ip_pool
- hosts: ucs
connection: local
gather_facts: false

tasks:
- name: Test that we have a UCS hostname, UCS username, and UCS password
fail:
msg: 'Please define the following variables: ucs_hostname, ucs_username and ucs_password.'
when: ucs_hostname is not defined or ucs_username is not defined or ucs_password is not defined
vars:
# use "<<: *login_info" to substite the information below in each task
# this is not required, however it makes the playbook shorter.
login_info: &login_info
hostname: "{{ ucs_hostname }}"
username: "{{ ucs_username }}"
password: "{{ ucs_password }}"

- name: Add UCS Organization
cisco.ucs.ucs_org:
<<: *login_info
org_name: level1
parent_org_path: root
description: level1 org
state: present
delegate_to: localhost

- name: Configure IPv4 address pool
cisco.ucs.ucs_ip_pool:
<<: *login_info
name: ext-mgmt
org_dn: org-root/org-level1
description: CIMC IP Pool
ipv4_blocks:
- first_addr: 192.168.10.1
last_addr: 192.168.10.20
subnet_mask: 255.255.255.128
default_gw: 192.168.10.2
- first_addr: 192.168.11.1
last_addr: 192.168.11.20
subnet_mask: 255.255.255.128
default_gw: 192.168.11.2
delegate_to: localhost

- name: Remove IPv4 address pool blocks
cisco.ucs.ucs_ip_pool:
<<: *login_info
name: ext-mgmt
org_dn: org-root/org-level1
ipv4_blocks:
- first_addr: 192.168.10.1
last_addr: 192.168.10.20
state: absent
delegate_to: localhost

- name: Remove IPv4 address pool
cisco.ucs.ucs_ip_pool:
<<: *login_info
name: ext-mgmt
org_dn: org-root/org-level1
state: absent
delegate_to: localhost

- name: Remove UCS Organization
cisco.ucs.ucs_org:
<<: *login_info
org_name: level1
parent_org_path: root
state: absent
delegate_to: localhost
57 changes: 3 additions & 54 deletions plugins/modules/ucs_ip_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,19 +394,6 @@ def main():
if not module.check_mode:
update_ip_block(ucs, mo, ipv4_block, 'v4')
changed = True
elif module.params['last_addr'] and module.params['first_addr']:
# ipv4 block specified, check properties
mo_1 = get_ip_block(ucs, dn, module.params['first_addr'], module.params['last_addr'], 'v4')
if mo_1:
kwargs = dict(subnet=module.params['subnet_mask'])
kwargs['def_gw'] = module.params['default_gw']
kwargs['prim_dns'] = module.params['primary_dns']
kwargs['sec_dns'] = module.params['secondary_dns']
if not mo_1.check_prop_match(**kwargs):
# ipv4 block exists and properties match
ipv4_props_match = False
else:
ipv4_props_match = False

# only check ipv6 props if the top-level and ipv4 props matched
if module.params['ipv6_blocks']:
Expand All @@ -415,48 +402,10 @@ def main():
if not module.check_mode:
update_ip_block(ucs, mo, ipv6_block, 'v6')
changed = True
elif module.params['ipv6_last_addr'] and module.params['ipv6_first_addr']:
# ipv6 block specified, check properties
block_dn = dn + '/v6block-' + module.params['ipv6_first_addr'].lower() + '-' + module.params[
'ipv6_last_addr'].lower()
mo_1 = ucs.login_handle.query_dn(block_dn)
if mo_1:
kwargs = dict(prefix=module.params['ipv6_prefix'])
kwargs['def_gw'] = module.params['ipv6_default_gw']
kwargs['prim_dns'] = module.params['ipv6_primary_dns']
kwargs['sec_dns'] = module.params['ipv6_secondary_dns']
if not mo_1.check_prop_match(**kwargs):
# ipv6 block exists and properties match
ipv6_props_match = False
else:
ipv6_props_match = False

if not ipv4_props_match or not ipv6_props_match:
if not module.check_mode:
if module.params['last_addr'] and module.params['first_addr']:
IppoolBlock(
parent_mo_or_dn=mo,
to=module.params['last_addr'],
r_from=module.params['first_addr'],
subnet=module.params['subnet_mask'],
def_gw=module.params['default_gw'],
prim_dns=module.params['primary_dns'],
sec_dns=module.params['secondary_dns'],
)

if module.params['ipv6_last_addr'] and module.params['ipv6_first_addr']:
IppoolIpV6Block(
parent_mo_or_dn=mo,
to=module.params['ipv6_last_addr'],
r_from=module.params['ipv6_first_addr'],
prefix=module.params['ipv6_prefix'],
def_gw=module.params['ipv6_default_gw'],
prim_dns=module.params['ipv6_primary_dns'],
sec_dns=module.params['ipv6_secondary_dns'],
)

ucs.login_handle.add_mo(mo, True)
ucs.login_handle.commit()
if not module.check_mode:
ucs.login_handle.add_mo(mo, True)
ucs.login_handle.commit()

changed = True

Expand Down
Binary file added releases/cisco-ucs-1.12.0.tar.gz
Binary file not shown.