Beispiel #1
0
def get_subnets(auth, filter={}):
    client = auth_check(auth)
    if 'slice' in filter:
        slice = _get_slice(filter.get('slice'))
        if slice: filter['slice'] = slice
    subnets = Subnet.objects.filter(**filter)
    return subnets             
Beispiel #2
0
def get_subnets(auth, filter={}):
    client = auth_check(auth)
    if 'slice' in filter:
        slice = _get_slice(filter.get('slice'))
        if slice: filter['slice'] = slice
    subnets = Subnet.objects.filter(**filter)
    return subnets
Beispiel #3
0
def add_subnet(auth, fields):
    driver = OpenStackDriver(client=auth_check(auth))
    slices = _get_slices(fields.get('slice'))
    if slices: fields['slice'] = slices[0]
    subnet = Subnet(**fields)
    # create quantum subnet
    quantum_subnet = driver.create_subnet(name=subnet.slice.name,
                                          network_id=subnet.slice.network_id,
                                          cidr_ip=subnet.cidr,
                                          ip_version=subnet.ip_version,
                                          start=subnet.start,
                                          end=subnet.end)
    subnet.subnet_id = quantum_subnet['id']
    ## set dns servers
    #driver.update_subnet(subnet.id, {'dns_nameservers': ['8.8.8.8', '8.8.4.4']})

    # add subnet as interface to slice's router
    try:
        driver.add_router_interface(subnet.slice.router_id, subnet.subnet_id)
    except:
        pass
    #add_route = 'route add -net %s dev br-ex gw 10.100.0.5' % self.cidr
    commands.getstatusoutput(add_route)
    subnet.save()
    return subnet
Beispiel #4
0
def delete_subnet(auth, filter={}):
    driver = OpenStackDriver(client = auth_check(auth))   
    subnets = Subnet.objects.filter(**filter)
    for subnet in subnets:
        driver.delete_router_interface(subnet.slice.router_id, subnet.subnet_id)
        driver.delete_subnet(subnet.subnet_id) 
        subnet.delete()
        #del_route = 'route del -net %s' % subnet.cidr
    commands.getstatusoutput(del_route)
    return 1
Beispiel #5
0
def delete_subnet(auth, filter={}):
    driver = OpenStackDriver(client=auth_check(auth))
    subnets = Subnet.objects.filter(**filter)
    for subnet in subnets:
        driver.delete_router_interface(subnet.slice.router_id,
                                       subnet.subnet_id)
        driver.delete_subnet(subnet.subnet_id)
        subnet.delete()
        #del_route = 'route del -net %s' % subnet.cidr
    commands.getstatusoutput(del_route)
    return 1
Beispiel #6
0
def add_subnet(auth, fields):
    driver = OpenStackDriver(client = auth_check(auth))
    slices = _get_slices(fields.get('slice')) 
    if slices: fields['slice'] = slices[0]     
    subnet = Subnet(**fields)
    # create quantum subnet
    quantum_subnet = driver.create_subnet(name= subnet.slice.name,
                                          network_id=subnet.slice.network_id,
                                          cidr_ip = subnet.cidr,
                                          ip_version=subnet.ip_version,
                                          start = subnet.start,
                                          end = subnet.end)
    subnet.subnet_id=quantum_subnet['id']
    ## set dns servers
    #driver.update_subnet(subnet.id, {'dns_nameservers': ['8.8.8.8', '8.8.4.4']})

    # add subnet as interface to slice's router
    try: driver.add_router_interface(subnet.slice.router_id, subnet.subnet_id)
    except: pass         
    #add_route = 'route add -net %s dev br-ex gw 10.100.0.5' % self.cidr
    commands.getstatusoutput(add_route)    
    subnet.save()
    return subnet