Skip to content

Commit 850aae0

Browse files
committed
cmd/rofl/deploy: Show instance expiration date and top-up
1 parent 0d7d935 commit 850aae0

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

cmd/rofl/deploy.go

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ var (
150150
},
151151
}
152152

153-
obtainMachine := func() (*buildRofl.Machine, error) {
153+
obtainMachine := func() (*buildRofl.Machine, *roflmarket.Instance, error) {
154154
if deployOffer != "" {
155155
machine.Offer = deployOffer
156156
}
@@ -168,15 +168,15 @@ var (
168168
}
169169
if offer == nil {
170170
showProviderOffers(ctx, npa, conn, *providerAddr)
171-
return nil, fmt.Errorf("offer '%s' not found for provider '%s'", machine.Offer, providerAddr)
171+
return nil, nil, fmt.Errorf("offer '%s' not found for provider '%s'", machine.Offer, providerAddr)
172172
}
173173

174174
fmt.Printf("Taking offer:\n")
175175
showProviderOffer(ctx, offer)
176176

177177
term := detectTerm(offer)
178178
if deployTermCount < 1 {
179-
return nil, fmt.Errorf("number of terms must be at least 1")
179+
return nil, nil, fmt.Errorf("number of terms must be at least 1")
180180
}
181181

182182
// Calculate total price.
@@ -206,23 +206,27 @@ var (
206206

207207
var machineID roflmarket.InstanceID
208208
if !common.BroadcastOrExportTransaction(ctx, npa, conn, sigTx, meta, &machineID) {
209-
return nil, fmt.Errorf("broadcast transaction failed")
209+
return nil, nil, fmt.Errorf("broadcast transaction failed")
210210
}
211211

212212
rawMachineID, _ := machineID.MarshalText()
213-
cobra.CheckErr(err)
214213
machine.ID = string(rawMachineID)
215214
deployment.Machines[deployMachine] = machine
216215

217216
fmt.Printf("Created machine: %s\n", machine.ID)
218-
return machine, nil
217+
218+
var insDsc *roflmarket.Instance
219+
insDsc, err = conn.Runtime(npa.ParaTime).ROFLMarket.Instance(ctx, client.RoundLatest, *providerAddr, machineID)
220+
cobra.CheckErr(err)
221+
222+
return machine, insDsc, nil
219223
}
220224

221-
doDeployMachine := func(machine *buildRofl.Machine) error {
225+
doDeployMachine := func(machine *buildRofl.Machine) (*roflmarket.Instance, error) {
222226
// Deploy into existing machine.
223227
var machineID roflmarket.InstanceID
224228
if err = machineID.UnmarshalText([]byte(machine.ID)); err != nil {
225-
return fmt.Errorf("malformed machine ID: %w", err)
229+
return nil, fmt.Errorf("malformed machine ID: %w", err)
226230
}
227231

228232
fmt.Printf("Deploying into existing machine: %s\n", machine.ID)
@@ -237,8 +241,8 @@ var (
237241
if deployReplaceMachine {
238242
fmt.Printf("Machine instance not found. Obtaining new one...")
239243
machine.ID = ""
240-
_, err = obtainMachine()
241-
return err
244+
_, _, err = obtainMachine()
245+
return nil, err
242246
}
243247

244248
cobra.CheckErr("Machine instance not found.\nTip: If your instance expired, run this command with --replace-machine flag to replace it with a new machine.")
@@ -248,7 +252,7 @@ var (
248252
if insDsc.Deployment != nil && insDsc.Deployment.AppID != machineDeployment.AppID && !deployForce {
249253
fmt.Printf("Machine already contains a deployment of ROFL app '%s'.\n", insDsc.Deployment.AppID)
250254
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")
255+
return nil, fmt.Errorf("refusing to change existing ROFL app, use --force to override")
252256
}
253257

254258
// Prepare transaction.
@@ -269,23 +273,26 @@ var (
269273
cobra.CheckErr(err)
270274

271275
if !common.BroadcastOrExportTransaction(ctx, npa, conn, sigTx, meta, nil) {
272-
return fmt.Errorf("broadcast transaction failed")
276+
return nil, fmt.Errorf("broadcast transaction failed")
273277
}
274278

275-
return nil
279+
return insDsc, nil
276280
}
277281

282+
var insDsc *roflmarket.Instance
278283
if machine.ID == "" {
279284
// When machine is not set, we need to obtain one.
280285
fmt.Printf("No pre-existing machine configured, creating a new one...\n")
281-
machine, err = obtainMachine()
286+
machine, insDsc, err = obtainMachine()
282287
cobra.CheckErr(err)
283288
} else {
284-
cobra.CheckErr(doDeployMachine(machine))
289+
insDsc, err = doDeployMachine(machine)
290+
cobra.CheckErr(err)
285291
}
286292

287293
fmt.Printf("Deployment into machine scheduled.\n")
288-
fmt.Printf("Use `oasis rofl machine show` to see status.\n")
294+
fmt.Printf("This machine expires on %s. Use `oasis rofl machine top-up` to extend it.\n", time.Unix(int64(insDsc.PaidUntil), 0))
295+
fmt.Printf("Use `oasis rofl machine show` to check status.\n")
289296

290297
if err = manifest.Save(); err != nil {
291298
cobra.CheckErr(fmt.Errorf("failed to update manifest: %w", err))

examples/rofl/deploy.out.static

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ Transaction hash: bce96976f38485546b5950f8b2a7f9b7c43b9656935cc472a90680187469f4
4141
Execution successful.
4242
Created machine: 0000000000000000
4343
Deployment into machine scheduled.
44-
Use `oasis rofl machine show` to see status.
44+
This machine expires on 2025-08-07 12:35:47 +0200 CEST. Use `oasis rofl machine top-up` to extend it.
45+
Use `oasis rofl machine show` to check status.

0 commit comments

Comments
 (0)