def create_subnet(subnet=None): rc = create_rc_by_subnet(subnet) subnet_params = {"network_id": subnet.network.network_id, "name": "subnet-%s" % subnet.id, "cidr": subnet.address, "ip_version": subnet.ip_version, "dns_nameservers": settings.DNS_NAMESERVERS, "enable_dhcp": True} LOG.info("Start to create subnet, id[%s], name[%s]", subnet.id, subnet.name) begin = datetime.datetime.now() try: sub = neutron.subnet_create(rc, **subnet_params) end = datetime.datetime.now() LOG.info("Create subnet api apply [%s] seconds", \ (end-begin).seconds) subnet.subnet_id = sub.id subnet.status = NETWORK_STATE_ACTIVE subnet.save() except Exception as ex: end = datetime.datetime.now() LOG.info("Create subnet api apply [%s] seconds", \ (end-begin).seconds) subnet.status = NETWORK_STATE_ERROR subnet.save() LOG.exception("Failed to create subnet, id:[%s], name:[%s], msg:[%s]", subnet.id, subnet.name, ex) raise ex return subnet
def network_create(request): network_params = {'name': "network-04", "admin_state_up": True} network = neutron.network_create(request, **network_params) print network subnet_params = {"network_id": network.id, "name": "subnet-04", "cidr": "172.30.0.0/24", "ip_version": 4, #"gateway_ip": None, # is set none, disable gateway "enable_dhcp": True} subnet = neutron.subnet_create(request, **subnet_params) print subnet return network
def create_subnet(subnet=None): rc = create_rc_by_subnet(subnet) LOG.info("subnet is" + str(subnet)) LOG.info("subnet address is" + str(subnet.address)) # start to get gateway. sub_cidr = str(subnet.address) subnet_split = sub_cidr.split('/') sub_addr = subnet_split[0] sub_addr_split = sub_addr.split('.') gateway = sub_addr_split[0] + "." + sub_addr_split[ 1] + "." + sub_addr_split[2] + ".1" LOG.info("gateway is" + str(gateway)) subnet_params = { "network_id": subnet.network.network_id, "name": "subnet-%s" % subnet.id, "cidr": subnet.address, "ip_version": subnet.ip_version, "dns_nameservers": settings.DNS_NAMESERVERS, "gateway_ip": gateway, "enable_dhcp": True } LOG.info("Start to create subnet, id[%s], name[%s]", subnet.id, subnet.name) begin = datetime.datetime.now() try: sub = neutron.subnet_create(rc, **subnet_params) end = datetime.datetime.now() LOG.info("Create subnet api apply [%s] seconds", \ (end-begin).seconds) subnet.subnet_id = sub.id subnet.status = NETWORK_STATE_ACTIVE subnet.save() except Exception as ex: end = datetime.datetime.now() LOG.info("Create subnet api apply [%s] seconds", \ (end-begin).seconds) subnet.status = NETWORK_STATE_ERROR subnet.save() LOG.exception("Failed to create subnet, id:[%s], name:[%s], msg:[%s]", subnet.id, subnet.name, ex) raise ex return subnet
def subnet_create_task(subnet=None): rc = create_rc_by_subnet(subnet) subnet_params = {"network_id": subnet.network.network_id, "name": "subnet-%s" % subnet.id, "cidr": subnet.address, "ip_version": subnet.ip_version, "enable_dhcp": True} try: sub = neutron.subnet_create(rc, **subnet_params) subnet.subnet_id = sub.id subnet.status = NETWORK_STATE_ACTIVE subnet.save() except Exception as ex: subnet.status = NETWORK_STATE_ERROR subnet.save() LOG.info("create subnet error,id:[%s], msg:[%s]" % (subnet.id, ex)) raise ex return subnet