Skip to content

Commit

Permalink
feat: Improve SKE, Postgres, RabbitMQ, Redis examples
Browse files Browse the repository at this point in the history
  • Loading branch information
joaopalet committed Nov 29, 2024
1 parent bad1092 commit 18a1e89
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import os

from stackit.core.configuration import Configuration
from stackit.postgresflex.api.default_api import DefaultApi
from stackit.postgresflex.models.create_instance_payload import CreateInstancePayload
from stackit.postgresflex.models.acl import ACL
from stackit.postgresflex.models.create_instance_payload import CreateInstancePayload
from stackit.postgresflex.models.storage import Storage
from stackit.core.configuration import Configuration

project_id = os.getenv("PROJECT_ID")
storage_class = "premium-perf2-stackit"

# Create a new API client, that uses default authentication and configuration
config = Configuration()
Expand All @@ -21,10 +20,11 @@
name="example-instance",
backupSchedule="0 0 1 * *",
acl=ACL(items=["45.129.40.0/21", "193.148.160.0/19"]),
storage=Storage(var_class=storage_class, size=20),
storage=Storage(var_class="premium-perf2-stackit", size=20),
flavorId=flavor_response.flavors[0].id,
replicas=1,
version="16",
options={"type": "Single"},
)
client.create_instance(project_id, create_instance_payload)
instance = client.create_instance(project_id, create_instance_payload)
print("Created instance with ID: " + instance.id)
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import os

from stackit.postgresflex.api.default_api import DefaultApi
from stackit.core.configuration import Configuration
from stackit.postgresflex.api.default_api import DefaultApi

project_id = os.getenv("PROJECT_ID")
instance_id = "INSTANCE_ID"

# Create a new API client, that uses default authentication and configuration
config = Configuration()
client = DefaultApi(config)

# List all postgresflex instances
response = client.list_instances(project_id)

# Delete all instances
for instance in response.items:
client.delete_instance(project_id, instance.id)
# Delete an instances
client.delete_instance(project_id, instance_id)
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import os

from stackit.core.configuration import Configuration
from stackit.rabbitmq.api.default_api import DefaultApi
from stackit.rabbitmq.models.create_instance_payload import CreateInstancePayload

from stackit.core.configuration import Configuration

project_id = os.getenv("PROJECT_ID")
storage_class = "premium-perf2-stackit"

# Create a new API client, that uses default authentication and configuration
config = Configuration()
Expand All @@ -17,7 +15,8 @@

# Create instance using the first flvaor
create_instance_payload = CreateInstancePayload(
instance_name="exampleInstance",
instance_name="example-instance",
plan_id=response.offerings[0].plans[0].id,
)
client.create_instance(project_id, create_instance_payload)
instance = client.create_instance(project_id, create_instance_payload)
print("Created instance with ID: " + instance.instance_id)
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import os

from stackit.rabbitmq.api.default_api import DefaultApi
from stackit.core.configuration import Configuration
from stackit.rabbitmq.api.default_api import DefaultApi

project_id = os.getenv("PROJECT_ID")
instance_id = "INSTANCE_ID"

# Create a new API client, that uses default authentication and configuration
config = Configuration()
client = DefaultApi(config)

# List all rabbitmq instances
response = client.list_instances(project_id)

# Delete all instances
for instance in response.instances:
client.delete_instance(project_id, instance.cf_guid)
# Delete an instance
client.delete_instance(project_id, instance_id)
16 changes: 7 additions & 9 deletions examples/redis/create_instance.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import os

from stackit.core.configuration import Configuration
from stackit.redis.api.default_api import DefaultApi
from stackit.redis.models.create_instance_payload import CreateInstancePayload
from stackit.core.configuration import Configuration

project_id = os.getenv("PROJECT_ID")

config = Configuration()
client = DefaultApi(config)

# check out all available offerings
# Check out all available offerings
available_offerings = client.list_offerings(project_id)

# take the first available plan id
# Take the first available plan id
offering_id = available_offerings.offerings[0].plans[0].id
payload = CreateInstancePayload(
instance_name="Test Instance",
instance_name="test-instance",
plan_id=offering_id,
)

# create the instance
response = client.create_instance(project_id, payload)
instance_id = response.instance_id

print(f"Instance with id:{instance_id} has been created.")
# Create the instance
instance = client.create_instance(project_id, payload)
print("Created instance with ID: " + instance.instance_id)
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import os

from stackit.redis.api.default_api import DefaultApi
from stackit.core.configuration import Configuration

from stackit.redis.api.default_api import DefaultApi

project_id = os.getenv("PROJECT_ID")
instance_id = "INSTANCE_ID"

config = Configuration()
client = DefaultApi(config)

# get all instances
response = client.list_instances(project_id)

# delete all instances
for instance in response.instances:
client.delete_instance(project_id=project_id, instance_id=instance.cf_guid)
# Delete an instance
client.delete_instance(project_id=project_id, instance_id=instance_id)
5 changes: 2 additions & 3 deletions examples/redis/list_instances.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import os

from stackit.redis.api.default_api import DefaultApi
from stackit.core.configuration import Configuration

from stackit.redis.api.default_api import DefaultApi

project_id = os.getenv("PROJECT_ID")

config = Configuration()
client = DefaultApi(config)

# get all instances
# Get all instances
print(client.list_instances(project_id))
2 changes: 1 addition & 1 deletion examples/resourcemanager/list_projects.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

from stackit.resourcemanager.api.default_api import DefaultApi
from stackit.core.configuration import Configuration
from stackit.resourcemanager.api.default_api import DefaultApi

project_id = os.getenv("PROJECT_ID")

Expand Down
35 changes: 16 additions & 19 deletions examples/ske/create_cluster.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,47 @@
import os

from stackit.core.configuration import Configuration
from stackit.ske.api.default_api import DefaultApi
from stackit.ske.models.create_or_update_cluster_payload import (
CreateOrUpdateClusterPayload,
)
from stackit.ske.models.image import Image
from stackit.ske.models.kubernetes import Kubernetes
from stackit.ske.models.nodepool import Nodepool
from stackit.ske.models.machine import Machine
from stackit.ske.models.nodepool import Nodepool
from stackit.ske.models.volume import Volume
from stackit.ske.models.image import Image

from stackit.core.configuration import Configuration


project_id = os.getenv("PROJECT_ID")
volume_type = "storage_premium_perf0"

# Create a new API client, that uses default authentication and configuration
config = Configuration()
client = DefaultApi(config)

# Get available options
options_resonse = client.list_provider_options()

# Create a new instance using the first option for everything
cluser_name = "cl-name"
create_instance_payload = CreateOrUpdateClusterPayload(
kubernetes=Kubernetes(version=options_resonse.kubernetes_versions[0].version),
# Create a new cluster
cluster_name = "my-cl"
create_cluster_payload = CreateOrUpdateClusterPayload(
kubernetes=Kubernetes(version="1.30.6"),
nodepools=[
Nodepool(
availability_zones=[options_resonse.availability_zones[0].name],
availability_zones=["eu01-3"],
machine=Machine(
image=Image(
name=options_resonse.machine_images[0].name,
version=options_resonse.machine_images[0].versions[0].version,
name="ubuntu",
version="2204.20240912.0",
),
type=options_resonse.machine_types[0].name,
type="b1.2",
),
maximum=3,
minimum=2,
name="my-nodepool",
volume=Volume(
size=20,
type=volume_type,
type="storage_premium_perf0",
),
)
],
)
client.create_or_update_cluster(project_id, cluser_name, create_instance_payload)
cluster = client.create_or_update_cluster(
project_id, cluster_name, create_cluster_payload
)
print("Created cluster with name: " + cluster.name)
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import os

from stackit.ske.api.default_api import DefaultApi
from stackit.core.configuration import Configuration
from stackit.ske.api.default_api import DefaultApi

project_id = os.getenv("PROJECT_ID")
cluster_name = "CLUSTER_NAME"

# Create a new API client, that uses default authentication and configuration
config = Configuration()
client = DefaultApi(config)

# List all ske clusters
response = client.list_clusters(project_id)

# Delete all cluster
for cluster in response.items:
client.delete_cluster(project_id, cluster.name)
# Delete a cluster
client.delete_cluster(project_id, cluster_name)
2 changes: 1 addition & 1 deletion examples/ske/list_clusters.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

from stackit.ske.api.default_api import DefaultApi
from stackit.core.configuration import Configuration
from stackit.ske.api.default_api import DefaultApi

project_id = os.getenv("PROJECT_ID")

Expand Down

0 comments on commit 18a1e89

Please sign in to comment.