from vcloud_plugin_common import Config, VcloudDirectorClient
from pyvcloud.schema.vcd.v1_5.schemas.vcloud.networkType import OrgVdcNetworkType
from pyvcloud.helper import generalHelperFunctions as ghf

content_type = "application/vnd.vmware.vcloud.orgVdcNetwork+xml"
vcd_client = VcloudDirectorClient().get()
link = filter(lambda link: link.get_type() == content_type, vdc_client.get_Link())
net = OrgVdcNetworkType()
body = '<?xml version="1.0" encoding="UTF-8"?>' + \
       ghf.convertPythonObjToStr(net, name = 'OrgVdcNetwork',
       namespacedef = 'xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ')
response = requests.post(link[0].get_href(), data=body, headers=self.headers)
print response.status_code

@@ -136,16 +136,111 @@
 workType
+, ReferenceType, NetworkConfigurationType, IpScopesType, IpScopeType, IpRangesType, IpRangeType
 %0Afrom py
@@ -291,16 +291,42 @@
 as ghf%0A%0A
+testnet = %22test_network%22%0A%0A
 content_
@@ -428,115 +428,872 @@
 t()%0A
-link = filter(lambda link: link.get_type() == content_type, vdc_client.get_Link())%0Anet = OrgVdcNetworkType(
+vdc=vcd_client._get_vdc()%0Anetworks_name = %5Bnet.name for net in  vdc.AvailableNetworks.Network%5D%0A%0Apostlink = filter(lambda link: link.get_type() == content_type, vdc.get_Link())%5B0%5D.href%0A%0Agatewayref = vcd_client.get_gateways()%5B0%5D.me.href%0A%0Agateway=ReferenceType(href=gatewayref)%0Agateway.original_tagname_=%22EdgeGateway%22%0A%0Aiprange = IpRangeType(StartAddress=%22192.168.0.100%22, EndAddress=%22192.168.0.199%22)%0Aipranges = IpRangesType(IpRange=%5Biprange%5D)%0Aipscope = IpScopeType(IsInherited=False, Gateway=%22192.168.0.1%22, Netmask=%22255.255.255.0%22,%0A                    Dns1=%224.2.2.4%22, DnsSuffix=%22example.com%22, IpRanges=ipranges)%0Aipscopes =  IpScopesType(IpScope=%5Bipscope%5D)%0Aconfiguration = NetworkConfigurationType(IpScopes=ipscopes, FenceMode=%22natRouted%22)%0Anet = OrgVdcNetworkType(name=testnet, Description=%22test_network%22, EdgeGateway=gateway, Configuration=configuration, IsShared=True
 )%0Abo
@@ -1403,17 +1403,44 @@
 etwork',
-%0A
+%5C%0A                          
        n
@@ -1499,66 +1499,23 @@
 1.5%22
- xmlns:xsi=%22http://www.w3.org/2001/XMLSchema-instance%22 ')%0A
+')%0Aprint body%0A#
 resp
@@ -1539,15 +1539,16 @@
 ost(
+post
 link
-%5B0%5D
 .get
@@ -1589,16 +1589,17 @@
 eaders)%0A
+#
 print re

improve add network command