3838 deployProvider string
3939 deployOffer string
4040 deployMachine string
41- deployTerm string
42- deployTermCount uint64
4341 deployForce bool
4442 deployShowOffers bool
4543 deployReplaceMachine bool
@@ -150,7 +148,7 @@ var (
150148 },
151149 }
152150
153- obtainMachine := func () (* buildRofl.Machine , error ) {
151+ obtainMachine := func () (* buildRofl.Machine , * roflmarket. Instance , error ) {
154152 if deployOffer != "" {
155153 machine .Offer = deployOffer
156154 }
@@ -168,19 +166,19 @@ var (
168166 }
169167 if offer == nil {
170168 showProviderOffers (ctx , npa , conn , * providerAddr )
171- return nil , fmt .Errorf ("offer '%s' not found for provider '%s'" , machine .Offer , providerAddr )
169+ return nil , nil , fmt .Errorf ("offer '%s' not found for provider '%s'" , machine .Offer , providerAddr )
172170 }
173171
174172 fmt .Printf ("Taking offer:\n " )
175173 showProviderOffer (ctx , offer )
176174
177175 term := detectTerm (offer )
178- if deployTermCount < 1 {
179- return nil , fmt .Errorf ("number of terms must be at least 1" )
176+ if roflCommon . TermCount < 1 {
177+ return nil , nil , fmt .Errorf ("number of terms must be at least 1" )
180178 }
181179
182180 // Calculate total price.
183- qTermCount := quantity .NewFromUint64 (deployTermCount )
181+ qTermCount := quantity .NewFromUint64 (roflCommon . TermCount )
184182 totalPrice , ok := offer .Payment .Native .Terms [term ]
185183 if ! ok {
186184 cobra .CheckErr ("internal error: previously selected term not found in offer terms" )
@@ -197,7 +195,7 @@ var (
197195 Offer : offer .ID ,
198196 Deployment : & machineDeployment ,
199197 Term : term ,
200- TermCount : deployTermCount ,
198+ TermCount : roflCommon . TermCount ,
201199 })
202200
203201 var sigTx , meta any
@@ -206,23 +204,27 @@ var (
206204
207205 var machineID roflmarket.InstanceID
208206 if ! common .BroadcastOrExportTransaction (ctx , npa , conn , sigTx , meta , & machineID ) {
209- return nil , fmt .Errorf ("broadcast transaction failed" )
207+ return nil , nil , fmt .Errorf ("broadcast transaction failed" )
210208 }
211209
212210 rawMachineID , _ := machineID .MarshalText ()
213- cobra .CheckErr (err )
214211 machine .ID = string (rawMachineID )
215212 deployment .Machines [deployMachine ] = machine
216213
217214 fmt .Printf ("Created machine: %s\n " , machine .ID )
218- return machine , nil
215+
216+ var insDsc * roflmarket.Instance
217+ insDsc , err = conn .Runtime (npa .ParaTime ).ROFLMarket .Instance (ctx , client .RoundLatest , * providerAddr , machineID )
218+ cobra .CheckErr (err )
219+
220+ return machine , insDsc , nil
219221 }
220222
221- doDeployMachine := func (machine * buildRofl.Machine ) error {
223+ doDeployMachine := func (machine * buildRofl.Machine ) ( * roflmarket. Instance , error ) {
222224 // Deploy into existing machine.
223225 var machineID roflmarket.InstanceID
224226 if err = machineID .UnmarshalText ([]byte (machine .ID )); err != nil {
225- return fmt .Errorf ("malformed machine ID: %w" , err )
227+ return nil , fmt .Errorf ("malformed machine ID: %w" , err )
226228 }
227229
228230 fmt .Printf ("Deploying into existing machine: %s\n " , machine .ID )
@@ -237,8 +239,8 @@ var (
237239 if deployReplaceMachine {
238240 fmt .Printf ("Machine instance not found. Obtaining new one..." )
239241 machine .ID = ""
240- _ , err = obtainMachine ()
241- return err
242+ _ , _ , err = obtainMachine ()
243+ return nil , err
242244 }
243245
244246 cobra .CheckErr ("Machine instance not found.\n Tip: If your instance expired, run this command with --replace-machine flag to replace it with a new machine." )
@@ -248,7 +250,7 @@ var (
248250 if insDsc .Deployment != nil && insDsc .Deployment .AppID != machineDeployment .AppID && ! deployForce {
249251 fmt .Printf ("Machine already contains a deployment of ROFL app '%s'.\n " , insDsc .Deployment .AppID )
250252 fmt .Printf ("You are trying to replace it with ROFL app '%s'.\n " , machineDeployment .AppID )
251- return fmt .Errorf ("refusing to change existing ROFL app, use --force to override" )
253+ return nil , fmt .Errorf ("refusing to change existing ROFL app, use --force to override" )
252254 }
253255
254256 // Prepare transaction.
@@ -269,23 +271,26 @@ var (
269271 cobra .CheckErr (err )
270272
271273 if ! common .BroadcastOrExportTransaction (ctx , npa , conn , sigTx , meta , nil ) {
272- return fmt .Errorf ("broadcast transaction failed" )
274+ return nil , fmt .Errorf ("broadcast transaction failed" )
273275 }
274276
275- return nil
277+ return insDsc , nil
276278 }
277279
280+ var insDsc * roflmarket.Instance
278281 if machine .ID == "" {
279282 // When machine is not set, we need to obtain one.
280283 fmt .Printf ("No pre-existing machine configured, creating a new one...\n " )
281- machine , err = obtainMachine ()
284+ machine , insDsc , err = obtainMachine ()
282285 cobra .CheckErr (err )
283286 } else {
284- cobra .CheckErr (doDeployMachine (machine ))
287+ insDsc , err = doDeployMachine (machine )
288+ cobra .CheckErr (err )
285289 }
286290
287291 fmt .Printf ("Deployment into machine scheduled.\n " )
288- fmt .Printf ("Use `oasis rofl machine show` to see status.\n " )
292+ fmt .Printf ("This machine expires on %s. Use `oasis rofl machine top-up` to extend it.\n " , time .Unix (int64 (insDsc .PaidUntil ), 0 ))
293+ fmt .Printf ("Use `oasis rofl machine show` to check status.\n " )
289294
290295 if err = manifest .Save (); err != nil {
291296 cobra .CheckErr (fmt .Errorf ("failed to update manifest: %w" , err ))
@@ -327,11 +332,11 @@ func detectTerm(offer *roflmarket.Offer) (term roflmarket.Term) {
327332 cobra .CheckErr (fmt .Errorf ("no payment terms available for offer '%s'" , offer .ID ))
328333 }
329334
330- if deployTerm != "" {
335+ if roflCommon . Term != "" {
331336 // Custom deploy term.
332- term = roflCommon .ParseMachineTerm (deployTerm )
337+ term = roflCommon .ParseMachineTerm (roflCommon . Term )
333338 if _ , ok := offer .Payment .Native .Terms [term ]; ! ok {
334- cobra .CheckErr (fmt .Errorf ("term '%s' is not available for offer '%s'" , deployTerm , offer .ID ))
339+ cobra .CheckErr (fmt .Errorf ("term '%s' is not available for offer '%s'" , roflCommon . Term , offer .ID ))
335340 }
336341 return
337342 }
@@ -447,8 +452,6 @@ func init() {
447452 providerFlags .StringVar (& deployProvider , "provider" , "" , "set the provider address" )
448453 providerFlags .StringVar (& deployOffer , "offer" , "" , "set the provider's offer identifier" )
449454 providerFlags .StringVar (& deployMachine , "machine" , buildRofl .DefaultMachineName , "machine to deploy into" )
450- providerFlags .StringVar (& deployTerm , "term" , "" , "term to pay for in advance" )
451- providerFlags .Uint64Var (& deployTermCount , "term-count" , 1 , "number of terms to pay for in advance" )
452455 providerFlags .BoolVar (& deployForce , "force" , false , "force deployment" )
453456 providerFlags .BoolVar (& deployShowOffers , "show-offers" , false , "show all provider offers and quit" )
454457 providerFlags .BoolVar (& deployReplaceMachine , "replace-machine" , false , "rent a new machine if the provided one expired" )
@@ -457,4 +460,5 @@ func init() {
457460 deployCmd .Flags ().AddFlagSet (providerFlags )
458461 deployCmd .Flags ().AddFlagSet (roflCommon .DeploymentFlags )
459462 deployCmd .Flags ().AddFlagSet (roflCommon .WipeFlags )
463+ deployCmd .Flags ().AddFlagSet (roflCommon .TermFlags )
460464}
0 commit comments