CreateNetwork() public method

public CreateNetwork ( string name, bool adminStateUp = true, string networkType = "vxlan", string segmentationId = null ) : Network
name string
adminStateUp bool
networkType string
segmentationId string
return Network
        public void CreateVIPTest()
        {
            var os = new OpenStackMember(UserName, Password, TenantName, TenantId);

            // Get Pool
            Pool pool;
            try { pool = GetPoolByName(TesterName, ref os); }
            catch (ArgumentException pae)
            {
                if (pae.Message.Equals("no pool found"))
                {
                    // Get Subnet
                    Subnet subnet;
                    try
                    {
                        // subnet = GetSubnetByName(TesterName, ref os);
                        subnet = os.GetSubnet("20f429bb-472c-403d-b9ec-e637475f1602"); // fixed tyo1 subnet
                    }
                    catch (ArgumentException sae)
                    {
                        if (sae.Message.Equals("no subnet found"))
                        {
                            // Get Network
                            Network network;
                            try { network = GetNetworkByName(TesterName, ref os); }
                            catch (ArgumentException nae)
                            {
                                if (nae.Message.Equals("no network found"))
                                {
                                    // var tenantId = os.IdentityProvider.GetToken(os.Identity).Tenant.Id;
                                    network = os.CreateNetwork(TesterName);
                                    Assert.IsNotNull(network);
                                }
                                else
                                    throw;
                            }
                            subnet = os.CreateSubnet(TesterName, network.Id, ipVersion: 4, cidr: "192.168.2.0/24");
                            Assert.IsNotNull(subnet);

                        }
                        else
                            throw;
                    }

                    var subnetId = GetSubnetIdByRegion(region: null);

                    pool = os.CreatePool(TesterName, TenantId, subnetId);
                    Assert.IsNotNull(pool);
                }
                else
                    throw;
            }

            string name = GetTesterNameByEnv(); ;
            string protocol = "TCP"; // TCP Only
            string protocolPort = "80"; // A valid value is from 0 to 65535.
            string poolId = GetPoolByName(TesterName, ref os).Id;
            string TokyoLBaas_subnetId = GetSubnetIdByRegion(region: null);
            string address = "157.7.81.200"; // cidr of (subnetid=20f429bb-472c-403d-b9ec-e637475f1602) is "157.7.81.128/27"
            bool adminStateUp = true;
            string description = null;
            string sessionPpersistence = null;
            int? connectionLimit = null;

            var vip = os.CreateVIP(name, protocol, protocolPort, poolId, TokyoLBaas_subnetId, address, adminStateUp, description, sessionPpersistence, connectionLimit);
            Assert.IsNotNull(vip);
        }
        public void UpdateSubnetTest()
        {

            var os = new OpenStackMember(UserName, Password, TenantName, TenantId);

            // create network
            string network_name = GetTesterNameByEnv();
            bool adminStateUp = true;
            string networkType = "vxlan";
            string segmentationId = null;
            var n = os.CreateNetwork(network_name, adminStateUp, networkType, segmentationId);
            Assert.IsNotNull(n);

            try
            {
                string subnet_name = GetTesterNameByEnv();
                int ipVersion = 4;
                string cidr = "192.168.2.0/24";

                // create subnet
                var s = os.CreateSubnet(subnet_name, n.Id, ipVersion, cidr);
                Assert.IsNotNull(s);
                Trace.WriteLine(string.Format("subnet IpVersion : {0}", s.IpVersion));

                try
                {
                    // update subnet
                    var subnet = os.UpdateSubnet(s.Id, "new value");
                    Assert.IsNotNull(subnet);
                    Trace.WriteLine(string.Format("subnet name : {0}", subnet.Name));

                    // this fails
                    //subnet = os.UpdateSubnet(s.Id, "日本語");
                    //subnet = os.UpdateSubnet(s.Id, "new value\\\"");

                }
                finally
                {
                    Assert.IsTrue(os.DeleteSubnet(s.Id));
                }
            }
            finally
            {
                Assert.IsTrue(os.DeleteNetwork(n.Id));
            }
        }
        public void CreateSubnetTest()
        {
            var os = new OpenStackMember(UserName, Password, TenantName, TenantId);

            // create network
            string network_name = GetTesterNameByEnv();
            bool adminStateUp = true;
            string networkType = "vxlan";
            string segmentationId = null;
            var n = os.CreateNetwork(network_name, adminStateUp, networkType, segmentationId);
            Assert.IsNotNull(n);

            try
            {
                // create subnet
                string subnet_name = GetTesterNameByEnv();
                int ipVersion = 4;
                string cidr = "192.168.2.0/24";

                var s = os.CreateSubnet(subnet_name, n.Id, ipVersion, cidr);
                Assert.IsNotNull(s);
                Trace.WriteLine(string.Format("subnet Id : {0}", s.Id));
                Trace.WriteLine(string.Format("subnet Name : {0}", s.Name));
                Trace.WriteLine(string.Format("subnet TenantId : {0}", s.TenantId));
                Trace.WriteLine(string.Format("subnet NetworkId : {0}", s.NetworkId));
                Trace.WriteLine(string.Format("subnet Cidr : {0}", s.Cidr));
                Trace.WriteLine(string.Format("subnet GatewayIp : {0}", s.GatewayIp));
                Trace.WriteLine(string.Format("subnet IpVersion : {0}", s.IpVersion));

                Assert.IsTrue(os.DeleteSubnet(s.Id));
            }
            finally
            {
                Assert.IsTrue(os.DeleteNetwork(n.Id));
            }
        }
        public void UpdatePortTest()
        {
            var os = new OpenStackMember(UserName, Password, TenantName, TenantId);
            // string tenantId = os.IdentityProvider.GetToken(os.Identity).Tenant.Id;

            // create network
            string network_name = GetTesterNameByEnv();
            bool adminStateUp = true;
            string networkType = "vxlan";
            string segmentationId = null;
            var n = os.CreateNetwork(network_name, adminStateUp, networkType, segmentationId);
            Assert.IsNotNull(n);

            try
            {
                // create port
                string port_name = GetTesterNameByEnv();
                string networkId = n.Id;
                var port = os.CreatePort(networkId, tenantId: TenantId);
                Assert.IsNotNull(port);

                Trace.WriteLine(string.Format("portStatus : {0}", port.Status));
                Assert.AreEqual(port.Status, "DOWN");

                try
                {
                    // update port
                    string newName = "new-name";
                    port = os.UpdatePort(port.Id, adminStateUp);
                    Assert.IsNotNull(port);
                    Assert.AreEqual(port.Name, newName);

                    newName = "日本語";
                    port = os.UpdatePort(port.Id, adminStateUp);
                    //Assert.IsNotNull(port);
                    //Assert.AreEqual(port.Name, newName);

                    Trace.WriteLine(string.Format("portId : {0}", port.Id));
                    Trace.WriteLine(string.Format("portName : {0}", port.Name));
                    Trace.WriteLine(string.Format("portMacAddress : {0}", port.MacAddress));
                    Trace.WriteLine(string.Format("portnetworkId : {0}", port.NetworkId));
                    Trace.WriteLine(string.Format("portTenantId : {0}", port.TenantId));
                    Trace.WriteLine(string.Format("portStatus : {0}", port.Status));
                    Trace.WriteLine(string.Format("portSecurityGroups : {0}", string.Join(",", port.SecurityGroups)));

                }
                finally
                {
                    Assert.IsTrue(os.DeletePort(port.Id));
                }
            }
            finally
            {
                Assert.IsTrue(os.DeleteNetwork(n.Id));
            }
        }
        public void CreateNetworkTest()
        {
            var os = new OpenStackMember(UserName, Password, TenantName, TenantId);
            string name = GetTesterNameByEnv();
            bool adminStateUp = true;
            string networkType = "vxlan";
            string segmentationId = null;

            var n = os.CreateNetwork(name, adminStateUp, networkType, segmentationId);
            Assert.IsNotNull(n);

            os.DeleteNetwork(n.Id);
        }
        private string GetInterfaceAttachmentIdByTesterName(string testerName = null)
        {
            testerName = testerName ?? TesterName;

            var os = new OpenStackMember(UserName, Password, TenantName);

            IEnumerable<Network> networks = os.ListNetworks();
            Network n = networks.Where<Network>(x => x.Name == testerName).FirstOrDefault<Network>();
            if (n == null)
            {
                try
                {
                    n = os.CreateNetwork(testerName);
                    Trace.WriteLine(string.Format("network added : {0}", DateTime.Now));
                    Trace.WriteLine(string.Format("NetworkId : {0}, Name : {1}", n.Id, n.Name));
                }
                catch (Exception)
                {
                    throw;
                }
            }
            IEnumerable<Port> ports = os.ListPorts();
            Port p = ports.Where<Port>(x => x.Name == testerName).FirstOrDefault<Port>();
            if (p == null)
            {
                try
                {
                    p = os.CreatePort(n.Id);
                    Trace.WriteLine(string.Format("port added : {0}", DateTime.Now));
                    Trace.WriteLine(string.Format("PortId : {0}, Name : {1}", p.Id, p.Name));
                }
                catch (Exception)
                {
                    throw;
                }
            }

            return p.Id;
        }