Ejemplo n.º 1
0
        public override async Task <PortGroupAllocation> AddPortGroup(string sw, VmNet eth)
        {
            try
            {
                HostPortGroupSpec spec = new HostPortGroupSpec();
                spec.vswitchName     = sw;
                spec.vlanId          = eth.Vlan;
                spec.name            = eth.Net;
                spec.policy          = new HostNetworkPolicy();
                spec.policy.security = new HostNetworkSecurityPolicy();
                spec.policy.security.allowPromiscuous          = true;
                spec.policy.security.allowPromiscuousSpecified = true;
                if (eth.Net.Untagged().EndsWith(_client.NetworkAllowAllSuffix))
                {
                    spec.policy.security.forgedTransmits          = true;
                    spec.policy.security.forgedTransmitsSpecified = true;
                    spec.policy.security.macChanges          = true;
                    spec.policy.security.macChangesSpecified = true;
                }

                await _client.vim.AddPortGroupAsync(_client.net, spec);
            } catch {}

            return(new PortGroupAllocation
            {
                Net = eth.Net,
                Key = eth.Net,
                VlanId = eth.Vlan,
                Switch = sw
            });
        }
Ejemplo n.º 2
0
        private static VirtualDeviceConfigSpec GetEthernetAdapter(ref int key, VmNet nic, string dvsuuid)
        {
            VirtualDeviceConfigSpec devicespec = new VirtualDeviceConfigSpec();
            VirtualEthernetCard     eth        = new VirtualE1000();

            if (nic.Type == "pcnet32")
            {
                eth = new VirtualPCNet32();
            }

            if (nic.Type == "vmx3")
            {
                eth = new VirtualVmxnet3();
            }

            if (nic.Type == "e1000e")
            {
                eth = new VirtualE1000e();
            }

            eth.key = key--;

            if (nic.Mac.HasValue())
            {
                eth.addressType = "Manual";
                eth.macAddress  = nic.Mac;
            }

            if (nic.Net.StartsWith("nsx."))
            {
                eth.backing = new VirtualEthernetCardOpaqueNetworkBackingInfo {
                    opaqueNetworkId   = nic.Key.Tag(),
                    opaqueNetworkType = nic.Key.Untagged()
                };
            }
            else if (dvsuuid.HasValue())
            {
                eth.backing = new VirtualEthernetCardDistributedVirtualPortBackingInfo {
                    port = new DistributedVirtualSwitchPortConnection
                    {
                        switchUuid   = dvsuuid,
                        portgroupKey = nic.Key.AsReference().Value
                    }
                };
            }
            else
            {
                eth.backing = new VirtualEthernetCardNetworkBackingInfo {
                    deviceName = nic.Key
                };
            }

            devicespec                    = new VirtualDeviceConfigSpec();
            devicespec.device             = eth;
            devicespec.operation          = VirtualDeviceConfigSpecOperation.add;
            devicespec.operationSpecified = true;

            return(devicespec);
        }
        public override async Task <PortGroupAllocation> AddPortGroup(string sw, VmNet eth)
        {
            var mor = new ManagedObjectReference();

            try
            {
                bool allowAll = eth.Net.Untagged().EndsWith(_client.NetworkAllowAllSuffix);

                var spec = new DVPortgroupConfigSpec()
                {
                    name       = eth.Net,
                    autoExpand = true,
                    type       = "earlyBinding",

                    defaultPortConfig = new VMwareDVSPortSetting
                    {
                        vlan = new VmwareDistributedVirtualSwitchVlanIdSpec
                        {
                            vlanId = eth.Vlan
                        },
                        securityPolicy = new DVSSecurityPolicy()
                        {
                            allowPromiscuous = new BoolPolicy()
                            {
                                value          = true,
                                valueSpecified = true
                            },
                            forgedTransmits = new BoolPolicy()
                            {
                                value          = allowAll,
                                valueSpecified = allowAll
                            },
                            macChanges = new BoolPolicy()
                            {
                                value          = allowAll,
                                valueSpecified = allowAll
                            }
                        }
                    }
                };

                var task = await _client.vim.CreateDVPortgroup_TaskAsync(_client.dvs, spec);

                var info = await WaitForVimTask(task);

                mor = info.result as ManagedObjectReference;
            }
            catch { }
            return(new PortGroupAllocation
            {
                Net = eth.Net,
                Key = mor.AsString(),
                VlanId = eth.Vlan,
                Switch = _client.UplinkSwitch
            });
        }
Ejemplo n.º 4
0
        private static VirtualDeviceConfigSpec GetEthernetAdapter(ref int key, VmNet nic, string dvsuuid)
        {
            VirtualDeviceConfigSpec devicespec = new VirtualDeviceConfigSpec();
            VirtualEthernetCard     eth        = new VirtualE1000();

            if (nic.Type == "pcnet32")
            {
                eth = new VirtualPCNet32();
            }

            if (nic.Type == "vmx3")
            {
                eth = new VirtualVmxnet3();
            }

            if (nic.Type == "e1000e")
            {
                eth = new VirtualE1000e();
            }

            // VirtualEthernetCardNetworkBackingInfo ethbacking = new VirtualEthernetCardNetworkBackingInfo();
            // ethbacking.deviceName = nic.Net;

            eth.key = key--;
            if (dvsuuid.HasValue())
            {
                eth.backing = new VirtualEthernetCardDistributedVirtualPortBackingInfo {
                    port = new DistributedVirtualSwitchPortConnection
                    {
                        switchUuid   = dvsuuid,
                        portgroupKey = nic.Net
                    }
                }
            }
            ;
            else
            {
                eth.backing = new VirtualEthernetCardNetworkBackingInfo {
                    deviceName = nic.Net
                }
            };

            devicespec                    = new VirtualDeviceConfigSpec();
            devicespec.device             = eth;
            devicespec.operation          = VirtualDeviceConfigSpecOperation.add;
            devicespec.operationSpecified = true;

            return(devicespec);
        }
Ejemplo n.º 5
0
        public override async Task <PortGroupAllocation> AddPortGroup(string sw, VmNet eth)
        {
            try
            {
                HostPortGroupSpec spec = new HostPortGroupSpec();
                spec.vswitchName     = sw;
                spec.vlanId          = eth.Vlan;
                spec.name            = eth.Net;
                spec.policy          = new HostNetworkPolicy();
                spec.policy.security = new HostNetworkSecurityPolicy();
                spec.policy.security.allowPromiscuous          = true;
                spec.policy.security.allowPromiscuousSpecified = true;

                await _client.vim.AddPortGroupAsync(_client.net, spec);
            } catch {}

            return(new PortGroupAllocation
            {
                Net = eth.Net,
                Key = "HostPortGroup|" + eth.Net,
                VlanId = eth.Vlan,
                Switch = sw
            });
        }
Ejemplo n.º 6
0
        public override async Task <PortGroupAllocation> AddPortGroup(string sw, VmNet eth)
        {
            await InitClient();

            string url = $"{_apiUrl}/{_apiSegments}/{eth.Net.Replace("#","%23")}";

            var response = await _sddc.PutAsync(
                url,
                new StringContent(
                    "{\"advanced_config\": { \"connectivity\": \"OFF\" } }",
                    Encoding.UTF8,
                    "application/json"
                    )
                );

            int count = 0;
            PortGroupAllocation pga = null;

            while (pga == null && count < 10)
            {
                // slight delay
                await Task.Delay(1500);

                count += 1;

                pga = (await LoadPortGroups())
                      .FirstOrDefault(p => p.Net == eth.Net);
            }

            if (pga == null)
            {
                throw new Exception($"Failed to create net {eth.Net}");
            }

            return(pga);
        }
Ejemplo n.º 7
0
 public abstract Task <PortGroupAllocation> AddPortGroup(string sw, VmNet eth);