shrub/base/ape/cloud/core.hook

449 lines
12 KiB
Plaintext
Raw Normal View History

2015-04-25 21:23:34 +03:00
:: digital ocean fleet management
::
::::
::
2015-05-13 16:14:36 +03:00
/? 314
/- *talk
/+ talk, sole, http
2015-04-25 21:23:34 +03:00
::
::
2015-05-21 04:34:45 +03:00
:::: sivtyv-barnel
2015-04-25 21:23:34 +03:00
::
!:
|%
2015-04-30 00:02:54 +03:00
++ droplet
2015-05-01 06:22:05 +03:00
$: id=@ud name=@t memory=@ud vcpus=@ud disk=@ud locked=?
2015-05-13 16:14:36 +03:00
created=@t status=@t backup-ids=(list ,@t) snapshot-ids=(list ,@ud)
2015-04-30 23:55:10 +03:00
features=(list ,@t) region=regi image=img
size=syze size-slug=@t networks=ntwrks kernel=kern
2015-04-30 05:24:24 +03:00
next-backup-window=json
2015-04-30 00:02:54 +03:00
==
2015-04-30 23:55:10 +03:00
++ regi ,[name=@t slug=@t sizes=(list ,@t)]
2015-04-30 05:24:24 +03:00
++ kern ,[id=@ud name=@t version=@t]
2015-04-30 00:02:54 +03:00
++ img
2015-05-21 04:34:45 +03:00
$: id=@ud name=@t distribution=@t slug=(unit ,@t) public=? regions=(list ,@t)
2015-04-30 00:02:54 +03:00
created-at=@t type=@t min-disk-size=@ud
==
2015-04-30 05:24:24 +03:00
++ ntwrks ,[v4=(list v) v6=(list v)]
2015-04-30 00:02:54 +03:00
++ v ,[ip-address=@t netmask=@t gateway=@t type=@t]
2015-04-30 23:55:10 +03:00
++ syze
$: memory=@ud price-monthly=@t price-hourly=@t disk=@ud vcpus=@ud
slug=@t transfer=@t available=? regions=(list ,@t)
2015-04-30 05:24:24 +03:00
==
2015-05-23 23:45:42 +03:00
++ create-req-do
2015-04-30 23:55:10 +03:00
$:
2015-05-23 23:45:42 +03:00
name=@t region=@t size=@t image=@t ssh=(list cord)
backups=(unit ,?) ipv6=(unit ,?)
private-networking=(unit ,?) user-data=(unit ,@t)
==
++ create-req-gce ,[project=@t zone=@t name=@t machine-type=@t]
++ axle
$: auth=[do=keys gcp=keys] toke=[do=tokens gcp=tokens]
drops=(list droplet)
2015-04-30 23:55:10 +03:00
==
2015-04-25 21:23:34 +03:00
++ keys ,[authc=(unit ,@t) client-secret=(unit ,@t)]
++ tokens ,[access=@t refresh=@t]
2015-05-21 04:34:45 +03:00
++ move ,[bone card]
++ card
$% [%diff %json json]
[%wait wire @da]
[%send wire [ship term] %poke %talk-command command]
[%them wire (unit hiss)]
2015-05-13 16:14:36 +03:00
==
2015-04-30 00:02:54 +03:00
--
2015-04-30 23:55:10 +03:00
!:
2015-05-01 22:05:16 +03:00
|% :::
2015-04-30 05:24:24 +03:00
++ parse-img
2015-04-30 00:02:54 +03:00
=> jo
2015-04-30 05:24:24 +03:00
%- ot
2015-05-21 04:34:45 +03:00
:~ id/ni name/so distribution/so slug/(mu so) public/bo
2015-04-30 05:24:24 +03:00
regions/(ar so) 'created_at'^so type/so 'min_disk_size'^ni
2015-04-30 00:02:54 +03:00
==
++ parse-ntwrks
=> jo
%- ot
2015-04-30 05:24:24 +03:00
:+ v4/(ar (ot 'ip_address'^so netmask/so gateway/so type/so ~))
v6/(ar (ot 'ip_address'^so netmask/so gateway/so type/so ~))
2015-04-30 00:02:54 +03:00
~
2015-04-30 05:24:24 +03:00
++ parse-size
=> jo
%- ot
2015-04-30 23:55:10 +03:00
:~ memory/ni 'price_monthly'^no 'price_hourly'^no disk/ni
vcpus/ni slug/so transfer/no available/bo regions/(ar so)
2015-04-30 05:24:24 +03:00
==
2015-04-30 23:55:10 +03:00
++ parse-region
=> jo
(ot name/so slug/so sizes/(ar so) ~)
2015-05-23 23:45:42 +03:00
++ create-do-body
|= $: name=@t region=@t size=@t image=@t ssh-keys=(list cord)
2015-04-30 23:55:10 +03:00
backups=(unit ,?) ipv6=(unit ,?) private-networking=(unit ,?) user-data=(unit ,@t)
2015-04-30 05:24:24 +03:00
==
%- jobe
2015-05-23 23:45:42 +03:00
:~ name/s/name region/s/region size/s/size image/s/image ::(jone image)
2015-05-13 16:14:36 +03:00
backups/?~(backups ~ b/u.backups) ipv6/?~(ipv6 ~ b/u.ipv6)
2015-04-30 23:55:10 +03:00
'user_data'^?~(user-data ~ s/u.user-data) 'private_networking'^?~(private-networking ~ b/u.private-networking)
2015-04-30 05:24:24 +03:00
==
2015-05-01 06:22:05 +03:00
++ state-to-json
|= a=(list droplet)
:- %a
%+ turn a
|= droplet
^- json
%- jobe
:~ id/`json`(jone id)
name/`json`s/name
vcpus/`json`(jone vcpus)
disk/`json`(jone disk)
locked/b/locked
created/s/created
status/s/status
backup-ids/a/(turn backup-ids |=(el=cord s/el))
2015-05-13 16:14:36 +03:00
snapshot-ids/a/(turn snapshot-ids jone)
2015-05-01 06:22:05 +03:00
features/a/(turn features |=(el=cord s/el))
=+ ^= reg
:~ name/s/name.region slug/s/slug.region
sizes/a/(turn sizes.region |=(el=cord s/el))
==
region/(jobe reg)
=+ ^= im
:~ id/(jone id.image) name/s/name.image distribution/s/distribution.image
2015-05-21 04:34:45 +03:00
slug/?~(slug.image ~ s/u.slug.image) public/b/public.image
2015-05-01 06:22:05 +03:00
regions/a/(turn regions.image |=(el=cord s/el))
created-at/s/created-at.image type/s/type.image
min-disk-size/(jone min-disk-size.image)
==
image/(jobe im)
=+ ^= sz
:~ memory/(jone memory.size) price-monthly/s/price-monthly.size
price-hourly/s/price-hourly.size disk/(jone disk.size) vcpus/(jone vcpus.size)
slug/s/slug.size transfer/s/transfer.size available/b/available.size
regions/a/(turn regions.size |=(el=cord s/el))
==
size/(jobe sz)
size-slug/s/size-slug
=+ ^= nt
=+ ^= vobj
|= v
%- jobe :~
ip-address/s/ip-address netmask/s/netmask
gateway/s/gateway type/s/type
==
:~ v4/[%a (turn v4.networks vobj)]
v6/[%a (turn v4.networks vobj)]
==
networks/(jobe nt)
kernel/s/'kernel'
next-backup-window/s/'valid'
==
2015-04-25 21:23:34 +03:00
--
!:
|_ [hid=hide vat=axle]
2015-04-30 00:02:54 +03:00
::
2015-05-23 23:45:42 +03:00
::++ prep ,_`.
2015-05-13 16:14:36 +03:00
:::
++ spam
|= jon=json
%+ turn (~(tap by sup.hid))
|= [sub=bone @ pax=path]
^- move
2015-05-21 04:34:45 +03:00
[sub %diff %json jon]
2015-05-13 16:14:36 +03:00
++ auth-queries
2015-05-21 04:34:45 +03:00
|= code=cord
2015-04-25 21:23:34 +03:00
:~ 'grant_type'^'authorization_code'
2015-05-21 04:34:45 +03:00
'code'^code
2015-04-25 21:23:34 +03:00
:- 'client_id'
'd8f46b95af38c1ab3d78ad34c2157a6959c23eb0eb5d8e393f650f08e6a75c6f'
2015-05-22 03:22:56 +03:00
'redirect_uri'^'http://localhost:8443/home/pub/cloud/fab'
2015-04-25 21:23:34 +03:00
==
++ httpreq
|= $: ost=bone pour-path=wire
domain=(list cord) end-point=path
2015-04-30 05:24:24 +03:00
req-type=$?(%get [%post json]) headers=math
2015-04-25 21:23:34 +03:00
queries=quay
==
^- move
=+ ^- parsed-url=purl
:+ ^= host-port :: ++hart
:+ security=%.y
port=~
host=[%.y [path=[%com domain]]]
endpoint=[extensions=~ point=end-point] :: ++pork,
q-strings=queries :: ++quay
=+ ^- request=hiss :: cast to hiss
:- parsed-url
2015-04-30 05:24:24 +03:00
?@ req-type
[%get headers ~]
[%post headers ~ (tact (pojo +.req-type))]
2015-05-21 04:34:45 +03:00
:^ ost %them pour-path
2015-04-25 21:23:34 +03:00
`(unit hiss)`[~ request]
::
++ peer
2015-05-21 04:34:45 +03:00
|= [[ost=bone you=ship] pax=path]
2015-04-25 21:23:34 +03:00
^- [(list move) _+>.$]
:_ +>.$
2015-05-21 04:34:45 +03:00
[ost %diff %json (state-to-json drops.vat)]~
2015-04-25 21:23:34 +03:00
::
2015-05-22 03:22:56 +03:00
++ poke-cloud-auth
2015-05-21 04:34:45 +03:00
|= [[ost=bone you=ship] [cde=cord typ=cord]]
2015-04-25 21:23:34 +03:00
^- [(list move) _+>.$]
2015-05-21 04:34:45 +03:00
~& [cde typ]
?: =(%do typ)
=. authc.do.auth.vat
[~ cde]
:_ +>.$
~
2015-05-23 23:45:42 +03:00
=. access.gcp.toke.vat
cde
2015-04-25 21:23:34 +03:00
:_ +>.$
2015-05-21 04:34:45 +03:00
~
2015-04-25 21:23:34 +03:00
::
2015-05-22 03:22:56 +03:00
++ poke-cloud-secret
2015-05-21 04:34:45 +03:00
|= [[ost=bone you=ship] secret=cord typ=cord]
2015-04-25 21:23:34 +03:00
^- [(list move) _+>.$]
2015-05-23 23:45:42 +03:00
~& [secret typ]
2015-05-21 04:34:45 +03:00
::=+ [newvat code path]=[vat(auth auth.vat) ...]
::=. vat newvat
?+ typ ~|(missing-platform=typ !!)
%do
=. client-secret.do.auth.vat
[~ secret]
:_ +>.$
:_ ~
2015-05-23 23:45:42 +03:00
%^ httpreq ost /auth-do
2015-05-21 04:34:45 +03:00
:^ ~[%digitalocean %cloud] `path`/v1/oauth/token
[%post ~]
:- ~ `quay`['client_secret'^secret (auth-queries (need authc.do.auth.vat))]
%gce
=. client-secret.gcp.auth.vat
[~ secret]
:_ +>.$
:_ ~
2015-05-23 23:45:42 +03:00
%^ httpreq ost /auth-gce
2015-05-21 04:34:45 +03:00
:^ ~[%google %cloud] `path`/v1/oauth/token
[%post ~]
2015-05-23 23:45:42 +03:00
:- (mo ['Content-Type' 'application/json' ~] ['Authorization' (cat 3 'Bearer ' access.do.toke.vat) ~] ~)
`quay`['client_secret'^secret %'access_token'^(need authc.gcp.auth.vat) ~] ::(auth-queries (need authc.gcp.auth.vat))]
2015-05-21 04:34:45 +03:00
==
2015-04-25 21:23:34 +03:00
::
2015-04-30 00:02:54 +03:00
++ receive-auth
2015-05-23 23:45:42 +03:00
|= [ost=bone pour-path=cord resp=httr]
2015-05-13 16:14:36 +03:00
^- [(list move) _+>.$]
~| resp
2015-05-21 04:34:45 +03:00
=+ body=(rash q:(need r.resp) apex:poja)
~| recieve-auth/resp(r body)
2015-05-23 23:45:42 +03:00
?+ pour-path !!
%auth-do
2015-04-30 00:02:54 +03:00
=+ [ac re]=(need ((ot 'access_token'^so 'refresh_token'^so ~):jo body))
2015-05-23 23:45:42 +03:00
=: access.do.toke.vat ac
refresh.do.toke.vat re
2015-04-30 00:02:54 +03:00
==
:_ +>.$
2015-05-13 16:14:36 +03:00
:~ (list-droplets ost)
(publish ost our.hid [%lin & 'successfully authenticated']~)
==
2015-05-23 23:45:42 +03:00
%auth-gce
::=+ ac=(need ((ot ~):jo
~& [body resp]
:_ +>.$
~
==
2015-04-30 00:02:54 +03:00
::
++ poke-json
2015-05-21 04:34:45 +03:00
|= [[ost=bone you=ship] act=json]
2015-05-01 22:05:16 +03:00
^- [(list move) _+>.$]
2015-04-30 05:24:24 +03:00
=+ do=(need ((ot action/so ~):jo act))
2015-04-30 00:02:54 +03:00
?+ do !!
2015-05-13 16:14:36 +03:00
%list
2015-05-01 06:22:05 +03:00
:_ +>.$
2015-05-13 16:14:36 +03:00
:- (list-droplets ost)
2015-05-21 04:34:45 +03:00
~
2015-05-13 16:14:36 +03:00
::
2015-05-23 23:45:42 +03:00
%create-do
2015-05-01 06:22:05 +03:00
:_ +>.$
2015-05-23 23:45:42 +03:00
=+ ^- deets=create-req-do
2015-05-01 06:22:05 +03:00
%- need
%. act
=> jo
%- ot
2015-05-23 23:45:42 +03:00
:~ name/so region/so size/so image/so :: id key:img object
2015-05-22 03:22:56 +03:00
ssh/(ar so) backups/(mu bo)
2015-05-01 06:22:05 +03:00
'ipv6'^(mu bo) 'priv_networking'^(mu bo) 'user_data'^(mu so)
==
2015-05-23 23:45:42 +03:00
:- (create-do ost deets)
~
::
%create-gce
~& 'chamado'
:_ +>.$
=+ ^- deets=create-req-gce
%- need
%. act
=> jo
%- ot
:~ project/so zone/so name/so %'machine_type'^so
==
~& 'dois'
:- (create-gce ost deets)
2015-05-21 04:34:45 +03:00
~
2015-05-13 16:14:36 +03:00
::
$? %reboot %'power_cycle' %shutdown %'power_off' %'power_on'
%'password_reset' %'enable_ipv6' %'enable_private_networking'
%snapshot %upgrade
==
=+ id=(need ((ot id/no ~):jo act))
(droplet-action ost id do)
2015-04-25 21:23:34 +03:00
==
2015-05-13 16:14:36 +03:00
::
++ droplet-action
|= $: os=bone id=@t
$= action $?
%delete %reboot %'power_cycle' %shutdown %'power_off'
%'power_on' %'password_reset' %'enable_ipv6' %'enable_private_networking'
%snapshot %upgrade :: add retrieve droplet action
== ==
:: restore, resize, rebuild, change_kernelm, retrieve droplet action
:_ +>.$
^- (list move)
2015-05-21 04:34:45 +03:00
:_ ~
2015-05-13 16:14:36 +03:00
=+ ^= req
2015-05-01 22:05:16 +03:00
%- httpreq :*
2015-05-13 16:14:36 +03:00
os /reboot
~[%digitalocean %api] /v2/droplets/[id]/actions
[%post `json`(jobe type/s/action ~)]
2015-05-23 23:45:42 +03:00
(mo ['Content-Type' 'application/json' ~] ['Authorization' (cat 3 'Bearer ' access.do.toke.vat) ~] ~)
2015-05-01 22:05:16 +03:00
*quay
==
2015-05-13 16:14:36 +03:00
req
2015-05-01 22:05:16 +03:00
2015-04-25 21:23:34 +03:00
++ list-droplets
|= os=bone
2015-05-01 06:22:05 +03:00
=+ ^= lis
:~ os /list
2015-04-25 21:23:34 +03:00
~[%digitalocean %api] /v2/droplets
%get
2015-05-23 23:45:42 +03:00
(mo ['Content-Type' 'application/json' ~] ['Authorization' (cat 3 'Bearer ' access.do.toke.vat) ~] ~)
2015-04-25 21:23:34 +03:00
==
2015-05-13 16:14:36 +03:00
(httpreq lis)
2015-04-30 00:02:54 +03:00
::
2015-04-30 05:24:24 +03:00
++ receive-list
2015-05-23 23:45:42 +03:00
|= [ost=bone plat=cord resp=httr]
2015-05-13 16:14:36 +03:00
^- [(list move) _+>.$]
2015-05-21 04:34:45 +03:00
=+ parsed=(rash q:(need r.resp) apex:poja)
2015-05-13 16:14:36 +03:00
~| recieve-list/parsed
2015-04-30 05:24:24 +03:00
=+ dar=(need ((ot droplets/(ar some) ~):jo parsed))
2015-04-30 23:55:10 +03:00
=+ ^- dropz=(list droplet)
2015-04-30 05:24:24 +03:00
~| bad-json/-.dar
2015-04-30 23:55:10 +03:00
%+ turn dar
|= drp=json
2015-04-30 05:24:24 +03:00
%- need
2015-04-30 23:55:10 +03:00
%. drp =+ jo
2015-04-30 05:24:24 +03:00
%- ot
2015-05-20 23:49:19 +03:00
:~ id/ni name/so
2015-04-30 05:24:24 +03:00
memory/ni vcpus/ni disk/ni
locked/bo 'created_at'^so status/so
2015-05-13 16:14:36 +03:00
'backup_ids'^(ar so) 'snapshot_ids'^(ar ni) features/(ar so)
2015-04-30 23:55:10 +03:00
region/parse-region image/parse-img size/parse-size
2015-04-30 05:24:24 +03:00
'size_slug'^so networks/parse-ntwrks kernel/(ot id/ni name/so version/so ~)
'next_backup_window'^some
==
2015-04-30 23:55:10 +03:00
=. drops.vat
dropz
2015-05-13 16:14:36 +03:00
=+ buf=`@da`(add ~s10 lat.hid)
2015-04-30 05:24:24 +03:00
:_ +>.$
2015-05-13 16:14:36 +03:00
:_ (spam (state-to-json drops.vat))
2015-05-21 04:34:45 +03:00
[ost %wait /refresh buf]
2015-04-30 05:24:24 +03:00
::
2015-05-23 23:45:42 +03:00
++ create-do
|= [os=bone create-req-do]
2015-05-21 04:34:45 +03:00
=- ~& - -
=+ ^- body=json
2015-05-23 23:45:42 +03:00
%- create-do-body :*
2015-05-21 04:34:45 +03:00
name region size image ssh backups
ipv6 private-networking user-data
2015-04-30 23:55:10 +03:00
==
2015-05-21 04:34:45 +03:00
%- httpreq :*
2015-05-23 23:45:42 +03:00
os /create-do
2015-05-21 04:34:45 +03:00
~[%digitalocean %api] /v2/droplets
[%post body]
%^ mo ['Content-Type' 'application/json' ~]
2015-05-23 23:45:42 +03:00
['Authorization' (cat 3 'Bearer ' access.do.toke.vat) ~]
2015-05-21 04:34:45 +03:00
~
~
==
2015-05-23 23:45:42 +03:00
++ create-gce
|= [os=bone create-req-gce]
~& 'called'
=+ ^- body=json
%- jobe
~[name/s/name %'machine-type'^s/machine-type]
~& body
=+ ^= req
%- httpreq
:* `bone`os `path`/create-gce
`(list cord)`~['googleapis' 'www'] `path`/v1/[project]/zones/[zone]/'instances'
~& 'here'
[%post `json`body]
2015-05-24 00:21:47 +03:00
~& 'here'
2015-05-24 00:40:20 +03:00
%^ mo ['Content-Type' 'application/json' ~]
['Authorization' (cat 3 'Bearer ' access.do.toke.vat) ~]
~
2015-05-23 23:45:42 +03:00
`quay`~
==
~& req req
2015-05-21 04:34:45 +03:00
++ wake
|= [[ost=bone him=ship pour-path=path] ~]
?+ -.pour-path !!
%refresh
:_ +>.$
[(list-droplets ost)]~
==
++ thou
|= [[ost=bone him=ship pour-path=path] resp=httr]
2015-04-30 00:02:54 +03:00
^- [(list move) _+>.$]
?+ -.pour-path !!
2015-05-23 23:45:42 +03:00
%auth-do
(receive-auth ost -.pour-path resp)
::
%auth-gce
(receive-auth ost -.pour-path resp)
2015-04-30 00:02:54 +03:00
::
%list
2015-05-23 23:45:42 +03:00
(receive-list ost -.pour-path resp)
2015-04-30 23:55:10 +03:00
::
2015-05-13 16:14:36 +03:00
$?
%delete %reboot %'power_cycle' %shutdown %'power_off'
%'power_on' %'password_reset' %'enable_ipv6' %'enable_private_networking'
%snapshot %upgrade :: add retrieve droplet action
2015-05-23 23:45:42 +03:00
%create-do %create-gce
2015-05-13 16:14:36 +03:00
==
~& resp
:_ +>.$ ~
2015-05-01 06:22:05 +03:00
::
2015-05-13 16:14:36 +03:00
%pub
:_ +>.$ ~
::
2015-04-30 00:02:54 +03:00
==
2015-05-13 16:14:36 +03:00
++ publish
|= [ost=bone you=ship act=(list speech)]
^- move
=+ ^= spchz
%+ turn act
|= sp=speech
=+ ^= tail
:- ^- audience
:+ :- `partner`[%& our.hid ?+((clan our.hid) !! %czar %court, %duke %porch)]
^- (pair envelope delivery)
[`envelope`[& ~] %pending]
~
~
`statement`[lat.hid ~ sp]
^- thought
:- `@`(sham eny.hid tail)
tail
2015-05-21 04:34:45 +03:00
=+ mez=[%talk-command [%publish `(list thought)`spchz]]
[ost %send /pub [our.hid %talk] %poke mez]
2015-04-25 21:23:34 +03:00
--