cutting out create-disk

This commit is contained in:
Henry Ault 2015-06-10 13:53:43 -07:00
parent 277886d092
commit 273400608c
4 changed files with 178 additions and 104 deletions

View File

@ -41,6 +41,18 @@ $% [%diff %json json]
[%send wire [ship term] %poke %talk-command command] [%send wire [ship term] %poke %talk-command command]
[%them wire (unit hiss)] [%them wire (unit hiss)]
== ==
++ droplet-action
$% [%start ~]
[%stop ~]
[%reboot ~]
[%delete ~]
[%snapshot p=@t]
==
++ cloud-command
$% [%action id=@t name=@t act=droplet-action]
[%create-do p=json]
[%create-gce p=json]
==
-- --
!: !:
|% ::: |% :::
@ -66,6 +78,23 @@ $% [%diff %json json]
== ==
++ parse-zone-sign ;~(plug ;~(pose (cold & lus) (cold | hep))) ++ parse-zone-sign ;~(plug ;~(pose (cold & lus) (cold | hep)))
-- --
++ parse-cloud-command
=+ jo
%- of :~
[%create-do some]
[%create-gce some]
:- %action
(ot id/so name/so act/parse-droplet-action ~)
==
++ parse-droplet-action
=> jo
%- of :~
[%start ul]
[%stop ul]
[%reboot ul]
[%delete ul]
[%snapshot so]
==
++ key-do ++ key-do
(mo [%start 'power_on'] [%stop 'shutdown'] [%reboot 'power_cycle'] ~) (mo [%start 'power_on'] [%stop 'shutdown'] [%reboot 'power_cycle'] ~)
++ adapter-do ++ adapter-do
@ -100,7 +129,7 @@ $% [%diff %json json]
'user_data'^?~(user-data ~ s/u.user-data) 'private_networking'^?~(private-networking ~ b/u.private-networking) 'user_data'^?~(user-data ~ s/u.user-data) 'private_networking'^?~(private-networking ~ b/u.private-networking)
== ==
++ convert-do ++ convert-do
|= a=?(%start %stop %reboot) |= a=?(%start %stop %reboot %snapshot)
?- a ?- a
%start %start
'power_on' 'power_on'
@ -108,9 +137,13 @@ $% [%diff %json json]
'shutdown' 'shutdown'
%reboot %reboot
'power_cycle' 'power_cycle'
%snapshot
'snapshot'
== ==
++ instance-to-json ++ instance-to-json
|= a=(list instance) |= a=(list instance)
^- json
%+ joba 'instances'
:- %a :- %a
%+ turn a %+ turn a
|= instance |= instance
@ -132,6 +165,7 @@ $% [%diff %json json]
|=(a=[[@t @t] image] `image`+.a) |=(a=[[@t @t] image] `image`+.a)
++ image-to-json ++ image-to-json
|= a=(list image) |= a=(list image)
%+ joba 'images'
:- %a :- %a
%+ turn a %+ turn a
|= image |= image
@ -231,72 +265,75 @@ $% [%diff %json json]
list-do list-do
:: ::
++ poke-json ++ poke-json
|= act=json |= jon=json
^- [(list move) _+>.$] ^- [(list move) _+>.$]
=+ action=(need ((ot action/so ~):jo act)) ~& receive-act/jon
=+ action=`cloud-command`(need (parse-cloud-command jon))
:_ +>.$ :_ +>.$
?+ action !! ?- -.action
::
%create-do %create-do
[(create-do act)]~ [(create-do p.action)]~
:: ::
%create-gce %create-gce
(create-gce-disks act) ::(create-gce-disks p.action)
~[(create-gce 'name')]
:: ::
?(%start %stop %reboot %delete) %action
=+ :- id=(need ((ot id/so ~):jo act)) [(instance-action [id name act]:action)]~
name=(need ((ot name/so ~):jo act))
[(instance-action id name action)]~
== ==
:: ::
++ instance-action ++ instance-action
|= $: id=@t name=@t |= [id=@t name=@t action=droplet-action]
$= action $?
%start %stop %reboot %delete
== ==
=+ d=(~(got by insts.vat) id) =+ d=(~(got by insts.vat) id)
~| 'can\'t find id' ~| 'can\'t find id'
=+ typ=?~(d !! -.d) =+ typ=?~(d !! -.d)
?- typ ?- typ
%do %do
=+ meth=?:(?=(%delete action) %delt [%post (jobe type/s/(convert-do action) ~)]) =+ ^= meth
^- move ?: ?=(%delete -.action)
=+ ^= req %delt
%- httpreq :* [%post (jobe type/s/(convert-do -.action) ?.(?=(%snapshot -.action) ~ [name/s/p.action ~]))]
/do/[action] ^- move
~[%digitalocean %api] =+ ^= req
?:(?=(%delt meth) /v2/droplets/[id] /v2/droplets/[id]/actions) %- httpreq :*
meth /do/[-.action]
%^ mo ['Content-Type' 'application/json' ~] ~[%digitalocean %api]
['Authorization' (cat 3 'Bearer ' access.do.toke.vat) ~] ~ ?:(?=(%delt meth) /v2/droplets/[id] /v2/droplets/[id]/actions)
*quay meth
== %^ mo ['Content-Type' 'application/json' ~]
req ['Authorization' (cat 3 'Bearer ' access.do.toke.vat) ~] ~
*quay
==
req
%gce %gce
=+ ^= head-query =+ ^= head-query
:- %^ mo ['Content-Type' 'application/json' ~] :- %^ mo ['Content-Type' 'application/json' ~]
['Authorization' (cat 3 'Bearer ' access.gce.toke.vat) ~] ~ ['Authorization' (cat 3 'Bearer ' access.gce.toke.vat) ~] ~
*quay *quay
?- action ?- -.action
?(%start %stop %reboot) ?(%start %stop %reboot %'snapshot')
=+ end=/compute/v1/projects/urbcloud/zones/us-central1-a/instances/[name] =+ end=/compute/v1/projects/urbcloud/zones/us-central1-a/instances/[name]
%- httpreq :* %- httpreq :*
/gce-act/[action] ~['googleapis' 'www'] /gce-act/[-.action] ~['googleapis' 'www']
(welp end [?:(?=(%reboot action) 'reset' action) ~]) (welp end [?:(?=(%reboot -.action) 'reset' -.action) ~])
[%post ~] [%post ~]
head-query head-query
== ==
%delete %delete
=+ end=/compute/v1/projects/urbcloud/zones/us-central1-a/instances/[name] =+ end=/compute/v1/projects/urbcloud/zones/us-central1-a/instances/[name]
~& end %- httpreq :*
%- httpreq :* /gce-act/[-.action] ~['googleapis' 'www']
/gce-act/[action] ~['googleapis' 'www'] end
end %delt
%delt head-query
head-query ==
== ==
==
== ==
++ thou-do-snapshot
|= [pax=path resp=httr]
~& 'arrives'
~& response/resp
:_ +>.$ ~
++ thou-gce-act ++ thou-gce-act
|= [pax=path resp=httr] |= [pax=path resp=httr]
~& [resp act/pax] ~& [resp act/pax]
@ -343,7 +380,7 @@ $% [%diff %json json]
=+ ^- body=json =+ ^- body=json
(jobe name/s/name %'sourceSnapshot'^s/'compute/v1/projects/urbcloud/global/snapshots/snapshot-1' ~) ::^so/snap ~) (jobe name/s/name %'sourceSnapshot'^s/'compute/v1/projects/urbcloud/global/snapshots/snapshot-1' ~) ::^so/snap ~)
%- httpreq %- httpreq
:* /create-gce-disk/[snapshot]/[name] :* /create-gce-disk/[snap]/[name]
~['googleapis' 'www'] /compute/v1/projects/urbcloud/zones/us-central1-a/disks ~['googleapis' 'www'] /compute/v1/projects/urbcloud/zones/us-central1-a/disks
[%post body] [%post body]
%^ mo ['Content-Type' 'application/json' ~] %^ mo ['Content-Type' 'application/json' ~]
@ -370,6 +407,7 @@ $% [%diff %json json]
?: =('200' hcode) ?: =('200' hcode)
~| 'did not receive 200' !! ~| 'did not receive 200' !!
=+ :-(parsed=(rash q:(need r.resp) apex:poja) jo) =+ :-(parsed=(rash q:(need r.resp) apex:poja) jo)
~& parsed
=+ :- status=(need ((ot status/so ~) parsed)) =+ :- status=(need ((ot status/so ~) parsed))
lin=(need ((ot 'selfLink'^so ~) parsed)) lin=(need ((ot 'selfLink'^so ~) parsed))
=+ link=(scot %uv lin) =+ link=(scot %uv lin)
@ -382,13 +420,16 @@ $% [%diff %json json]
[ost %wait `path`[%check-status link ins-img ~] `@da`(add ~s3 now)]~ :: refesh every 10 sec [ost %wait `path`[%check-status link ins-img ~] `@da`(add ~s3 now)]~ :: refesh every 10 sec
:: ::
++ create-gce ++ create-gce
|= [name=@t snap=@t] |= name=@t ::snap=@t]
=+ ^= image
"https://www.googleapis.com/compute/v1/projects/debian-cloud/global/".
"images/backports-debian-7-wheezy-v20150603"
=+ src=(cat 3 'compute/v1/projects/urbcloud/zones/us-central1-a/disks/' name) =+ src=(cat 3 'compute/v1/projects/urbcloud/zones/us-central1-a/disks/' name)
=+ ^- body=json =+ ^- body=json
%- jobe %- jobe
:~ name/s/name 'machineType'^s/'zones/us-central1-a/machineTypes/n1-standard-1' :~ name/s/name 'machineType'^s/'zones/us-central1-a/machineTypes/n1-standard-1'
:- %disks :- %a :_ ~ :- %disks :- %a :_ ~
(jobe boot/b/%.y type/s/'persistent' source/s/src ~) ^- json (jobe 'initializeParams'^`json`(jobe 'sourceImage'^s/(crip image) ~) ~) ::boot/b/%.y type/s/'persistent' source/s/src ~)
:- 'networkInterfaces' :- %a :_ ~ :- 'networkInterfaces' :- %a :_ ~
(joba 'network' `json`[%s 'global/networks/default']) (joba 'network' `json`[%s 'global/networks/default'])
== ==
@ -538,18 +579,12 @@ $% [%diff %json json]
|= [pax=path resp=httr] |= [pax=path resp=httr]
=+ parsed=(rash q:(need r.resp) apex:poja) =+ parsed=(rash q:(need r.resp) apex:poja)
~| crashed-do-images/parsed ~| crashed-do-images/parsed
=+ imgz=(need ((ot images/(ar some) ~):jo parsed)) =+ imgz=(need ((ot images/(ar (ot [name/so distribution/so id/no ~])) ~):jo parsed))
=+ ^- images=(list ,[[@t @t] image]) =+ ^- images=(list ,[[@t @t] image])
%+ turn imgz %+ turn imgz
|= im=json |= [name=@t dist=@t id=@t]
=< [[name %do] .] =+ nom=(cat 3 name dist)
^- image [[%do nom] `image`[%do nom id]]
:- %do
%- need
%. im
=+ jo
%- ot
[name/so id/no ~]
=. images.vat =. images.vat
%- mo %- mo
%+ weld images %+ weld images
@ -558,6 +593,14 @@ $% [%diff %json json]
:_ +>.$ ~ :_ +>.$ ~
::=. ::=.
:: ::
++ thou-do
|= [pax=path resp=httr]
~& resp
:_ +>.$ ~
++ thou-create
|= [pax=path resp=httr]
~& resp
:_ +>.$ ~
++ thou ++ thou
|= [pour-path=path resp=httr] |= [pour-path=path resp=httr]
^- [(list move) _+>.$] ^- [(list move) _+>.$]
@ -566,10 +609,7 @@ $% [%diff %json json]
(receive-auth +.pour-path resp) (receive-auth +.pour-path resp)
:: ::
$? $?
%delete %reboot %'power_cycle' %shutdown %'power_off' %create-do %create-gce
%'power_on' %'password_reset' %'enable_ipv6' %'enable_private_networking'
%snapshot %upgrade :: add retrieve droplet action
%create-do %create-gce %do-start %do-stop %do-reboot %do-delete
== ==
:_ +>.$ ~ :_ +>.$ ~
:: ::
@ -604,3 +644,4 @@ $% [%diff %json json]
=+ mez=[%talk-command [%publish `(list thought)`spchz]] =+ mez=[%talk-command [%publish `(list thought)`spchz]]
[ost %send /pub [our %talk] %poke mez] [ost %send /pub [our %talk] %poke mez]
-- --

16
base/mar/cloud-auth.hoon Normal file
View File

@ -0,0 +1,16 @@
:: this mark is used to receive incoming oauth2 tokens that we use to poke our %gall server
::
:::: /hook/door/do-auth/mar
::
/? 310
!:
|_ cod=cord
::
++ grab :: converter arm
|%
++ noun ,@t :: clam from noun
++ json (cork (ot authcode/so platform/so ~):jo need) :: (need (so:jo jon))
--
--

View File

@ -0,0 +1,9 @@
!:
|_ cod=cord
::
++ grab :: converter am
|%
++ noun ,@t :: clam from noun
++ json (cork (ot secret/so platform/so ~):jo need) :: (need (so:jo jon))
--
--

View File

@ -24,19 +24,18 @@ function HashToJSON() {
DOControls = React.createClass({ DOControls = React.createClass({
createDroplet: function(){ createDroplet: function(){
urb.send({appl: "cloud", urb.send({appl: "cloud",
data: { mark: "json",
action:'create-do', data: {'create-do':{
name:$('#name').val(), name:$('#name').val(),
region:$('#region').val(), region:$('#region').val(),
size:$('#size').val(), size:$('#size').val(),
image:$('#image').val(), image:$('#image').val(),
ssh:[], // $('#ssh').val()] ssh:[], // $('#ssh').val()]
backups:null,//$('#backups').val(), backups:null,//$('#backups').val(),
ipv6:null,//$('#ipv6').val(), ipv6:null,//$('#ipv6').val(),
priv_networking:null,//$('#priv-networking').val(), priv_networking:null,//$('#priv-networking').val(),
user_data:null//$('#user-data').val() user_data:null//$('#user-data').val()
}, }}})
mark: "json"})
}, },
render: function(){ render: function(){
@ -73,24 +72,25 @@ GCEControls = React.createClass({
createDroplet: function(){ createDroplet: function(){
urb.send({ urb.send({
appl: 'cloud', appl: 'cloud',
data: {action:'create-gce', mark: 'json',
data: {'create-gce':{
// project:$('#project').val(), // project:$('#project').val(),
// zone:$('#zone').val(), // zone:$('#zone').val(),
// name:$('#gname').val(), // name:$('#gname').val(),
// machine_type:$('#machine_type').val() / // machine_type:$('#machine_type').val() /
}, }}})
mark: 'json'})
}, },
createDisk: function(){ createDisk: function(){
urb.send({ urb.send({
appl: 'cloud', appl: 'cloud',
data: {action:'create-gce', mark: 'json',
data: {'create-gce':{
snap:$('#gsnap').val(), snap:$('#gsnap').val(),
number:$('#number').val(), number:parseInt($('#number').val()),
name:$('#gcpName').val(), name:$('#gcpName').val(),
instance_img:$('#instance_image').val()}, instance_img:$('#instance_image').val()
mark: 'json'}) }}})
}, },
render: function(){ render: function(){
@ -118,30 +118,32 @@ GCEControls = React.createClass({
}) })
Droplet = React.createClass({ Droplet = React.createClass({
dropletAction:function(id, action){ dropletAction: function(act){
urb.send({ return function(){
appl:"cloud", var action = {act:{}, id:this.props.id, name:this.props.name}
data: {action:action, switch(act){
id:id}}) case "snapshot":
action.act[act] = this.refs.snapname.getDOMNode().value
break; default:
action.act[act] = null
}
urb.send({appl: "cloud", data: {action:action}})}
}, },
render: function() { render: function() {
var $this = this //local var, else it always points at second var $this = this //local var, else it always points at second
var acts = ["start","stop","reboot","delete"] var acts = ["start","stop","reboot","delete","snapshot"]
var buttons = []; var buttons = [];
var buttons = acts.map(function(act){ var buttons = acts.map(function(act){ return b({onClick:$this.dropletAction(act).bind($this)}, act)})
return b({onClick:function(){
$this.dropletAction($this.props.id, act)
}}, act)
})
kay = Object.keys(this.props) kay = Object.keys(this.props)
kay = kay.filter(function(b){return b!="children"}) // XX individually adress props kay = kay.filter(function(b){return b!="children"}) // XX individually adress props
return div({}, return div({},[
buttons, buttons,
input({ref:'snapname',placeholder:'Name of Snapshot'}),
table({}, table({},
tr({},kay.map(function(k){return th({},k)})), tr({},kay.map(function(k){return th({},k)})),
tr({},kay.map(function(k){return td({},JSON.stringify($this.props[k]))}))), tr({},kay.map(function(k){return td({},JSON.stringify($this.props[k]))}))),
hr()) hr()])
} }
}) })
@ -181,10 +183,16 @@ Page = recl({
render: function(){ render: function(){
var drops = [], imgs = []
if(this.props.instances) drops = this.props.instances.map(Droplet)
if(this.props.images) imgs = this.props.images.map(
function(i){return div({},i.name)}
)
return (div({}, return (div({},
DOControls({handleClick:this.handleClick,sendSecret:this.sendSecret}), DOControls({handleClick:this.handleClick,sendSecret:this.sendSecret}),
GCEControls({handleClick:this.handleClick,sendSecret:this.sendSecret}), GCEControls({handleClick:this.handleClick,sendSecret:this.sendSecret}),
this.props.droplets.map(Droplet) drops,
imgs
)) ))
} }
}) })
@ -194,6 +202,6 @@ authcode.gce = hash.access_token
mounted = React.render(Page({droplets:[]}), $("#container")[0]) mounted = React.render(Page({droplets:[]}), $("#container")[0])
urb.bind("/", function(err,d) { urb.bind("/", function(err,d) {
mounted.setProps({droplets:d.data}) mounted.setProps(d.data)
return}) return})