From 16c333987927ea420fd48fb27930a8026ed178c9 Mon Sep 17 00:00:00 2001 From: Manuel Huber Date: Wed, 2 Feb 2022 18:56:06 +0000 Subject: [PATCH 1/3] Changes for AksIot --- hcn/hcnnetwork.go | 4 +++- vm.go | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/hcn/hcnnetwork.go b/hcn/hcnnetwork.go index b85cbafc1c..f35772af5b 100644 --- a/hcn/hcnnetwork.go +++ b/hcn/hcnnetwork.go @@ -453,7 +453,9 @@ func (network *HostComputeNetwork) Create() (*HostComputeNetwork, error) { for _, subnet := range ipam.Subnets { if subnet.IpAddressPrefix != "" { hasDefault := false + needsDefault := false for _, route := range subnet.Routes { + needsDefault = true if route.NextHop == "" { return nil, errors.New("network create error, subnet has address prefix but no gateway specified") } @@ -461,7 +463,7 @@ func (network *HostComputeNetwork) Create() (*HostComputeNetwork, error) { hasDefault = true } } - if !hasDefault { + if !hasDefault && needsDefault { return nil, errors.New("network create error, no default gateway") } } diff --git a/vm.go b/vm.go index 367334bc5e..90326b5f4d 100644 --- a/vm.go +++ b/vm.go @@ -54,6 +54,7 @@ type VirtualMachineOptions struct { VnicId string MacAddress string UseGuestConnection bool + UseVsock bool AllowOvercommit bool } @@ -132,7 +133,7 @@ func CreateVirtualMachineSpec(opts *VirtualMachineOptions) (*VirtualMachineSpec, if opts.UseGuestConnection { spec.VirtualMachine.GuestConnection = &hcsschema.GuestConnection{ - UseVsock: true, + UseVsock: opts.UseVsock, UseConnectedSuspend: true, } } From 171dc767149c020d083750fd8ff00b07f8dc45b9 Mon Sep 17 00:00:00 2001 From: Manuel Huber Date: Mon, 14 Feb 2022 19:38:23 +0000 Subject: [PATCH 2/3] Changes for AksIot #2 --- vm.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vm.go b/vm.go index 90326b5f4d..1a0a409efb 100644 --- a/vm.go +++ b/vm.go @@ -71,10 +71,12 @@ type VirtualMachineSpec struct { func CreateVirtualMachineSpec(opts *VirtualMachineOptions) (*VirtualMachineSpec, error) { // Ensure the VM has access, we use opts.Id to create VM if err := wclayer.GrantVmAccess(opts.Id, opts.VhdPath); err != nil { - return nil, err + // TODO we need to sort this out - if we error here, VMs won't come up anymore after reboot + //return nil, fmt.Errorf("Failed to grant VM access to VHD file, error: %s", err) } if err := wclayer.GrantVmAccess(opts.Id, opts.IsoPath); err != nil { - return nil, err + //return nil, fmt.Errorf("Failed to grant VM access to ISO file, error: %s", err) + err = nil } spec := &hcsschema.ComputeSystem{ From f60ece137933578129bc66f5a4f50a3a9790b09b Mon Sep 17 00:00:00 2001 From: Manuel Huber Date: Thu, 24 Feb 2022 23:00:00 +0000 Subject: [PATCH 3/3] Changes for AksIot #3 Use the endpoint name instead of id to ensure the resource path remains constant across VM reboots. Otherwise, e.g. Windows VMs will recognize a different network adapter (leading to loss of static IP config) --- vm.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/vm.go b/vm.go index 1a0a409efb..d5f9059b96 100644 --- a/vm.go +++ b/vm.go @@ -71,12 +71,10 @@ type VirtualMachineSpec struct { func CreateVirtualMachineSpec(opts *VirtualMachineOptions) (*VirtualMachineSpec, error) { // Ensure the VM has access, we use opts.Id to create VM if err := wclayer.GrantVmAccess(opts.Id, opts.VhdPath); err != nil { - // TODO we need to sort this out - if we error here, VMs won't come up anymore after reboot - //return nil, fmt.Errorf("Failed to grant VM access to VHD file, error: %s", err) + return nil, fmt.Errorf("Failed to grant VM access to VHD file, error: %s", err) } if err := wclayer.GrantVmAccess(opts.Id, opts.IsoPath); err != nil { - //return nil, fmt.Errorf("Failed to grant VM access to ISO file, error: %s", err) - err = nil + return nil, fmt.Errorf("Failed to grant VM access to ISO file, error: %s", err) } spec := &hcsschema.ComputeSystem{ @@ -365,7 +363,7 @@ func (vm *VirtualMachineSpec) HotDetachEndpoint(endpoint *hcn.HostComputeEndpoin // Hot detach an endpoint from the compute system request := hcsschema.ModifySettingRequest{ RequestType: requesttype.Remove, - ResourcePath: path.Join("VirtualMachine/Devices/NetworkAdapters", endpoint.Id), + ResourcePath: path.Join("VirtualMachine/Devices/NetworkAdapters", endpoint.Name), Settings: hcsschema.NetworkAdapter{ EndpointId: endpoint.Id, MacAddress: endpoint.MacAddress, @@ -383,7 +381,7 @@ func (vm *VirtualMachineSpec) hotAttachEndpoint(ctx context.Context, system *hcs // Hot attach an endpoint to the compute system request := hcsschema.ModifySettingRequest{ RequestType: requesttype.Add, - ResourcePath: path.Join("VirtualMachine/Devices/NetworkAdapters", endpoint.Id), + ResourcePath: path.Join("VirtualMachine/Devices/NetworkAdapters", endpoint.Name), Settings: hcsschema.NetworkAdapter{ EndpointId: endpoint.Id, MacAddress: endpoint.MacAddress,