Openstack / Create Port On Network
Create Port On Network
Create a new port on a specified network in OpenStack.
openstack port create --network <network_id_or_name> <port_name> openstack port create --network <network_id_or_name> <port_name> #!/bin/bash
# Create Port On Network
openstack port create --network {{network_id_or_name}} {{port_name}} import subprocess
# Create Port On Network
# Make sure to replace <placeholders> with actual values
def run_command():
cmd = [
"openstack",
"port",
"create",
"--network",
"<network_id_or_name>",
"<port_name>"
]
try:
print(f"Executing: {' '.join(cmd)}")
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
except FileNotFoundError:
print("Error: openstack not found. Please install it first.")
if __name__ == "__main__":
run_command() When To Use
When provisioning a new instance that requires networking resources.
Pro Tip
If the specified network is down, the port creation will fail; ensure network availability beforehand.
Anatomy of Output
Understanding the result
+--------------------------------------+------+----------+-------------------+-----------+ Output Header Displays the ID, name, and status of the newly created port.
| ID | Name | Network ID | MAC Address | Status | Column Details Details of the created port showing its identity and state.
| 23456789-abcd-ef00-2222-334455667788 | new-port | 87654321-dcba-9876-5432-abcdef012345 | 02:42:ac:11:00:03 | ACTIVE | Port Entry The output reflects the created port's details.
Troubleshooting
Common pitfalls
Network not found (HTTP 404)
Solution: Ensure that the network ID or name exists before creating a port.
Invalid port name (HTTP 400)
Solution: Port name must not contain special characters; use alphanumeric only.
Conflict (HTTP 409)
Solution: A port with that name already exists; use a unique name.
Command Breakdown
What each part is doing
-
openstack - Base Command
- The executable that performs this operation. Here it runs Openstack before the shell applies any redirect operators.
-
<network_id_or_name> - network id or name
- The value supplied for network id or name.
-
<port_name> - port name
- The port value supplied to this command.
-
--network - Command Option
- Tool-specific option used by this command invocation.
Alternative Approaches
Comparable commands in other tools
Alternative networking tools for the same job.
dnsmasq --version Curl / Send Form Encoded Data curl -X POST -d '<name=bob>' {http://example.com/form} Openvpn / Connect To Host With Same Static Key sudo openvpn --remote <bob.example.com> --dev <tun1> --ifconfig <10.4.0.2> <10.4.0.1> --secret <path/to/key> Ifconfig / Convert Command Output To Json Via Pipe <ifconfig> | jc <--ifconfig> Jc / Convert Command Output To Json Via Magic Syntax jc <ifconfig>