-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen-data.py
More file actions
executable file
·102 lines (85 loc) · 2.29 KB
/
gen-data.py
File metadata and controls
executable file
·102 lines (85 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python
import random
from cf import *
from utils import *
### initiate
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-listing-event-history.html
cf = CF()
iEvents = cf.stack_status() # type: ignore
iTypes = [
'AWS::CloudFormation::Stack',
'AWS::IAM::Role',
'AWS::S3::Bucket',
'AWS::Lambda:Function'
]
iIds = [
'my-stack',
'test-stack',
'foo-stack',
'bar-stack'
]
iKeys = {
'EventId': 'Event',
'ResourceType': 'Type',
'LogicalResourceId': 'Resource',
'ResourceStatus': 'Status',
'Timestamp': 'TS',
'StackName': 'Stack',
# 'StackId': 'StackId',
'ResourceStatusReason': 'Reason',
}
'''
aws cloudformation list-stacks \
--stack-status-filter CREATE_COMPLETE
aws cloudformation describe-stacks \
--stack-name myteststack
aws cloudformation describe-stack-events \
--stack-name myteststack
aws cloudformation list-stack-resources \
--stack-name myteststack
'''
COLORED = True
res = {'Events': []}
iRange = 10
iPath = [
'CREATE_STACK',
'UPDATE_STACK',
'DELETE_STACK',
'IMPORT_STACK',
]
iStatus = cf.status_transition()
iPathIndex = 0
mi = MyIndex(levels=2)
for action in iPath:
ppwide(f'{mi.set(0)}. {action}')
tStates = []
for obj in iStatus[action]:
for sObj in obj:
if sObj not in tStates: tStates.append(sObj)
print(f' {mi.set(1)}. {textwrap.fill(str(obj), width=90, subsequent_indent=" "*8)}')
print()
print(
iColor(f'{len(tStates)} Unique States:', 'Green'),
textwrap.fill(str(tStates), 74, subsequent_indent=' '*8, break_on_hyphens=False)
)
print()
# sysExit('Done!')
res = []
for i in range(iRange):
iRand = random.randrange(start=1, stop=5)
ts = get_tdelta(get_dtutc(), hours=iRand) # type: ignore
myStatus = iStatus[iPath[iPathIndex]][iRand-1]
StackName = iIds[rand(0, len(iIds)-1)] + '-' + str(i)
rs = {
'StackName': StackName,
'StackStatus': myStatus[-1],
'TemplateDescription': lorem.sentence(),
'ResourceType': iTypes[rand(0, len(iTypes)-1)],
'LogicalResourceId': StackName,
'ResourceStatus': myStatus,
'Timestamp': ts,
'ResourceStatusReason': lorem.sentence(),
}
res.append(rs)
printll('Result')
ppjson(res)