diff --git a/cli/cdsctl/worker_model.go b/cli/cdsctl/worker_model.go index d5f4cfefd5..fdc10dfeba 100644 --- a/cli/cdsctl/worker_model.go +++ b/cli/cdsctl/worker_model.go @@ -44,6 +44,53 @@ var workerModelListCmd = cli.Command{ }, } +type workerModelDisplay struct { + Name string `json:"name" cli:"name,key"` + Type string `json:"type" cli:"type"` + Disabled bool `json:"disabled" cli:"disabled"` + Restricted bool `json:"restricted" cli:"restricted"` + NeedRegistration bool `json:"need_registration" cli:"need_registration"` + NbSpawnErr int64 `json:"nb_spawn_err" cli:"nb_spawn_err"` + IsDeprecated bool `json:"is_deprecated" cli:"deprecated"` + IsOfficial bool `json:"is_official" cli:"official"` + Image string `json:"image" cli:"image"` + Flavor string `json:"flavor" cli:"flavor"` +} + +func newWorkerModelDisplay(wm sdk.Model) workerModelDisplay { + name := wm.Name + if wm.Group != nil { + name = fmt.Sprintf("%s/%s", wm.Group.Name, wm.Name) + } else { + name = wm.Name + } + + var image, flavor string + + switch wm.Type { + case sdk.Docker: + image = wm.ModelDocker.Image + case sdk.Openstack, sdk.VSphere: + image = wm.ModelVirtualMachine.Image + flavor = wm.ModelVirtualMachine.Flavor + } + + w := workerModelDisplay{ + Name: name, + Type: wm.Type, + Disabled: wm.Disabled, + Restricted: wm.Restricted, + NeedRegistration: wm.NeedRegistration, + NbSpawnErr: wm.NbSpawnErr, + IsDeprecated: wm.IsDeprecated, + Image: image, + Flavor: flavor, + IsOfficial: wm.IsOfficial, + } + + return w +} + func workerModelListRun(v cli.Values) (cli.ListResult, error) { var err error var workerModels []sdk.Model @@ -63,7 +110,13 @@ func workerModelListRun(v cli.Values) (cli.ListResult, error) { if err != nil { return nil, err } - return cli.AsListResult(workerModels), nil + + wms := make([]workerModelDisplay, len(workerModels)) + for i := range workerModels { + wms[i] = newWorkerModelDisplay(workerModels[i]) + } + + return cli.AsListResult(wms), nil } var workerModelImportCmd = cli.Command{ diff --git a/engine/hatchery/swarm/swarm_util_create_test.go b/engine/hatchery/swarm/swarm_util_create_test.go index 00d464dd1d..823ab33206 100644 --- a/engine/hatchery/swarm/swarm_util_create_test.go +++ b/engine/hatchery/swarm/swarm_util_create_test.go @@ -149,9 +149,7 @@ func TestHatcherySwarm_createAndStartContainer(t *testing.T) { // RegisterOnly = true, this will pull image if image is not found spawnArgs := hatchery.SpawnArguments{ RegisterOnly: true, - Model: &sdk.Model{ - Image: args.image, - }, + Model: &sdk.Model{}, } err := h.createAndStartContainer(context.TODO(), h.dockerClients["default"], args, spawnArgs) require.NoError(t, err) @@ -195,9 +193,7 @@ func TestHatcherySwarm_createAndStartContainerWithMount(t *testing.T) { spawnArgs := hatchery.SpawnArguments{ RegisterOnly: false, - Model: &sdk.Model{ - Image: args.image, - }, + Model: &sdk.Model{}, } err = h.createAndStartContainer(context.TODO(), h.dockerClients["default"], args, spawnArgs) require.NoError(t, err) @@ -230,9 +226,7 @@ func TestHatcherySwarm_createAndStartContainerWithNetwork(t *testing.T) { spawnArgs := hatchery.SpawnArguments{ RegisterOnly: false, - Model: &sdk.Model{ - Image: args.image, - }, + Model: &sdk.Model{}, } err = h.createAndStartContainer(context.TODO(), h.dockerClients["default"], args, spawnArgs) require.NoError(t, err) diff --git a/engine/sql/208_worker_model.sql b/engine/sql/208_worker_model.sql new file mode 100644 index 0000000000..eba0fb0a03 --- /dev/null +++ b/engine/sql/208_worker_model.sql @@ -0,0 +1,7 @@ +-- +migrate Up + +ALTER TABLE "worker_model" DROP COLUMN IF EXISTS image; + +-- +migrate Down + +ALTER TABLE "worker_model" ADD COLUMN IF NOT EXISTS image TEXT; diff --git a/sdk/exportentities/worker_model.go b/sdk/exportentities/worker_model.go index 29285113c6..ac8eb13b5c 100644 --- a/sdk/exportentities/worker_model.go +++ b/sdk/exportentities/worker_model.go @@ -6,24 +6,23 @@ import ( // WorkerModel is the as code format of a worker model type WorkerModel struct { - Name string `json:"name" yaml:"name"` - Group string `json:"group" yaml:"group"` - Communication string `json:"communication,omitempty" yaml:"communication,omitempty"` - Image string `json:"image" yaml:"image"` - Registry string `json:"registry,omitempty" yaml:"registry,omitempty"` - Username string `json:"username,omitempty" yaml:"username,omitempty"` - Password string `json:"password,omitempty" yaml:"password,omitempty"` - Description string `json:"description" yaml:"description"` - Type string `json:"type" yaml:"type"` - Flavor string `json:"flavor,omitempty" yaml:"flavor,omitempty"` - Envs map[string]string `json:"envs,omitempty" yaml:"envs,omitempty"` - PatternName string `json:"pattern_name,omitempty" yaml:"pattern_name,omitempty"` - Shell string `json:"shell,omitempty" yaml:"shell,omitempty"` - PreCmd string `json:"pre_cmd,omitempty" yaml:"pre_cmd,omitempty"` - Cmd string `json:"cmd,omitempty" yaml:"cmd,omitempty"` - PostCmd string `json:"post_cmd,omitempty" yaml:"post_cmd,omitempty"` - Restricted bool `json:"restricted,omitempty" yaml:"restricted,omitempty"` - IsDeprecated bool `json:"is_deprecated,omitempty" yaml:"is_deprecated,omitempty"` + Name string `json:"name" yaml:"name"` + Group string `json:"group" yaml:"group"` + Image string `json:"image" yaml:"image"` + Registry string `json:"registry,omitempty" yaml:"registry,omitempty"` + Username string `json:"username,omitempty" yaml:"username,omitempty"` + Password string `json:"password,omitempty" yaml:"password,omitempty"` + Description string `json:"description" yaml:"description"` + Type string `json:"type" yaml:"type"` + Flavor string `json:"flavor,omitempty" yaml:"flavor,omitempty"` + Envs map[string]string `json:"envs,omitempty" yaml:"envs,omitempty"` + PatternName string `json:"pattern_name,omitempty" yaml:"pattern_name,omitempty"` + Shell string `json:"shell,omitempty" yaml:"shell,omitempty"` + PreCmd string `json:"pre_cmd,omitempty" yaml:"pre_cmd,omitempty"` + Cmd string `json:"cmd,omitempty" yaml:"cmd,omitempty"` + PostCmd string `json:"post_cmd,omitempty" yaml:"post_cmd,omitempty"` + Restricted bool `json:"restricted,omitempty" yaml:"restricted,omitempty"` + IsDeprecated bool `json:"is_deprecated,omitempty" yaml:"is_deprecated,omitempty"` } type WorkerModelOption func(sdk.Model, *WorkerModel) error @@ -53,7 +52,6 @@ func NewWorkerModel(wm sdk.Model, opts ...WorkerModelOption) WorkerModel { IsDeprecated: wm.IsDeprecated, Description: wm.Description, Restricted: wm.Restricted, - Image: wm.Image, } switch wm.Type { diff --git a/sdk/worker_model.go b/sdk/worker_model.go index fc6914d9e6..21df10a65c 100644 --- a/sdk/worker_model.go +++ b/sdk/worker_model.go @@ -42,7 +42,6 @@ type Model struct { Name string `json:"name" db:"name" cli:"name,key"` Description string `json:"description" db:"description" cli:"description"` Type string `json:"type" db:"type" cli:"type"` - Image string `json:"image" db:"image" cli:"image"` // TODO: DELETE after migration done Disabled bool `json:"disabled" db:"disabled" cli:"disabled"` Restricted bool `json:"restricted" db:"restricted" cli:"restricted"` RegisteredOS *string `json:"registered_os" db:"registered_os" cli:"-"`