-
Notifications
You must be signed in to change notification settings - Fork 0
/
values.yml
291 lines (261 loc) · 12.7 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
image:
repository: 9mine/9mine-vultr-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: 3000
ClusterIPRange:
from: 3001
to: 3020
description: "vultrfs"
fs: |
{% include './common.j2' %}
fs:
# root
"/":
<<: *is_dir
readdir:
sh: ls /accounts
# /<id>
"/[0-9]+":
<<: *is_dir
name: id
readdir:
list:
- version
- instance
# /<id>/.console.lua
"/.console.lua":
<<: *is_file
read_file:
sh: |
cat <<EOF
class "vultr_cmdchan"("cmdchan")
function vultr_cmdchan:vultr_cmdchan(connection, cmdchan_path)
self.connection = connection
self.cmdchan_path = cmdchan_path
end
function vultr_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 vultr_cmdchan:execute(command, location)
local tmp_file = "/n/cmdchan/cmdchan_output"
pcall(vultr_cmdchan.write, self, command, location)
return select(2, pcall(vultr_cmdchan.read, self, tmp_file))
end
connection:set_cmdchan(vultr_cmdchan(connection, core_conf:get("cmdchan_path")))
local tx_name = "9mine-vultr-fs-icon.png"
texture.download(
"https://www.vultr.com/favicon/android-chrome-512x512.png",
true, tx_name, "9mine-vultr-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(), "vultr: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 vultr_console(player, formname, fields)
if formname == "vultr: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("^vultr%-cli ", ""))
minetest.show_formspec(player_name, "vultr: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, "vultr: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("vultr:console", vultr_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 tx_name = "9mine-vultr-fs-icon.png"
if entry.platform_string == prefix .. "/instance/get" then
texture.download("https://www.vultr.com/favicon/android-chrome-512x512.png", true, tx_name, "9mine-vultr-fs")
entity:set_properties({
visual = "cube",
textures = {tx_name, tx_name, tx_name, tx_name, tx_name, tx_name}
})
end
end
class "vultr_cmdchan"("cmdchan")
function vultr_cmdchan:vultr_cmdchan(connection, cmdchan_path)
self.connection = connection
self.cmdchan_path = cmdchan_path
end
function vultr_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 vultr_cmdchan:execute(command, location)
local tmp_file = "/n/cmdchan/cmdchan_output"
pcall(vultr_cmdchan.write, self, command, location)
return select(2, pcall(vultr_cmdchan.read, self, tmp_file))
end
platform.cmdchan = vultr_cmdchan(platform.connection, core_conf:get("cmdchan_path"))
register.add_texture_handler(init_path .. "9mine-vultr-fs", set_texture)
local function vultr_message_handler(player_name, message)
if message:match("^vultr%-cli ") 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("^vultr%-cli ", "")
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 .. "vultr_message_handler", vultr_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 "export VULTR_API_KEY=`cat /accounts/${id}/api` && vultr-cli $str" > /accounts/$id/out 2>&1
cp /accounts/$id/out /accounts/$id/output
"/version":
<<: *is_file
read_file:
sh: export VULTR_API_KEY=`cat /accounts/${id}/api` && vultr-cli version
"/instance":
<<: *is_dir
readdir:
list:
- list
- get
"/list":
<<: *is_file
read_file:
sh: export VULTR_API_KEY=`cat /accounts/${id}/api` && vultr-cli instance list
"/get":
<<: *is_dir
readdir:
sh: export VULTR_API_KEY=`cat /accounts/${id}/api` && vultr-cli instance list | head -n -3 | tail -n 1 | awk '{print $1}'
"/[a-z0-9_-]+":
<<: *is_file
name: instanceid
read_file:
sh: export VULTR_API_KEY=`cat /accounts/${id}/api` && vultr-cli instance get ${instanceid}
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
VULTR_DIR = /tmp/aws/cmd
test -d $VULTR_DIR || mkdir -p $VULTR_DIR
load mpexpr
fs_port = ${expr $NINEP_PUBLIC_PORT 1 +}
file2chan $VULTR_DIR^/vultr {} {
load mpexpr
var=${expr 10 rand}
echo new id is $var
echo hostname is `{os hostname}
(api) = `{echo ${rget data}}
`{os /bin/bash -c 'mkdir -p /accounts/'^$var}
`{os /bin/bash -c 'echo '^$api^' > /accounts/'^$var^'/api'}
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 $VULTR_DIR & }
test -n $status && os pkill -9 emu-g
echo --- end of profile loading ---