-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalues.yml
309 lines (282 loc) · 14.6 KB
/
values.yml
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
image:
repository: 9mine/9mine-aws-cloud-fs
tag: "main"
pullPolicy: Always
initContainerImage:
repository: 9mine/execfuse-jinja2
tag: "master"
pullPolicy: Always
securityContext:
privileged: true
capabilities:
add:
- SYS_ADMIN
service:
type: ClusterIP
port: 3370
ClusterIPRange:
from: 3371
to: 3390
description: "awscloudfs"
fs: |
{% include './common.j2' %}
fs:
# root
"/":
<<: *is_dir
readdir:
sh: ls /accounts
# /<id>
"/[0-9]+":
<<: *is_dir
name: id
readdir:
list:
- ec2
# /<id>/.console.lua
"/.console.lua":
<<: *is_file
read_file:
sh: |
cat <<EOF
class "aws_cmdchan"("cmdchan")
function aws_cmdchan:aws_cmdchan(connection, cmdchan_path)
self.connection = connection
self.cmdchan_path = cmdchan_path
end
function aws_cmdchan:write(command)
local conn = self.connection.conn
local f = conn:newfid()
print("Write " .. command .. " to " .. self.cmdchan_path)
conn:walk(conn.rootfid, f, self.cmdchan_path)
conn:open(f, 1)
local buf = data.new(command)
conn:write(f, 0, buf)
conn:clunk(f)
end
function aws_cmdchan:execute(command, location)
local tmp_file = "/n/cmdchan/cmdchan_output"
pcall(aws_cmdchan.write, self, command, location)
return select(2, pcall(aws_cmdchan.read, self, tmp_file))
end
connection:set_cmdchan(aws_cmdchan(connection, core_conf:get("cmdchan_path")))
local tx_name = "9mine-aws-cloud-fs-ec2-conf.png"
texture.download(
"https://upload.wikimedia.org/wikipedia/commons/thumb/5/5c/AWS_Simple_Icons_AWS_Cloud.svg/1200px-AWS_Simple_Icons_AWS_Cloud.svg.png",
true, tx_name, "9mine-aws-cloud-fs")
entity:set_properties({
visual = "cube",
textures = {tx_name, tx_name, tx_name, tx_name, tx_name, tx_name}
})
entity:get_luaentity().on_punch = function(self, player)
local p = self.object:get_pos()
local pos = minetest.serialize(p)
local request = ""
minetest.show_formspec(player:get_player_name(), "aws:console",
table.concat({"formspec_version[4]", "size[13,13,false]",
"textarea[0.5,0.5;12.0,10;;;" .. minetest.formspec_escape(self.output) .. "]",
"field[0.5,10.5;12,1;input;;]", "field_close_on_enter[input;false]",
"button[10,11.6;2.5,0.9;send;send]",
"field[13,13;0,0;entity_pos;;" .. minetest.formspec_escape(pos) .. "]"}, ""))
end
local function aws_console(player, formname, fields)
if formname == "aws:console" then
if not (fields.key_enter or fields.send) then
return
end
local player_name = player:get_player_name()
local pos = minetest.deserialize(fields.entity_pos)
local lua_entity = select(2, next(minetest.get_objects_inside_radius(pos, 0.5))):get_luaentity()
local cmdchan = connections:get_connection(player_name, lua_entity.addr):get_cmdchan()
cmdchan:write(fields.input:gsub("^aws ", ""))
minetest.show_formspec(player_name, "aws:console",
table.concat({"formspec_version[4]", "size[13,13,false]", "textarea[0.5,0.5;12.0,10;;;",
minetest.formspec_escape("Please, wait for response"), "]", "field[0.5,10.5;12,1;input;;]",
"field_close_on_enter[input;false]"}, ""))
minetest.after(3, function()
local function show_output()
local result, response = pcall(cmdchan.read, cmdchan, "/n/cmdchan/cmdchan_output")
if not result then
minetest.after(3, show_output)
return
end
lua_entity.output = fields.input .. ": \n" .. response .. "\n" .. lua_entity.output
minetest.show_formspec(player_name, "aws:console",
table.concat({"formspec_version[4]", "size[13,13,false]", "textarea[0.5,0.5;12.0,10;;;",
minetest.formspec_escape(lua_entity.output), "]", "field[0.5,10.5;12,1;input;;]",
"field_close_on_enter[input;false]", "button[10,11.6;2.5,0.9;send;send]",
"field[13,13;0,0;entity_pos;;", minetest.formspec_escape(fields.entity_pos), "]"}, ""))
end
show_output()
end)
end
end
register.add_form_handler("aws:console", aws_console)
EOF
# /<id>/.init.lua
"/.init.lua":
<<: *is_file
read_file:
sh: |
cat <<EOF
local function set_texture(entry, entity)
local prefix = init_path:match("/$") and init_path:sub(1, -2) or init_path
if not prefix then
return
end
local aws_textures_directory = "9mine-aws-cloud-fs"
local texture_prefix = "9mine-aws-cloud-fs"
if entry.entry_string == prefix .. "/ec2" then
texture.download("https://miro.medium.com/max/360/1*dfEIFZvuNC7ljFy2QNurLA.png", true,
texture_prefix .. "-ec2.png", aws_textures_directory)
entity:set_properties({
visual = "sprite",
textures = {texture_prefix .. "-ec2.png"}
})
end
if entry.platform_string == prefix .. "/ec2/describe-instances" then
texture.download("https://www.pinclipart.com/picdir/middle/323-3231192_aws-simple-icons-compute-amazon-ec2-clipart.png", true,
texture_prefix .. "-ec2-instance.png", aws_textures_directory)
entity:set_properties({
visual = "cube",
textures = {texture_prefix .. "-ec2-instance.png", texture_prefix .. "-ec2-instance.png", texture_prefix .. "-ec2-instance.png", texture_prefix .. "-ec2-instance.png", texture_prefix .. "-ec2-instance.png", texture_prefix .. "-ec2-instance.png"}
})
end
if entry.platform_string:match(string.gsub(prefix .. "/ec2/describe-instances", "%-", "%%%-") .. "/[%d%a%p]+") then
texture.download("https://upload.wikimedia.org/wikipedia/commons/thumb/5/5c/AWS_Simple_Icons_AWS_Cloud.svg/1200px-AWS_Simple_Icons_AWS_Cloud.svg.png", true,
texture_prefix .. "-ec2-conf.png", aws_textures_directory)
entity:set_properties({
visual = "sprite",
textures = {texture_prefix .. "-ec2-conf.png"}
})
end
end
class "aws_cmdchan"("cmdchan")
function aws_cmdchan:aws_cmdchan(connection, cmdchan_path)
self.connection = connection
self.cmdchan_path = cmdchan_path
end
function aws_cmdchan:write(command)
local conn = self.connection.conn
local f = conn:newfid()
print("Write " .. command .. " to " .. self.cmdchan_path)
conn:walk(conn.rootfid, f, self.cmdchan_path)
conn:open(f, 1)
local buf = data.new(command)
conn:write(f, 0, buf)
conn:clunk(f)
end
function aws_cmdchan:execute(command, location)
local tmp_file = "/n/cmdchan/cmdchan_output"
pcall(aws_cmdchan.write, self, command, location)
return select(2, pcall(aws_cmdchan.read, self, tmp_file))
end
platform.cmdchan = aws_cmdchan(platform.connection, core_conf:get("cmdchan_path"))
register.add_texture_handler(init_path .. "9mine-aws-cloud-fs", set_texture)
local function aws_message_handler(player_name, message)
if message:match("^aws ") then
local player = minetest.get_player_by_name(player_name)
local player_graph = graphs:get_player_graph(player_name)
local platform = player_graph:get_platform(common.get_platform_string(player))
if not platform then
return false
end
local cmdchan = platform:get_cmdchan()
if not cmdchan then
return
end
message = message:gsub("^aws ", "")
cmdchan:write(message)
minetest.chat_send_player(player_name, "Please, wait for response . . . ")
minetest.after(2, function()
local function read_response()
local result, response = pcall(cmdchan.read, cmdchan, "/n/cmdchan/cmdchan_output")
if not result then
minetest.after(2, read_response)
return
end
minetest.chat_send_player(player_name, message .. "\n" .. response .. "\n")
cmdchan.show_response(response, player_name)
end
read_response()
end)
return true
end
end
register.add_message_handler(init_path .. "aws_message_handler", aws_message_handler)
EOF
"/n":
<<: *is_dir
"/cmdchan":
<<: *is_dir
"/cmdchan_output":
getattr:
sh: (ls /accounts/$id/output >> /dev/null 2>&1 && echo 'ino=1 mode=-rwxr-xr-x nlink=1 uid=0 gid=0 rdev=0 size=0 blksize=512 blocks=2 atime=0 mtime=0 ctime=0 ')
read_file:
sh: cat /accounts/$id/output
"/chan":
<<: *is_dir
"/cmd":
<<: *is_file
write_file:
sh: |
str=`cat $CACHE_FILE_NAME`
rm -f /accounts/$id/output
eval "aws --profile $id $str" > /accounts/$id/out 2>&1
cp /accounts/$id/out /accounts/$id/output
# /<id>/ec2
"/ec2":
<<: *is_dir
readdir:
list:
- describe-instances
# /<id>/ec2/describe-instances
"/describe-instances":
<<: *is_dir
cache: 360
readdir:
sh: aws ec2 describe-instances --profile $id | jq -r '.Reservations[].Instances[].InstanceId'
# /<id>/ec2/describe-instances/<instance>
"/[a-z0-9_-]+":
<<: *is_dir
name: instanceid
cache: 16000
readdir:
sh: aws ec2 describe-instances --profile $id | jq -r ".Reservations[].Instances[] | select (.InstanceId==\"$instanceid\")" | jq -r "keys[]"
# /<id>/ec2/describe-instances/<instance>/<parameter>
"/[a-zA-Z0-9_-]+":
<<: *is_file
name: parameter
read_file:
sh: aws ec2 describe-instances --profile $id | jq -r ".Reservations[].Instances[] | select (.InstanceId==\"$instanceid\") .\"$parameter\""
profile: |
echo --- start of profile loading ---
load file2chan
load std
ndb/cs
for host_var in `{ os env } { '{'$host_var'}' }
dir = $EXPORT_PATH
port = $NINEP_PUBLIC_PORT
echo $NINEP_PUBLIC_HOST > /dev/sysname
test -d /mnt/registry || mkdir -p /mnt/registry
mount -A tcp!registry!registry /mnt/registry
AWS_DIR = /tmp/aws/cmd
test -d $AWS_DIR || mkdir -p $AWS_DIR
load mpexpr
fs_port = ${expr $NINEP_PUBLIC_PORT 1 +}
file2chan $AWS_DIR^/aws {} {
load mpexpr
var=${expr 10 rand}
echo new id is $var
echo hostname is `{os hostname}
(access_key secret_key region) = `{echo ${rget data}}
`{os /bin/bash -c 'mkdir -p /accounts/'^$var}
`{os /bin/bash -c 'aws configure set aws_access_key_id '^$access_key^' --profile '^$var}
`{os /bin/bash -c 'aws configure set aws_secret_access_key '^$secret_key^' --profile '^$var}
`{os /bin/bash -c 'aws configure set region '^$region^' --profile '^$var}
grid/reglisten -A -r description 'user id is '^$var tcp!*!^$fs_port { export $dir^/^$var & } &
fs_port=${expr $fs_port 1 +}
}
grid/reglisten -A -r description ${quote $NINEP_DESCRIPTION} 'tcp!*!'^$port { export $AWS_DIR & }
test -n $status && os pkill -9 emu-g
echo --- end of profile loading ---