Skip to content

Commit 282dead

Browse files
committed
feat(workload) create and delete catalogue item
1 parent d90b13b commit 282dead

8 files changed

Lines changed: 188 additions & 0 deletions
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import boto3
2+
3+
from staxapp.config import Config
4+
from staxapp.openapi import StaxClient
5+
6+
# Requirements
7+
# - Logged into the deployment bucket account
8+
# - Logged into the SDK
9+
10+
11+
Config.access_key = <Access Key>
12+
Config.secret_key = <Secret Key>
13+
14+
# Deployment bucket name
15+
deployment_bucket_name = <Deployment bucket workload name>
16+
# Path to Cloudformation file to deploy as a workload
17+
cloudformation_manifest_path = <Cloudformation File>
18+
# Catalogue Name
19+
catalogue_name = <Catalogue Name>
20+
# Catalogue version
21+
catalogue_version = <Catalogue Version>
22+
23+
# Get the AWS name of the deployment bucket
24+
ssm = boto3.client("ssm")
25+
bucket_name = ssm.get_parameter(Name=f"/workloads/{deployment_bucket_name}/BucketName", WithDecryption=True)
26+
27+
#Upload the cfn to the deployment bucket
28+
s3 = boto3.resource('s3')
29+
workload_client = StaxClient("workloads")
30+
cfn_name = f'{catalogue_version}-{catalogue_name}.yaml'
31+
s3.Bucket(bucket_name["Parameter"]["Value"]).upload_file(cloudformation_manifest_path, cfn_name)
32+
33+
# Make the cfn into a workload catalogue item
34+
manifest_body = f"""Resources:
35+
- WorkloadSSM:
36+
Type: AWS::Cloudformation
37+
TemplateURL: s3://{bucket_name["Parameter"]["Value"]}/{cfn_name}
38+
"""
39+
response = workload_client.CreateCatalogueItem(
40+
Name=catalogue_name,
41+
ManifestBody=manifest_body,
42+
Version=catalogue_version,
43+
Description='Example of how to use the sdk',
44+
)
45+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import boto3
2+
from staxapp.config import Config
3+
from staxapp.openapi import StaxClient
4+
5+
# Requirements
6+
# - Logged into the deployment bucket account
7+
# - Logged into the SDK
8+
9+
Config.access_key = <Access Key>
10+
Config.secret_key = <Secret Key>
11+
12+
# Deployment bucket name
13+
deployment_bucket_name = <Deployment bucket workload name>
14+
# Path to Cloudformation file to deploy as a workload
15+
cloudformation_manifest_path = <Cloudformation File>
16+
# Catalogue Id
17+
catalogue_id = <Catalogue Id>
18+
#The new Catalogue version
19+
catalogue_version = <Catalogue Version>
20+
21+
workload_client = StaxClient('workloads')
22+
23+
# Get the AWS name of the deployment bucket
24+
ssm = boto3.client("ssm")
25+
bucket_name = ssm.get_parameter(Name=f"/workloads/{deployment_bucket_name}/BucketName", WithDecryption=True)
26+
27+
#Upload the cfn to the deployment bucket
28+
s3 = boto3.resource('s3')
29+
workload_client = StaxClient("workloads")
30+
cfn_name = f'{catalogue_version}-{catalogue_name}.yaml'
31+
s3.Bucket(bucket_name["Parameter"]["Value"]).upload_file(cloudformation_manifest_path, cfn_name)
32+
33+
# Make the cfn into a workload catalogue item
34+
manifest_body = f"""Resources:
35+
- WorkloadSSM:
36+
Type: AWS::Cloudformation
37+
TemplateURL: s3://{bucket_name["Parameter"]["Value"]}/{cfn_name}
38+
"""
39+
40+
response = workload_client.CreateCatalogueVersion(
41+
ManifestBody=manifest_body,
42+
Version=catalogue_version,
43+
Description='Updating versions via sdk',
44+
catalogue_id=catalogue["Id"]
45+
)
46+
print(response)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from staxapp.config import Config
2+
from staxapp.openapi import StaxClient
3+
4+
# Requirements
5+
# - Logged into the deployment bucket account
6+
# - Logged into the SDK
7+
8+
Config.access_key = <Access Key>
9+
Config.secret_key = <Secret Key>
10+
11+
12+
catalogue_id = <Catalogue Id>
13+
workload_name = <Workload Name>
14+
account_id = <Account Id>
15+
parameter_dict = <Dictionary of Parameters
16+
tags_dict = <Dictionary of Tags>
17+
18+
workload_client = StaxClient('workloads')
19+
20+
parameters = []
21+
for key, value in parameter_dict.items():
22+
parameters.append({'Key': key, 'Value': value})
23+
24+
response = workload_client.CreateWorkload(
25+
Name=workload_name, CatalogueId=catalogue_id,
26+
AccountId=account_id, Region='ap-southeast-2',
27+
Parameters=parameters, Tags=tags_dict
28+
)
29+
print(response)
30+
31+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
from staxapp.config import Config
3+
from staxapp.openapi import StaxClient
4+
from staxapp.api import Api
5+
6+
# Requirements
7+
# - Logged into the SDK
8+
9+
10+
Config.access_key = <Access Key>
11+
Config.secret_key = <Secret Key>
12+
13+
catalogue_id = <Catalogue Id>
14+
15+
workload_client = StaxClient("workloads")
16+
17+
response = workload_client.DeleteCatalogueItem(catalogue_id=catalogue_id)
18+
print(response)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from staxapp.config import Config
2+
from staxapp.openapi import StaxClient
3+
4+
# Requirements
5+
# - Logged into the SDK
6+
7+
Config.access_key = <Access Key>
8+
Config.secret_key = <Secret Key>
9+
10+
workload_client = StaxClient('workloads')
11+
12+
# Catalogue Name
13+
catalogue_id = <Catalogue Id>
14+
#The Catalogue version to delete
15+
catalogue_version_id = <Catalogue Version>
16+
17+
response = workload_client.DeleteCatalogueVersion(
18+
catalogue_id=catalogue_id,
19+
version_id=catalogue_version_id
20+
)
21+
print(response)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from staxapp.config import Config
2+
from staxapp.openapi import StaxClient
3+
4+
Config.access_key = <Access Key>
5+
Config.secret_key = <Secret Key>
6+
7+
workload_id = <Workload Id>
8+
9+
workload_client = StaxClient('workloads')
10+
11+
response = workload_client.DeleteWorkload(workload_id=workload_id)
12+
print(response)
File renamed without changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from staxapp.config import Config
2+
from staxapp.openapi import StaxClient
3+
4+
Config.access_key = <Access key>
5+
Config.secret_key = <Secret key>
6+
7+
# Catalogue Id
8+
catalogue_id = <Catalogue Id>
9+
#Version Id
10+
version_id = <Catalogue Version>
11+
12+
workload_client = StaxClient("workloads")
13+
response = workload_client.ReadCatalogueVersion(catalogue_id=catalogue_id, version_id=version_id)
14+
15+
print(response)

0 commit comments

Comments
 (0)