Skip to content
Draft
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
4 changes: 3 additions & 1 deletion hcn/hcnnetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,15 +453,17 @@ func (network *HostComputeNetwork) Create() (*HostComputeNetwork, error) {
for _, subnet := range ipam.Subnets {
if subnet.IpAddressPrefix != "" {
hasDefault := false
needsDefault := false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false

decide the value of needsDefault by checking if subnet.Routes is empty before the loop, no need to set it in the loop.

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")
}
if route.DestinationPrefix == "0.0.0.0/0" || route.DestinationPrefix == "::/0" {
hasDefault = true
}
}
if !hasDefault {
if !hasDefault && needsDefault {
return nil, errors.New("network create error, no default gateway")
}
}
Expand Down
11 changes: 6 additions & 5 deletions vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type VirtualMachineOptions struct {
VnicId string
MacAddress string
UseGuestConnection bool
UseVsock bool
AllowOvercommit bool
}

Expand All @@ -70,10 +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 {
return nil, err
return nil, fmt.Errorf("Failed to grant VM access to VHD file, error: %s", err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VHD file

use opts.VhdPath

}
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ISO file

use opts.IsoPath

}

spec := &hcsschema.ComputeSystem{
Expand Down Expand Up @@ -132,7 +133,7 @@ func CreateVirtualMachineSpec(opts *VirtualMachineOptions) (*VirtualMachineSpec,

if opts.UseGuestConnection {
spec.VirtualMachine.GuestConnection = &hcsschema.GuestConnection{
UseVsock: true,
UseVsock: opts.UseVsock,
UseConnectedSuspend: true,
}
}
Expand Down Expand Up @@ -362,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),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the original motivation to change it from Id to Name?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use the ID, the ID changes every time the VM is rebooted. This is a problem for the Windows VM because it detects a different physical network adapter and loses its networking configuration.

I.e. if we use the ID, a different physical network adapter is mapped into the VM each time the VM restarts.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an optional input parameter to allow caller specify resource name, if caller specify resource name, use it, otherwise use ID to ensure no conflict to existing resource name.

Same for hotAttachEndpoint

ResourcePath: path.Join("VirtualMachine/Devices/NetworkAdapters", endpoint.Name),
Settings: hcsschema.NetworkAdapter{
EndpointId: endpoint.Id,
MacAddress: endpoint.MacAddress,
Expand All @@ -380,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,
Expand Down