Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update-service #18

Merged
merged 5 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/OpenNebula/one/src/oca/go/src/goca v0.0.0-20220128134709-75e34b0d670d
github.com/slntopp/nocloud v0.0.15-r5
github.com/slntopp/nocloud v0.0.15-r6
github.com/spf13/cobra v1.3.0
github.com/spf13/viper v1.11.0
github.com/streadway/amqp v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ github.com/sagikazarmark/crypt v0.3.0/go.mod h1:uD/D+6UF4SrIR1uGEv7bBNkNqLGqUr43
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/slntopp/nocloud v0.0.15-r5 h1:qvT64I6JfYJNuR+Z1Ck1Zm4+jpWOGKzuH4E35gDsZrg=
github.com/slntopp/nocloud v0.0.15-r5/go.mod h1:udple1N96lLvkKQpgf8XMP0vmH5VHliBKD3dhTyXhr8=
github.com/slntopp/nocloud v0.0.15-r6 h1:L0AFrv7nMAd+8YfUcA55JervkMh4XL1wd8LTFFutCZE=
github.com/slntopp/nocloud v0.0.15-r6/go.mod h1:udple1N96lLvkKQpgf8XMP0vmH5VHliBKD3dhTyXhr8=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.3.3/go.mod h1:5KUK8ByomD5Ti5Artl0RtHeI5pTF7MIDuXL3yY520V4=
github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
Expand Down
27 changes: 2 additions & 25 deletions pkg/driver/monitoring_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,30 +166,7 @@ func MonitorNetworks(log *zap.Logger, c *ONeClient) (res *structpb.Value, err er
return state
}()

state["private_vnet_tmpl"] = func() (state map[string]interface{}) {
state = map[string]interface{}{}
private_vnet_tmpl_id, ok := c.vars[PRIVATE_VN_TEMPLATE]
if !ok {
state["error"] = "VNet Template is not set"
return state
}

id, err := GetVarValue(private_vnet_tmpl_id, "default")
if err != nil {
state["error"] = err.Error()
return state
}
vn_tmpl, err := c.ctrl.VNTemplate(int(id.GetNumberValue())).Info(true)
if err != nil {
state["error"] = err.Error()
return state
}

state["id"] = vn_tmpl.ID
state["name"] = vn_tmpl.Name
log.Debug("private_vnet_tmpl", zap.Any("state", state))
return state
}()
state["private_vnet"] = map[string]interface{}{"error": "Private VNet Pool Monitoring not implemented"}

return structpb.NewValue(state)
}
Expand Down Expand Up @@ -233,7 +210,7 @@ func MonitorTemplates(log *zap.Logger, c *ONeClient) (res *structpb.Value, err e

state["min_size"] = img.Size

store:
store:
templates[strconv.Itoa(tmpl.ID)] = state
}

Expand Down
37 changes: 27 additions & 10 deletions pkg/driver/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import (

"github.com/OpenNebula/one/src/oca/go/src/goca/schemas/vm"
"github.com/OpenNebula/one/src/oca/go/src/goca/schemas/vm/keys"
"github.com/slntopp/nocloud-driver-ione/pkg/datas"
"github.com/slntopp/nocloud/pkg/hasher"
pb "github.com/slntopp/nocloud/pkg/instances/proto"
"github.com/slntopp/nocloud/pkg/nocloud/auth"
stpb "github.com/slntopp/nocloud/pkg/states/proto"
"go.uber.org/zap"
"google.golang.org/protobuf/types/known/structpb"
Expand Down Expand Up @@ -303,21 +305,14 @@ func (c *ONeClient) CheckInstancesGroup(IG *pb.InstancesGroup) (*CheckInstancesG
res.Uuid = inst.GetUuid()
res.Title = inst.GetTitle()
res.Status = inst.GetStatus()
res.State = inst.GetState()
//res.Resources = inst.GetResources()

err = hasher.SetHash(res.ProtoReflect())
if err != nil {
c.log.Error("Error Setting Instance Hash", zap.Error(err))
continue
}
err = hasher.SetHash(inst.ProtoReflect())
if err != nil {
c.log.Error("Error Setting Instance Hash", zap.Error(err))
continue
}

if res.Hash != inst.Hash {
c.log.Info("original", zap.Any("", inst))
c.log.Info("recieved", zap.Any("", res))
resp.ToBeUpdated = append(resp.ToBeUpdated, inst)
} else {
resp.Valid = append(resp.Valid, inst)
Expand All @@ -327,7 +322,26 @@ func (c *ONeClient) CheckInstancesGroup(IG *pb.InstancesGroup) (*CheckInstancesG
return &resp, nil
}

func (c *ONeClient) CheckInstancesGroupResponseProcess(resp *CheckInstancesGroupResponse) {
func (c *ONeClient) CheckInstancesGroupResponseProcess(resp *CheckInstancesGroupResponse, data map[string]*structpb.Value, group int) {
userid := int(data["userid"].GetNumberValue())
for _, inst := range resp.ToBeCreated {
token, err := auth.MakeTokenInstance(inst.GetUuid())
if err != nil {
c.log.Error("Error generating VM token", zap.String("instance", inst.GetUuid()), zap.Error(err))
continue
}
vmid, err := c.InstantiateTemplateHelper(inst, data, token)
if err != nil {
c.log.Error("Error deploying VM", zap.String("instance", inst.GetUuid()), zap.Error(err))
continue
}
c.Chown("vm", vmid, userid, group)

go datas.Pub(&pb.ObjectData{
Uuid: inst.Uuid,
Data: inst.Data,
})
}

for _, inst := range resp.ToBeDeleted {
vmid, err := GetVMIDFromData(c, inst)
Expand Down Expand Up @@ -427,6 +441,9 @@ func (c *ONeClient) CheckInstancesGroupResponseProcess(resp *CheckInstancesGroup
}

for _, inst := range resp.Valid {
if inst.GetState() == nil || inst.GetState().Meta == nil {
continue
}
_, updated := inst.State.Meta["updated"]
if updated {
delete(inst.State.Meta, "updated")
Expand Down
6 changes: 4 additions & 2 deletions pkg/driver/vnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ func (c *ONeClient) ReservePrivateIP(u int) (pool_id int, err error) {
return -1, err
}

//extra := fmt.Sprintf("VLAN_ID=%d", ar)
user_private_net_id, err := c.ctrl.VNTemplate(int(id.GetNumberValue())).Instantiate(fmt.Sprintf(USER_PRIVATE_VNET_NAME_PATTERN, u), "VLAN_ID=0")
private_vnet_name := fmt.Sprintf(USER_PRIVATE_VNET_NAME_PATTERN, u)
private_ar := "AR = [\n IP = \"10.0.0.0\",\n SIZE = \"255\",\n TYPE = \"IP4\" ]"

user_private_net_id, err := c.ctrl.VNTemplate(int(id.GetNumberValue())).Instantiate(private_vnet_name, private_ar)
if err != nil {
user_private_net_id = -1
}
Expand Down
12 changes: 9 additions & 3 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,14 @@ func (s *DriverServiceServer) Monitoring(ctx context.Context, req *pb.Monitoring
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "Error making client: %v", err)
}
client.SetSecrets(sp.GetSecrets())
client.SetVars(sp.GetVars())

secrets := sp.GetSecrets()
vars := sp.GetVars()

client.SetSecrets(secrets)
client.SetVars(vars)

group := secrets["group"].GetNumberValue()

for _, ig := range req.GetGroups() {
log.Debug("Monitoring group", zap.String("group", ig.GetUuid()), zap.String("title", ig.GetTitle()))
Expand All @@ -347,7 +353,7 @@ func (s *DriverServiceServer) Monitoring(ctx context.Context, req *pb.Monitoring
log.Error("Error Checking Instances Group", zap.String("ig", ig.GetUuid()), zap.Error(err))
} else {
log.Info("Check Instances Group Response", zap.Any("resp", resp))
client.CheckInstancesGroupResponseProcess(resp)
client.CheckInstancesGroupResponseProcess(resp, ig.GetData(), int(group))
}

log.Debug("Monitoring instances", zap.String("group", ig.GetUuid()), zap.Int("instances", len(ig.GetInstances())))
Expand Down