create disk, check status

This commit is contained in:
Henry Ault 2015-05-25 19:28:08 -07:00
parent ed2ba93eb2
commit 8918885dd5
3 changed files with 128 additions and 27 deletions

View File

@ -40,7 +40,7 @@ private-networking=(unit ,?) user-data=(unit ,@t)
== ==
++ create-req-gce ,[project=@t zone=@t name=@t machine-type=@t] ++ create-req-gce ,[project=@t zone=@t name=@t machine-type=@t]
++ axle ++ axle
$: auth=[do=keys gcp=keys] toke=[do=tokens gcp=tokens] $: auth=[do=keys gce=keys] toke=[do=tokens gce=tokens]
drops=(list droplet) drops=(list droplet)
== ==
++ keys ,[authc=(unit ,@t) client-secret=(unit ,@t)] ++ keys ,[authc=(unit ,@t) client-secret=(unit ,@t)]
@ -141,7 +141,7 @@ $% [%diff %json json]
!: !:
|_ [hid=hide vat=axle] |_ [hid=hide vat=axle]
:: ::
::++ prep ,_`. ++ prep ,_`.
::: :::
++ spam ++ spam
|= jon=json |= jon=json
@ -194,9 +194,10 @@ $% [%diff %json json]
[~ cde] [~ cde]
:_ +>.$ :_ +>.$
~ ~
=. access.gcp.toke.vat =. access.gce.toke.vat
cde cde
:_ +>.$ :_ +>.$
:- (list-droplets-gce ost)
~ ~
:: ::
++ poke-cloud-secret ++ poke-cloud-secret
@ -216,7 +217,7 @@ $% [%diff %json json]
[%post ~] [%post ~]
:- ~ `quay`['client_secret'^secret (auth-queries (need authc.do.auth.vat))] :- ~ `quay`['client_secret'^secret (auth-queries (need authc.do.auth.vat))]
%gce %gce
=. client-secret.gcp.auth.vat =. client-secret.gce.auth.vat
[~ secret] [~ secret]
:_ +>.$ :_ +>.$
:_ ~ :_ ~
@ -224,7 +225,7 @@ $% [%diff %json json]
:^ ~[%google %cloud] `path`/v1/oauth/token :^ ~[%google %cloud] `path`/v1/oauth/token
[%post ~] [%post ~]
:- (mo ['Content-Type' 'application/json' ~] ['Authorization' (cat 3 'Bearer ' access.do.toke.vat) ~] ~) :- (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))] `quay`['client_secret'^secret %'access_token'^(need authc.gce.auth.vat) ~] ::(auth-queries (need authc.gcp.auth.vat))]
== ==
:: ::
++ receive-auth ++ receive-auth
@ -240,7 +241,7 @@ $% [%diff %json json]
refresh.do.toke.vat re refresh.do.toke.vat re
== ==
:_ +>.$ :_ +>.$
:~ (list-droplets ost) :~ (list-droplets-do ost)
(publish ost our.hid [%lin & 'successfully authenticated']~) (publish ost our.hid [%lin & 'successfully authenticated']~)
== ==
%auth-gce %auth-gce
@ -257,7 +258,7 @@ $% [%diff %json json]
?+ do !! ?+ do !!
%list %list
:_ +>.$ :_ +>.$
:- (list-droplets ost) :- (list-droplets-do ost)
~ ~
:: ::
%create-do %create-do
@ -273,9 +274,16 @@ $% [%diff %json json]
== ==
:- (create-do ost deets) :- (create-do ost deets)
~ ~
::
%create-gce-disk
=+ name=(need ((ot name/so ~):jo act))
=+ snap=(need ((ot snap/so ~):jo act))
:_ +>.$
:- (create-gce-disk ost name snap)
~
:: ::
%create-gce %create-gce
~& 'chamado'
:_ +>.$ :_ +>.$
=+ ^- deets=create-req-gce =+ ^- deets=create-req-gce
%- need %- need
@ -284,7 +292,6 @@ $% [%diff %json json]
%- ot %- ot
:~ project/so zone/so name/so %'machine_type'^so :~ project/so zone/so name/so %'machine_type'^so
== ==
~& 'dois'
:- (create-gce ost deets) :- (create-gce ost deets)
~ ~
:: ::
@ -317,10 +324,21 @@ $% [%diff %json json]
== ==
req req
++ list-droplets ++ list-droplets-gce
|= os=bone |= os=bone
=+ ^= lis =+ ^= lis
:~ os /list :* os /list-gce
~[%googleapis %www] /compute/v1/projects/urbcloud/zones/['us-central1-a']/'instances'
%get ~
^- quay
[%'access_token' access.gce.toke.vat]~
==
(httpreq lis)
++ list-droplets-do
|= os=bone
=+ ^= lis
:~ os /list-do
~[%digitalocean %api] /v2/droplets ~[%digitalocean %api] /v2/droplets
%get %get
(mo ['Content-Type' 'application/json' ~] ['Authorization' (cat 3 'Bearer ' access.do.toke.vat) ~] ~) (mo ['Content-Type' 'application/json' ~] ['Authorization' (cat 3 'Bearer ' access.do.toke.vat) ~] ~)
@ -353,7 +371,7 @@ $% [%diff %json json]
=+ buf=`@da`(add ~s10 lat.hid) =+ buf=`@da`(add ~s10 lat.hid)
:_ +>.$ :_ +>.$
:_ (spam (state-to-json drops.vat)) :_ (spam (state-to-json drops.vat))
[ost %wait /refresh buf] [ost %wait /refresh-do buf]
:: ::
++ create-do ++ create-do
|= [os=bone create-req-do] |= [os=bone create-req-do]
@ -367,51 +385,111 @@ $% [%diff %json json]
os /create-do os /create-do
~[%digitalocean %api] /v2/droplets ~[%digitalocean %api] /v2/droplets
[%post body] [%post body]
%^ mo ['Content-Type' 'application/json' ~] %^ mo ['Content-Type' 'application/json; charset=utf-8' ~]
['Authorization' (cat 3 'Bearer ' access.do.toke.vat) ~] ['Authorization' (cat 3 'Bearer ' access.do.toke.vat) ~]
~ ~
~ ~
== ==
::++ batch-request
::|= [os=bone name=@t number=@ud snap=@t]
::(list httr) ^- httr
++ create-gce-disk
|= [os=bone name=@t snap=@t] :: num=(unit ,@u)
:: =. name ?~(num name ...
=+ ^- body=json
(jobe name/s/name %'sourceSnapshot'^s/'compute/v1/projects/urbcloud/global/snapshots/snapshot-1' ~) ::^so/snap ~)
%- httpreq
:* os /create-gce-disk
~['googleapis' 'www'] /compute/v1/projects/urbcloud/zones/us-central1-b/disks
[%post body]
%^ mo ['Content-Type' 'application/json' ~]
['Authorization' (cat 3 'Bearer ' access.gce.toke.vat) ~]
~
~
==
::++ receive-gce-disk
:: |= [os=bone resp=httr]
:: ~& insert/resp
:: =+ hcode=p.resp
:: ?: =('200' hcode)
:: ~| 'did not receive 200' !!
:: =+ parsed=(rash q:(need r.resp) apex:poja)
:: =+ link=(need ((ot 'targetLink'^(su auri:epur) ~):jo parsed))
:: :_ +>.$
:: :_(~ (ask-disk-status os link))
++ ask-disk-status
|= [os=bone pax=path] ^- move
=+ safe=(slav %uv ?~(pax !! -.pax))
=+ link=(need (epur ?~(pax !! safe)))
=. r.link ['access_token'^access.gce.toke.vat r.link]
:^ os %them `wire`/disk-status
`(unit hiss)`[~ [link [%get ~ ~]]]
++ disk-status ::receive
|= [ost=bone resp=httr]
^- [(list move) _+>.$]
~& resp
=+ parsed=(rash q:(need r.resp) apex:poja)
:: =+ =< [status link]=.
:: %- need
=+ jo
=+ :- status=(need ((ot status/so ~) parsed))
link=(scot %uv (need ((ot 'selfLink'^so ~) parsed)))
:: ?=(%running....)
~& status/status
:_ +>.$
[ost %wait `path`[%check-status link ~] `@da`(add ~s3 lat.hid)]~ :: refresh every 10 sec
++ create-gce ++ create-gce
|= [os=bone create-req-gce] |= [os=bone create-req-gce]
~& 'called' =+ src='compute/v1/projects/urbcloud/zones/us-central1-b/disks/disk-1'
=+ ^- body=json =+ ^- body=json
%- jobe %- jobe
~[name/s/name %'machine-type'^s/machine-type] :~ name/s/'name-provided' 'machineType'^s/'zones/us-central1-b/machineTypes/n1-standard-1'
~& body :- %disks :- %a :_ ~
=+ ^= req (jobe boot/b/%.y type/s/'persistent' source/s/src ~)
:- 'networkInterfaces' :- %a :_ ~
(joba 'network' `json`[%s 'global/networks/default'])
==
%- httpreq %- httpreq
:* `bone`os `path`/create-gce :* `bone`os `path`/create-gce
`(list cord)`~['googleapis' 'www'] `path`/v1/[project]/zones/[zone]/'instances' `(list cord)`~['googleapis' 'www'] `path`/compute/v1/projects/urbcloud/zones/us-central1-b/'instances'
~& 'here'
[%post `json`body] [%post `json`body]
~& 'here'
%^ mo ['Content-Type' 'application/json' ~] %^ mo ['Content-Type' 'application/json' ~]
['Authorization' (cat 3 'Bearer ' access.do.toke.vat) ~] ['Authorization' (cat 3 'Bearer ' access.gce.toke.vat) ~]
~ ~
`quay`~ `quay`[%key access.gce.toke.vat]~
== ==
~& req req
++ wake ++ wake
|= [[ost=bone him=ship pour-path=path] ~] |= [[ost=bone him=ship pour-path=path] ~]
?+ -.pour-path !! ?+ -.pour-path !!
%refresh %refresh-do
:_ +>.$ :_ +>.$
[(list-droplets ost)]~ [(list-droplets-do ost)]~
%check-status
:_ +>.$
[(ask-disk-status ost +.pour-path)]~
== ==
++ thou ++ thou
|= [[ost=bone him=ship pour-path=path] resp=httr] |= [[ost=bone him=ship pour-path=path] resp=httr]
^- [(list move) _+>.$] ^- [(list move) _+>.$]
?+ -.pour-path !! ?+ -.pour-path ~& pour-path !!
%auth-do %auth-do
(receive-auth ost -.pour-path resp) (receive-auth ost -.pour-path resp)
:: ::
%auth-gce %auth-gce
(receive-auth ost -.pour-path resp) (receive-auth ost -.pour-path resp)
:: ::
%list %list-do
(receive-list ost -.pour-path resp) (receive-list ost -.pour-path resp)
%list-gce
~& resp
:_ +>.$
~
:: ::
$? $?
%delete %reboot %'power_cycle' %shutdown %'power_off' %delete %reboot %'power_cycle' %shutdown %'power_off'
@ -421,6 +499,12 @@ $% [%diff %json json]
== ==
~& resp ~& resp
:_ +>.$ ~ :_ +>.$ ~
::
?(%create-gce-disk %disk-status)
(disk-status ost resp)
::
%check-status
:_ +>.$ ~[(ask-disk-status ost +.pour-path)]
:: ::
%pub %pub
:_ +>.$ ~ :_ +>.$ ~

View File

@ -23,6 +23,7 @@
;body ;body
;* =+ d=?~(do ~ (trip u.do)) ;* =+ d=?~(do ~ (trip u.do))
=+ g=?~(g ~ (trip u.g)) =+ g=?~(g ~ (trip u.g))
~& d
:_ ~ :_ ~
;script: authcode='{?~(d g d)}'; console.log(authcode) ;script: authcode='{?~(d g d)}'; console.log(authcode)
;div#container; ;div#container;

View File

@ -70,10 +70,26 @@ GCEControls = React.createClass({
mark: 'json'}) mark: 'json'})
}, },
createDisk: function(){
urb.send({
appl: 'cloud',
data: {action:'create-gce-disk',
snap:$('#gsnap').val(),
number:$('#number').val(),
name:$('#gcpName').val()},
mark: 'json'})
},
render: function(){ render: function(){
ghref = "https://accounts.google.com/o/oauth2/auth?response_type=token&scope=https://www.googleapis.com/auth/compute&redirect_uri=http://localhost:8443/home/pub/cloud/fab&client_id=719712694742-6htfj2t9s1j2jid92rc4dfq9psrr9qpo.apps.googleusercontent.com" ghref = "https://accounts.google.com/o/oauth2/auth?response_type=token&scope=https://www.googleapis.com/auth/compute&redirect_uri=http://localhost:8443/home/pub/cloud/fab&client_id=719712694742-6htfj2t9s1j2jid92rc4dfq9psrr9qpo.apps.googleusercontent.com"
return( return(
div({}, [ div({}, [
div({}, [
b({onClick:this.createDisk}, 'Create Disk From Image'),
input({id:'gcpName',placeholder:'Name for GCE Disk and Instance'}),
input({id:'number',placeholder:'Number of instances'}),
input({id:'gsnap',placeholder:'Snapshot'})
]),
div({}, [ div({}, [
a({href:ghref},"Get Google Authcode"), a({href:ghref},"Get Google Authcode"),
b({onClick:this.props.handleClick('gce')}, "Send Google Authcode") b({onClick:this.props.handleClick('gce')}, "Send Google Authcode")