You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.7 KiB
Go
51 lines
1.7 KiB
Go
//go:build libvirt
|
|
|
|
package hypervisor
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"git.luoli.live/root/virt/agent/operation"
|
|
"git.luoli.live/root/virt/agent/vpcrouting"
|
|
)
|
|
|
|
func (l *Libvirt) ApplyVPCNetwork(ctx context.Context, request vpcrouting.ApplyRequest) (vpcrouting.Result, error) {
|
|
if l.vpcRouter == nil {
|
|
return vpcrouting.Result{}, NewError(ErrUnavailable, "vpc_router_unavailable", "VPC host router is unavailable", nil)
|
|
}
|
|
return l.vpcRouter.Apply(ctx, request)
|
|
}
|
|
|
|
func (l *Libvirt) RemoveVPCNetwork(ctx context.Context, request vpcrouting.RemoveRequest) (vpcrouting.Result, error) {
|
|
if l.vpcRouter == nil {
|
|
return vpcrouting.Result{}, NewError(ErrUnavailable, "vpc_router_unavailable", "VPC host router is unavailable", nil)
|
|
}
|
|
return l.vpcRouter.Remove(ctx, request)
|
|
}
|
|
|
|
func (l *Libvirt) reconcileVPCNetwork(record operation.Record) (operation.Resolution, bool, error) {
|
|
expected := record.ExpectedState
|
|
if expected == nil || expected.Kind != operation.ExpectedVPCNetwork {
|
|
return operation.Resolution{}, false, nil
|
|
}
|
|
if l.vpcRouter == nil {
|
|
return operation.Resolution{}, true, NewError(ErrUnavailable, "vpc_router_unavailable", "VPC host router is unavailable", nil)
|
|
}
|
|
inspection, err := l.vpcRouter.Inspect(
|
|
record.OperationID, expected.VPCKey, expected.VPCRevision,
|
|
expected.VPCDigest, expected.VPCPresent,
|
|
)
|
|
if err != nil {
|
|
return operation.Resolution{}, true, err
|
|
}
|
|
if !inspection.Applied && !inspection.Removed {
|
|
return operation.Resolution{}, true, nil
|
|
}
|
|
encoded, err := json.Marshal(inspection.Result)
|
|
if err != nil {
|
|
return operation.Resolution{}, true, err
|
|
}
|
|
return operation.Resolution{Resolved: true, Succeeded: true, Result: encoded}, true, nil
|
|
}
|