Qinling, let’s run a packaged function

Gaëtan Trellu
May 31 · 4 min read

An amazing Python code sample edited with the fantastic Gimp!

A function a bit more complex this time

$ mkdir ~/qinling
$ wget -O ~/qinling/ip_range.py https://git.io/fj0SQ
$ pip install IPy -t ~/qinling
ip_range.py  IPy-1.0.dist-info  IPy.py  __pycache__
$ cd ~/qinling/
$ zip -r9 ~/qinling/ip_range.zip ~/qinling/

Run the best function ever ^^

$ openstack function create --name func-pkg-1 --runtime python3 --entry ip_range.details --package ~/qinling/ip_range.zip
$ openstack function execution create 1030e1ea-2374-40a7-bfbe-216bc5966f55
| result | {"duration": 0.036, "output": "{
"broadcast": "192.168.0.255",
"cidr": "192.168.0.0/24",
"ip_version": 4,
"length": 256,
"netmask": "255.255.255.0",
"prefix": 24,
"reverse": "0.168.192.in-addr.arpa.",
"type": "private"
}"} |
$ openstack function execution log show 5f2e7d71-7b26-4ab7-9e1a-854d8850e738
Start execution: 5f2e7d71-7b26-4ab7-9e1a-854d8850e738
----------------------
Function: details
JSON payload: {'ip_version': 4, 'type': 'private', 'reverse': '0.168.192.in-addr.arpa.', 'prefix': 24, 'netmask': '255.255.255.0', 'broadcast': '192.168.0.255', 'length': 256, 'cidr': '192.168.0.0/24'}
----------------------
----------------------
Function: build_json
JSON options
- indentation: 4
- sort: yes
{
"broadcast": "192.168.0.255",
"cidr": "192.168.0.0/24",
"ip_version": 4,
"length": 256,
"netmask": "255.255.255.0",
"prefix": 24,
"reverse": "0.168.192.in-addr.arpa.",
"type": "private"
}
----------------------
Finished execution: 5f2e7d71-7b26-4ab7-9e1a-854d8850e738

Change the default CIDR value

$ openstack function execution create 1030e1ea-2374-40a7-bfbe-216bc5966f55 --input '{"cidr": "10.0.0.0/10"}'
| result | {"duration": 0.035, "output": "{
"broadcast": "10.63.255.255",
"cidr": "10.0.0.0/10",
"ip_version": 4,
"length": 4194304,
"netmask": "255.192.0.0",
"prefix": 10,
"reverse": "0-255.10.in-addr.arpa.",
"type": "private"
}"} |

Conclusion

Resources

Gaëtan Trellu

Written by

Stories of a Technical Operations Manager @Ormuco_inc

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade