forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a python openstack webserver example (pulumi#1004)
* Create a python openstack webserver example Shows how to create an openstack instance starting with image upload, addition of security group rules, creating a keypari for ssh access and a custom user data script to run on the instance * Use openstack and horizon in step description
- Loading branch information
Showing
5 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name: pulum | ||
runtime: | ||
name: python | ||
options: | ||
virtualenv: venv | ||
description: A minimal OpenStack Python Pulumi program |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
[![Deploy](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new) | ||
|
||
# Web Server Using Openstack | ||
|
||
|
||
## Prerequisites | ||
|
||
1. [Install Pulumi](https://www.pulumi.com/docs/get-started/install/) | ||
1. [Configure Pulumi for Openstack](https://www.pulumi.com/docs/intro/cloud-providers/openstack/setup/) | ||
1. [Configure Pulumi for Python](https://www.pulumi.com/docs/intro/languages/python/) | ||
|
||
## Deploying and running the program | ||
|
||
1. Create a new stack: | ||
|
||
```bash | ||
$ pulumi stack init | ||
``` | ||
|
||
2. Modify `__main__.py` to include your keypair and image | ||
|
||
3. Run `pulumi up` to preview and deploy changes: | ||
|
||
```bash | ||
$ pulumi up | ||
Previewing update (dev): | ||
Type Name Plan | ||
pulumi:pulumi:Stack pulum-dev | ||
+ ├─ openstack:images:Image fedora create | ||
+ ├─ openstack:compute:Keypair default create | ||
+ ├─ openstack:networking:SecGroupRule secgroupRule1 create | ||
+ ├─ openstack:networking:SecGroupRule secgroupRule2 create | ||
+ ├─ openstack:networking:SecGroupRule secgroupRule3 create | ||
+ └─ openstack:compute:Instance test_fedora create | ||
|
||
Outputs: | ||
~ instance_ip: "192.168.0.243" => output<string> | ||
|
||
Resources: | ||
+ 6 to create | ||
1 unchanged | ||
Resources: | ||
+ 6 created | ||
1 unchanged | ||
|
||
Duration: 38s | ||
|
||
``` | ||
|
||
4. View the host name and IP address of the instance via `stack output`: | ||
|
||
```bash | ||
$ pulumi stack output | ||
Current stack outputs (1): | ||
OUTPUT VALUE | ||
instance_ip 192.168.0.243 | ||
``` | ||
|
||
5. Verify that the Openstack instance exists, by either using the Horizon dashboard or running `openstack server list`. | ||
```bash | ||
$ openstack server list | ||
+--------------------------------------+-------------+--------+-------------------------------------+--------------------------+----------+ | ||
| ID | Name | Status | Networks | Image | Flavor | | ||
+--------------------------------------+-------------+--------+-------------------------------------+--------------------------+----------+ | ||
| 8bdf8a6d-ac53-4448-ae09-e2a08ad554a0 | test_fedora | ACTIVE | public=192.168.0.243, 2001:db8::36b | fedora | m1.small | | ||
+--------------------------------------+-------------+--------+-------------------------------------+--------------------------+----------+ | ||
``` | ||
|
||
## Clean up | ||
|
||
To clean up resources, run `pulumi destroy` and answer the confirmation question at the prompt. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
"""An OpenStack Python Pulumi program""" | ||
|
||
import pulumi | ||
import pulumi_openstack as openstack | ||
|
||
|
||
fedora_image = openstack.images.Image( | ||
"fedora", | ||
name="fedora", | ||
container_format="bare", | ||
disk_format="qcow2", | ||
image_source_url="https://ftp.plusline.net/fedora/linux/releases/34/Cloud/x86_64/images/Fedora-Cloud-Base-34-1.2.x86_64.qcow2", | ||
visibility="public", | ||
) | ||
|
||
default_keypair = openstack.compute.keypair.Keypair( | ||
"default", | ||
name="default", | ||
public_key="ssh-ed25519 <public key>", | ||
) | ||
|
||
secgroup_default = openstack.networking.get_sec_group(name="default") | ||
|
||
secgroup_rule_ssh = openstack.networking.SecGroupRule( | ||
"secgroupRule1", | ||
direction="ingress", | ||
ethertype="IPv4", | ||
port_range_max=22, | ||
port_range_min=22, | ||
protocol="tcp", | ||
remote_ip_prefix="0.0.0.0/0", | ||
description="Allow ssh", | ||
security_group_id=secgroup_default.id, | ||
) | ||
|
||
secgroup_rule_python_server = openstack.networking.SecGroupRule( | ||
"secgroupRule2", | ||
direction="ingress", | ||
ethertype="IPv4", | ||
port_range_max=8000, | ||
port_range_min=8000, | ||
protocol="tcp", | ||
remote_ip_prefix="0.0.0.0/0", | ||
description="Allow python http server", | ||
security_group_id=secgroup_default.id, | ||
) | ||
|
||
secgroup_rule_icmp = openstack.networking.SecGroupRule( | ||
"secgroupRule3", | ||
direction="ingress", | ||
ethertype="IPv4", | ||
protocol="icmp", | ||
remote_ip_prefix="0.0.0.0/0", | ||
description="Allow ping", | ||
security_group_id=secgroup_default.id, | ||
) | ||
|
||
network_public = openstack.networking.get_network(name="public") | ||
|
||
user_data = """ | ||
#!/bin/bash | ||
echo "Hello, World!" > index.html | ||
nohup python3 -m http.server & | ||
""" | ||
|
||
fedora = openstack.compute.Instance( | ||
"test_fedora", | ||
name="test_fedora", | ||
flavor_name="m1.small", | ||
image_id=fedora_image.id, | ||
key_pair=default_keypair.id, | ||
security_groups=["default"], | ||
networks=[ | ||
openstack.compute.InstanceNetworkArgs(uuid=network_public.id), | ||
], | ||
user_data=user_data, | ||
) | ||
|
||
# Export the IP of the instance | ||
pulumi.export("instance_ip", fedora.access_ip_v4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pulumi>=3.0.0,<4.0.0 | ||
pulumi-openstack>=3.0.0,<4.0.0 |