-
Notifications
You must be signed in to change notification settings - Fork 24
/
base.go
98 lines (81 loc) · 3.18 KB
/
base.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package machines
import (
"context"
"yunion.io/x/jsonutils"
"yunion.io/x/log"
ocapi "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
"yunion.io/x/onecloud/pkg/httperrors"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/pkg/errors"
"yunion.io/x/kubecomps/pkg/kubeserver/api"
"yunion.io/x/kubecomps/pkg/kubeserver/models"
)
type sBaseDriver struct{}
func newBaseDriver() *sBaseDriver {
return &sBaseDriver{}
}
func (d *sBaseDriver) ValidateCreateData(name string) error {
man := models.MachineManager
err := man.ValidateName(name)
if err != nil {
return err
}
q := man.Query()
q = man.FilterByName(q, name)
if q.Count() != 0 {
return httperrors.NewDuplicateNameError("name", name)
}
return nil
}
func (d *sBaseDriver) RequestPrepareMachine(ctx context.Context, userCred mcclient.TokenCredential, machine *models.SMachine, task taskman.ITask) error {
/*cluster, err := machine.GetCluster()
if err != nil {
return errors.Wrap(err, "GetCluster")
}*/
createInput, err := machine.GetCreateInput(ctx, userCred)
if err != nil {
log.Errorf("Get create input error: %v", err)
}
input := &api.MachinePrepareInput{
FirstNode: machine.IsFirstNode(),
Role: machine.GetRole(),
Config: createInput.Config,
}
/*input, err = cluster.FillMachinePrepareInput(input)
if err != nil {
return errors.Wrap(err, "FillMachinePrepareInput")
}*/
return machine.StartPrepareTask(ctx, task.GetUserCred(), jsonutils.Marshal(input).(*jsonutils.JSONDict), task.GetTaskId())
}
func (d *sBaseDriver) PrepareResource(session *mcclient.ClientSession, machine *models.SMachine, data *api.MachinePrepareInput) (jsonutils.JSONObject, error) {
return nil, nil
}
func (d *sBaseDriver) PostDelete(ctx context.Context, userCred mcclient.TokenCredential, m *models.SMachine, t taskman.ITask) error {
t.SetStageComplete(ctx, nil)
return nil
}
func (d *sBaseDriver) TerminateResource(session *mcclient.ClientSession, machine *models.SMachine) error {
return nil
}
func (d *sBaseDriver) GetPrivateIP(session *mcclient.ClientSession, id string) (string, error) {
return "", errors.Errorf("not impl")
}
func (d *sBaseDriver) UseClusterAPI() bool {
return false
}
func (d *sBaseDriver) ValidateDeleteCondition(ctx context.Context, userCred mcclient.TokenCredential, cluster *models.SCluster, machine *models.SMachine) error {
return nil
}
func (d *sBaseDriver) ListNetworkAddress(ctx context.Context, s *mcclient.ClientSession, m *models.SMachine) ([]*ocapi.NetworkAddressDetails, error) {
return nil, errors.Errorf("Machine %s not support list network address", m.GetName())
}
func (d *sBaseDriver) AttachNetworkAddress(ctx context.Context, s *mcclient.ClientSession, m *models.SMachine, opt *api.MachineAttachNetworkAddressInput) error {
return errors.Errorf("Machine %s not support attach network address", m.GetName())
}
func (d *sBaseDriver) SyncNetworkAddress(ctx context.Context, s *mcclient.ClientSession, m *models.SMachine) error {
return errors.Errorf("Machine %s not support sync network address", m.GetName())
}
func (d *sBaseDriver) GetInfoFromCloud(ctx context.Context, s *mcclient.ClientSession, m *models.SMachine) (*api.CloudMachineInfo, error) {
return nil, nil
}