Custom initial method:
            * ensure device exists and store it in an instance attribute
            * change queryset to return only devices of current node
347373
def initial(self, request, *args, **kwargs):
        
        super(BaseInterfaceList, self).initial(request, *args, **kwargs)

        # ensure device exists
        try:
            self.device = Device.objects.accessible_to(request.user)\
                        .get(pk=self.kwargs.get('pk', None))
        except Device.DoesNotExist:
            raise Http404(_('Device not found.'))

        # check permissions on device (for interface creation)
        self.check_object_permissions(request, self.device)

        # return only interfaces of current device
        self.queryset = self.model.objects.filter(device_id=self.device.id)\
                        .accessible_to(self.request.user)
646691
def exclude_current_instance(self, queryset):
        
        if self.instance is not None:
            return queryset.exclude(pk=self.instance.pk)
        return queryset
171632
def getDevice(self, id):
        
        return next(iter([d for d in self.devices.values() if d.deviceId == id]), None)
1034047
def exists(self):
        
        self_object = self.query.filter_by(id=self.id).first()
        if self_object is None:
            return False
        return True
1039686
def start_device(name, frontend, backend):
    
    device = getattr(devices, name)
    device(frontend, backend)
535468
static DeviceInfo initialize(Context context) {
        if (thisInstance_ == null) {
            thisInstance_ = new DeviceInfo(context);
        }
        return thisInstance_;
    }
1372604
def as_device(self):
        
        if self.node_type != NodeType.DEVICE:
            raise ValueError(
                'Cannot convert to `Device`, node_type is not a device.')
        return self._origin.Device(self._data)
535355
def init(opts):
    '''
    
    '''
    NETWORK_DEVICE.update(salt.utils.napalm.get_device(opts))
    DETAILS['initialized'] = True
    return True
1034983
def obtain_all_devices(my_devices):
    """"""
    new_devices = {}
    for device_name, device_or_group in my_devices.items():
        # Skip any groups
        if not isinstance(device_or_group, list):
            new_devices[device_name] = device_or_group
    return new_devices
343452
def get_devices(self):
        
        def process_result(result):
            return [self.get_device(dev) for dev in result]

        return Command('get', [ROOT_DEVICES], process_result=process_result)
382174
function Device (client, opts) {
  var self = this
  if (!(self instanceof Device)) return new Device(client, opts)
  if (!opts) opts = {}

  self.client = client
}
359416
def initial(self, request, *args, **kwargs):
        
        super(NodeImageList, self).initial(request, *args, **kwargs)
        # ensure node exists
        self.node = get_queryset_or_404(
            Node.objects.published().accessible_to(request.user),
            {'slug': self.kwargs['slug']}
        )
        # check permissions on node (for image creation)
        self.check_object_permissions(request, self.node)
746581
def initial(self, request, *args, **kwargs):
        
        super(NodeRelationViewMixin, self).initial(request, *args, **kwargs)
        self.node = get_object_or_404(Node, **{'slug': self.kwargs['slug']})
        self.queryset = self.model.objects.filter(node_id=self.node.id)
1097800
def _set_current_context(self, device_id):
        
        if device_id not in self._all_index_update_counts:
            self._all_index_update_counts[device_id] = {}
        self._index_update_count = self._all_index_update_counts[device_id]
31902
def first_or_new(self, _attributes=None, **attributes):
        
        if _attributes is not None:
            attributes.update(_attributes)

        instance = self._query.where(attributes).first()

        if instance is None:
            instance = self._related.new_instance()
            self._set_foreign_attributes_for_create(instance)

        return instance
898785
def filter_unnecessary_ports(query, device_owners=None, vnic_type=None,
                             active=True):
    
    query = (query
             .filter_unbound_ports()
             .filter_by_device_owner(device_owners)
             .filter_by_device_id()
             .filter_unmanaged_physnets())
    if active:
        query = query.filter_inactive_ports()
    if vnic_type:
        query = query.filter_by_vnic_type(vnic_type)
    return query
1227123
def get_device_by_name(self, device_name):
        

        # Find the device for the vera device name we are interested in
        found_device = None
        for device in self.get_devices():
            if device.name == device_name:
              found_device = device
              # found the first (and should be only) one so we will finish
              break

        if found_device is None:
            logger.debug('Did not find device with {}'.format(device_name))

        return found_device