Skip to content

Commit 13d1774

Browse files
committed
cmd/rofl/deploy: Fix --provider behaviour
1 parent e76b4e9 commit 13d1774

3 files changed

Lines changed: 26 additions & 12 deletions

File tree

build/rofl/provider/defaults.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
package provider
22

3-
// DefaultSchedulerApp contains the default scheduler app IDs for each network/paratime.
4-
var DefaultSchedulerApp = map[string]map[string]string{
5-
"testnet": {
6-
"sapphire": "rofl1qrqw99h0f7az3hwt2cl7yeew3wtz0fxunu7luyfg",
3+
import "github.com/oasisprotocol/oasis-sdk/client-sdk/go/config"
4+
5+
// DefaultRoflServices contains ROFL default services per network/ParaTime.
6+
type DefaultRoflServices struct {
7+
Scheduler string
8+
Provider string
9+
}
10+
11+
// DefaultSchedulerApp contains the ROFL services defaults for specific networks/ParaTimes.
12+
var DefaultSchedulerApp = map[string]DefaultRoflServices{
13+
config.DefaultNetworks.All["testnet"].ParaTimes.All["sapphire"].ID: {
14+
Scheduler: "rofl1qrqw99h0f7az3hwt2cl7yeew3wtz0fxunu7luyfg",
15+
Provider: "oasis1qp2ens0hsp7gh23wajxa4hpetkdek3swyyulyrmz",
716
},
817
}

cmd/rofl/deploy.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/oasisprotocol/oasis-core/go/common/cbor"
1818
"github.com/oasisprotocol/oasis-core/go/common/sgx"
1919
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/client"
20+
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/config"
2021
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/connection"
2122
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/modules/rofl"
2223
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/modules/roflmarket"
@@ -90,16 +91,20 @@ var (
9091

9192
switch machine.Provider {
9293
case "":
93-
// Not yet set, require the provider to be specified.
94+
// Not yet set, obtain a new machine from the provider.
9495
if deployProvider == "" {
95-
cobra.CheckErr(fmt.Sprintf("Provider not configured for deployment '%s' machine '%s'. Please specify --provider.", deploymentName, deployMachine))
96+
if npa.ParaTime.ID == config.DefaultNetworks.All["testnet"].ParaTimes.All["sapphire"].ID {
97+
deployProvider = provider.DefaultSchedulerApp[npa.ParaTime.ID].Provider
98+
} else {
99+
cobra.CheckErr(fmt.Sprintf("Provider not configured for deployment '%s' machine '%s'. Please specify --provider.", deploymentName, deployMachine))
100+
}
96101
}
97102

98103
machine.Provider = deployProvider
99104
default:
100-
// Already set, require the provider to be omitted.
101-
if deployProvider != "" {
102-
cobra.CheckErr(fmt.Sprintf("Provider already configured for deployment '%s' machine '%s'. Omit --provider.", deploymentName, deployMachine))
105+
// Already set, require the provider to be omitted or equal.
106+
if deployProvider != "" && deployProvider != machine.Provider {
107+
cobra.CheckErr(fmt.Sprintf("Provider '%s' conflicts with existing provider '%s' for deployment '%s' machine '%s'. Omit --provider.", deployProvider, machine.Provider, deploymentName, deployMachine))
103108
}
104109
}
105110

@@ -345,7 +350,7 @@ func showProviderOffer(offer *roflmarket.Offer) {
345350
func init() {
346351
providerFlags := flag.NewFlagSet("", flag.ContinueOnError)
347352
// Default to Testnet playground provider.
348-
providerFlags.StringVar(&deployProvider, "provider", "oasis1qp2ens0hsp7gh23wajxa4hpetkdek3swyyulyrmz", "set the provider address")
353+
providerFlags.StringVar(&deployProvider, "provider", "", "set the provider address")
349354
providerFlags.StringVar(&deployOffer, "offer", "", "set the provider's offer identifier")
350355
providerFlags.StringVar(&deployMachine, "machine", buildRofl.DefaultMachineName, "machine to deploy into")
351356
providerFlags.StringVar(&deployTerm, "term", "", "term to pay for in advance")

cmd/rofl/provider/mgmt.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ var (
3636
}
3737

3838
var schedulerApp rofl.AppID
39-
rawSchedulerApp, ok := provider.DefaultSchedulerApp[npa.NetworkName][npa.ParaTimeName]
40-
if ok {
39+
rawSchedulerApp := provider.DefaultSchedulerApp[npa.ParaTime.ID].Scheduler
40+
if rawSchedulerApp != "" {
4141
err := schedulerApp.UnmarshalText([]byte(rawSchedulerApp))
4242
cobra.CheckErr(err)
4343
}

0 commit comments

Comments
 (0)