def create_network(self, name, tenant_id, subnet, gw=None):
try:<EOL><INDENT>body = {'<STR_LIT>': {'<STR_LIT:name>': name, '<STR_LIT>': tenant_id,<EOL>'<STR_LIT>': True}}<EOL>netw = self.neutronclient.create_network(body=body)<EOL>net_dict = netw.get('<STR_LIT>')<EOL>net_id = net_dict.get('<STR_LIT:id>')<EOL><DEDENT>except Exception as exc:<EOL><INDENT>LOG.error("<STR_LIT>",<EOL>{'<STR_LIT:name>': name, '<STR_LIT>': str(exc)})<EOL>return None, None<EOL><DEDENT>try:<EOL><INDENT>if gw is None:<EOL><INDENT>body = {'<STR_LIT>': {'<STR_LIT>': subnet,<EOL>'<STR_LIT>': <NUM_LIT:4>,<EOL>'<STR_LIT>': net_id,<EOL>'<STR_LIT>': tenant_id,<EOL>'<STR_LIT>': False}}<EOL><DEDENT>else:<EOL><INDENT>body = {'<STR_LIT>': {'<STR_LIT>': subnet,<EOL>'<STR_LIT>': <NUM_LIT:4>,<EOL>'<STR_LIT>': net_id,<EOL>'<STR_LIT>': tenant_id,<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT>': gw}}<EOL><DEDENT>subnet_ret = self.neutronclient.create_subnet(body=body)<EOL>subnet_dict = subnet_ret.get('<STR_LIT>')<EOL>subnet_id = subnet_dict.get('<STR_LIT:id>')<EOL><DEDENT>except Exception as exc:<EOL><INDENT>LOG.error("<STR_LIT>",<EOL>{'<STR_LIT>': subnet, '<STR_LIT>': str(exc)})<EOL>try:<EOL><INDENT>self.neutronclient.delete_network(net_id)<EOL><DEDENT>except Exception as exc:<EOL><INDENT>LOG.error("<STR_LIT>",<EOL>{'<STR_LIT>': net_id, '<STR_LIT>': str(exc)})<EOL><DEDENT>return None, None<EOL><DEDENT>return net_id, subnet_id<EOL>
Create the openstack network, including the subnet.