Openstack / Create New Server
Create New Server
Create a new server instance in OpenStack with specified image and flavor.
openstack server create --image <image_id> --flavor <flavor_id> --network <network_id> --wait <server_name> openstack server create --image <image_id> --flavor <flavor_id> --network <network_id> --wait <server_name> #!/bin/bash
# Create New Server
openstack server create --image {{image_id}} --flavor {{flavor_id}} --network {{network_id}} --wait {{server_name}} import subprocess
# Create New Server
# Make sure to replace <placeholders> with actual values
def run_command():
cmd = [
"openstack",
"server",
"create",
"--image",
"<image_id>",
"--flavor",
"<flavor_id>",
"--network",
"<network_id>",
"--wait",
"<server_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
During provisioning of new compute resources as part of an automated deployment pipeline.
Pro Tip
Utilize `--security-group` to add security restrictions during creation, mitigating future vulnerabilities.
Anatomy of Output
Understanding the result
+--------------------------------------+---------+----------+ Output Header Details new server ID and status.
| ID | Name | Status | Column Details Displays created server details.
| 789012bc-abcd-ef00-7777-88990000eeff | new-server | ACTIVE | New Server Entry Indicates successful creation and activation of the server.
Troubleshooting
Common pitfalls
Image not found (HTTP 404)
Solution: Verify the provided image ID matches an available image.
Flavor not found (HTTP 404)
Solution: Ensure the specified flavor ID is correct and available.
Conflict (HTTP 409)
Solution: A server with that name already exists; use a unique server 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.
-
<image_id> - image id
- The value supplied for image id.
-
<flavor_id> - flavor id
- The value supplied for flavor id.
-
<network_id> - network id
- The value supplied for network id.
-
<server_name> - server name
- The host or server name supplied to this command.
-
--image - Command Option
- Tool-specific option used by this command invocation.
-
--flavor - Command Option
- Tool-specific option used by this command invocation.
-
--network - Command Option
- Tool-specific option used by this command invocation.
-
--wait - 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>