codeaffen / phpipam-ansible-modules

Ansible Modules to manage phpIPAM installations
https://codeaffen.org/projects/phpipam-ansible-modules
GNU General Public License v3.0
22 stars 10 forks source link

Unable to create subnet in folder #101

Closed ingvarrwvw closed 1 year ago

ingvarrwvw commented 1 year ago

Describe the bug When creating a subnet, there is no way to specify in which folder it should be placed. Apparently the "master_folder" option is missing. This is possible through the web interface.

Screenshot: image

Versions:

Additional context Add any other context about the problem here.

cmeissner commented 1 year ago

/related #100

ingvarrwvw commented 1 year ago

/related #100

not sure if they are related. If you create a folder via gui, then it is impossible to specify it as a master folder when creating a subnet via ansible. It has nothing to do with idempotency, does it?

cmeissner commented 1 year ago

They are. As folders need to managed throught folders controller and not subnet. In phpIPAM both entity types are managed within subnet namespace but the presentation. Same entity parameters are used for different presentations.

See docs, subnet module has parameter parent which should work with subnets but not with folders. As resolution of folders does not work we first need to create folders handling. Second we will refactor parent/folder handling in subnet module.

To understand the relation it is a good idea to query the API directly (e.g. via cURL) to see what data will be returned.

See default data:

image

Query subnet 10.65.22.0 which is children of My folder

curl -ks -XGET -H "phpipam-token: ${IPAM_TOKEN}" https://localhost:8443/api/ansible/subnets/6 | jq '. | {subnet: .data.subnet, mask: .data.mask, masterSubnetId: .data.masterSubnetId, isFolder: .data.isFolder, description: .data.description}'
{
  "subnet": "10.65.22.0",
  "mask": "24",
  "masterSubnetId": "5",
  "isFolder": "0",
  "description": "DHCP range"
}

Querying My folder via subnet controller will not return any data

curl -ks -XGET -H "phpipam-token: ${IPAM_TOKEN}" https://localhost:8443/api/ansible/subnets/5 | jq '. | {subnet: .data.subnet, mask: .data.mask, masterSubnetId: .data.masterSubnetId, isFolder: .data.isFolder, description: .data.description}' 
{
  "subnet": null,
  "mask": null,
  "masterSubnetId": null,
  "isFolder": null,
  "description": null
}

but via folders controller

curl -ks -XGET -H "phpipam-token: ${IPAM_TOKEN}" https://localhost:8443/api/ansible/folders/5 | jq '. | {subnet: .data.subnet, mask: .data.mask, masterSubnetId: .data.masterSubnetId, isFolder: .data.isFolder, description: .data.description}'
{
  "subnet": "0.0.0.0",
  "mask": "",
  "masterSubnetId": "0",
  "isFolder": "1",
  "description": "My folder"
}

Similar story if we query 10.10.1.0/24 which is children of 10.10.0.0/16

curl -ks -XGET -H "phpipam-token: ${IPAM_TOKEN}" https://localhost:8443/api/ansible/subnets/3 | jq '. | {subnet: .data.subnet, mask: .data.mask, masterSubnetId: .data.masterSubnetId, isFolder: .data.isFolder, description: .data.description}'
{
  "subnet": "10.10.1.0",
  "mask": "24",
  "masterSubnetId": "2",
  "isFolder": "0",
  "description": "Customer 1"
}

subnet controller will return data for parent

curl -ks -XGET -H "phpipam-token: ${IPAM_TOKEN}" https://localhost:8443/api/ansible/subnets/2 | jq '. | {subnet: .data.subnet, mask: .data.mask, masterSubnetId: .data.masterSubnetId, isFolder: .data.isFolder, description: .data.description}'
{
  "subnet": "10.10.0.0",
  "mask": "16",
  "masterSubnetId": "0",
  "isFolder": "0",
  "description": "Business customers"
}

But folders controller will not

curl -ks -XGET -H "phpipam-token: ${IPAM_TOKEN}" https://localhost:8443/api/ansible/folders/2 | jq '. | {subnet: .data.subnet, mask: .data.mask, masterSubnetId: .data.masterSubnetId, isFolder: .data.isFolder, description: .data.description}' 
{
  "subnet": null,
  "mask": null,
  "masterSubnetId": null,
  "isFolder": null,
  "description": null
}

Independently of it seems that the resolving of parent will not work in the current version of our subnet module.

ingvarrwvw commented 1 year ago
"5",

thanks for the detailed explanation, looking forward to fixes