-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaws_workspace_utils.py
More file actions
99 lines (79 loc) · 2.93 KB
/
Copy pathaws_workspace_utils.py
File metadata and controls
99 lines (79 loc) · 2.93 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
"""
Helper function for all things workspaces
"""
import boto3
class WorkSpaceClient():
'''
A class that abstracts AWS Workspace boto client
'''
def __init__(self, region):
'''
Create a client to interact with WorkSpaces in a region
'''
self.ws_client = boto3.client('workspaces', region_name=region)
def create_workspace(self, workspace_config):
'''
Create a WorkSpace in the given region
'''
response = self.ws_client.create_workspaces(Workspaces=[workspace_config])
return response
def delete_bundle(self, bundle_id):
'''
Delete a Bundle in the given region
'''
response = self.ws_client.delete_workspace_bundle(BundleId=bundle_id)
return response
def delete_image(self, image_id):
'''
Delete an Image in the given region
'''
response = self.ws_client.delete_workspace_image(ImageId=image_id)
return response
def get_current_bundles(self):
'''
Retrieve all bundles in the current region, used for deriving config
'''
bundles = None
response = self.ws_client.describe_workspace_bundles()
bundles = {i['Name']:i for i in response['Bundles']}
return bundles
def get_current_directories(self):
'''
Retrieve all directories in the current region, used for deriving config
'''
directories = None
response = self.ws_client.describe_workspace_directories()
directories = {i['Alias']:i for i in response['Directories']}
return directories
def get_current_images(self):
'''
Retrieve all images in the current region, used for deriving config
'''
images = None
response = self.ws_client.describe_workspace_images()
images = {i['Name']:i for i in response['Images']}
return images
def get_current_workspaces(self):
'''
Retrieve all workspaces in the current region, used for creating the list for creation
'''
workspaces = None
response = self.ws_client.describe_workspaces()
workspaces = response['Workspaces']
return workspaces
def get_tags(self, resource_id):
'''
Given a ResourceId, retrieve the tags associated with it, used for determining ownership
'''
tags = None
response = self.ws_client.describe_tags(ResourceId=resource_id)
tags = response.get('TagList')
return tags
def migrate_workspace(self, workspace_id, bundle_id):
'''
Migrate a WorkSpace in the given region to the given bundle_id.
See https://docs.aws.amazon.com/workspaces/latest/adminguide/migrate-workspaces.html
'''
response = self.ws_client.migrate_workspace(SourceWorkspaceId=workspace_id,
BundleId=bundle_id)
return response