예제 #1
0
 def _get_libcloud_subnet(self, subnet):
     kwargs = {'subnet_ids': [subnet.subnet_id]}
     subnets = self.cloud.ctl.compute.connection.ex_list_subnets(**kwargs)
     if subnets:
         return subnets[0]
     raise SubnetNotFoundError('Subnet %s with subnet_id %s' %
                               (subnet.name, subnet.subnet_id))
예제 #2
0
def delete_subnet(request):
    """
    Tags: networks
    ---
    Delete a subnet

    READ permission required on cloud
    READ permission required on network
    READ permission required on subnet
    REMOVE permission required on subnet
    ---
    cloud_id:
      in: path
      required: true
      type: string
    network_id:
      in: path
      required: true
      type: string
    subnet_id:
      in: path
      required: true
      type: string
    """
    cloud_id = request.matchdict['cloud']
    subnet_id = request.matchdict['subnet']
    network_id = request.matchdict['network']

    auth_context = auth_context_from_request(request)

    # SEC
    auth_context.check_perm('cloud', 'read', cloud_id)
    auth_context.check_perm('network', 'read', network_id)
    auth_context.check_perm('network', 'edit_subnets', network_id)

    try:
        cloud = Cloud.objects.get(id=cloud_id, owner=auth_context.owner)
    except Cloud.DoesNotExist:
        raise CloudNotFoundError()
    try:
        network = Network.objects.get(id=network_id, cloud=cloud)
    except Network.DoesNotExist:
        raise NetworkNotFoundError()
    try:
        subnet = Subnet.objects.get(id=subnet_id, network=network)
        subnet.ctl.delete()
    except Subnet.DoesNotExist:
        raise SubnetNotFoundError()

    # Trigger a UI update.
    trigger_session_update(auth_context.owner, ['clouds'])
    return OK
예제 #3
0
 def _get_libcloud_subnet(self, subnet):
     networks = self.cloud.ctl.compute.connection.ex_list_networks()
     network = None
     for net in networks:
         if net.id == subnet.network.network_id:
             network = net
             break
     subnets = self.cloud.ctl.compute.connection.ex_list_subnets(network)
     for sub in subnets:
         if sub.id == subnet.subnet_id:
             return sub
     raise SubnetNotFoundError('Subnet %s with subnet_id \
         %s' % (subnet.name, subnet.subnet_id))