How to use get_device_list method in lisa

Best Python code snippet using lisa_python

dnacInterfaceSecurity.py

Source:dnacInterfaceSecurity.py Github

copy

Full Screen

...10 url = 'https://sandboxdnac.cisco.com/dna/system/api/v1/auth/token' # Endpoint URL11 resp = requests.post(url, auth=HTTPBasicAuth(DNAC_USER, DNAC_PASSWORD)) # Make the POST Request12 token = resp.json()['Token'] # Retrieve the Token from the returned JSONhahhah13 return token # Create a return statement to send the token back for later use14def get_device_list():15 """16 This function retrives a list of devices managed by DNAC17 """18 global token #Make the token variable available to all functions19 token = get_auth_token() # Get Token20 url = "https://sandboxdnac.cisco.com/api/v1/network-device"21 hdr = {'x-auth-token': token, 'content-type' : 'application/json'}22 resp = requests.get(url, headers=hdr) # Make the Get Request23 device_list = resp.json()24 get_device_id(device_list)25def get_device_id(device_json):26 for device in device_json['response']: # Loop through Device List and Retreive DeviceId27 print("Fetching Interfaces for Device ----> {}".format(device['hostname']))28 print('\n')29 get_device_int(device['id'])30 print('\n')31def get_device_int(device_id):32 """33 Building out function to retrieve device interface. Using requests.get to make a call to the network device Endpoint34 """35 url = "https://sandboxdnac.cisco.com/api/v1/interface"36 hdr = {'x-auth-token': token, 'content-type' : 'application/json'}37 querystring = {"macAddress": device_id} # Dynamically build the querey params to get device spefict Interface info38 resp = requests.get(url, headers=hdr, params=querystring) # Make the Get Request39 interface_info_json = resp.json()40 print_interface_info(interface_info_json)41def print_interface_info(interface_info):42 print("{0:25}{1:7}{2:20}{3:25}{4:15}{5:15}{6:25}". format("portName", "vlanId", "portMode", "portType", "duplex", "status", "description"))43 for intf in interface_info['response']:44 if intf['status'] == 'up' and intf['vlanId'] == "1" and intf['portMode'] == "access":45 print("{0:25}{1:7}{2:20}{3:25}{4:15}{5:15}{6:25}".46 format(str(intf['portName']),47 str(intf['vlanId']),48 str(intf['portMode']),49 str(intf['portType']),50 str(intf['duplex']),51 str(intf['status']),52 str(intf['description'])))53"""54Here we start the chain reaction.551. we call the get_device_list() function562. the get_device_list() function will use the get_auth_token() function to retrieve the token573. the get_device_list() function will retrieve the list of devices managed by DNAC584. the get_device_list() function will call the get_device_id() function 595. the get_device_id() function will retrieve the device id's of all the devices605. the get_device_id() function will call the get_device_int() function616. the get_device_int() function will retrieve all the interfaces from each device627. the get_device_int() function will call the print_interface_inf() function638. the print_interface_info() function will print a table with interface information64######LET'S GOOOOO!!!!!!######65"""...

Full Screen

Full Screen

admin.py

Source:admin.py Github

copy

Full Screen

...20 def get_gateway_name(self, obj):21 return obj.gateway.name22 get_gateway_name.short_description = "gateway"23 get_gateway_name.admin_order_field = "gateway__name"24 def get_device_list(self, obj):25 ces = ["%d. %s" % (i + 1, ce.device.name)26 for i, ce in enumerate(ConnectedDevice.objects.filter(27 gateway_instance=obj))]28 return "<br>".join(ces)29 get_device_list.short_description = "connected"30 get_device_list.allow_tags = True31class ServiceInstanceInline(admin.TabularInline):32 model = ServiceInstance33 fields = ("service",)34 readonly_fields = fields35 def has_add_permission(self, request):36 return False37class CharInstanceInline(admin.TabularInline):38 model = CharInstance...

Full Screen

Full Screen

forms.py

Source:forms.py Github

copy

Full Screen

1from django import forms2from .models import Device, Usage3class UsageEditForm(forms.ModelForm):4 class Meta:5 model = Usage6 fields = ['device_id',]7 labels = {8 'device_id': '장비 추가',9 }10 def __init__(self, *args, **kwargs):11 super(UsageEditForm, self).__init__(*args, **kwargs)12 get_device_list = []13 device_list = Device.objects.all()14 for i in device_list:15 usage_amount = Usage.objects.filter(device_id=i.device_id)16 if (i.amount - len(usage_amount)) > 0:17 get_device_list.append(i.device_id)18 #print("number", get_device_list)19 self.fields['device_id'].queryset = Device.objects.filter(device_id__in=get_device_list)20class DeviceNewForm(forms.ModelForm):21 class Meta:22 model = Device23 fields = ['category', 'sort', 'spec', 'amount', 'purchase_date', 'is_assets', 'etc']24 labels = {25 'category': '범주',26 'sort': '종류',27 'spec': '스펙',28 'amount': '총량',29 'purchase_date': '구매일자',30 'is_assets': '자산여부',31 'etc': '기타',32 }33 def __init__(self, *args, **kwargs):34 super(DeviceNewForm, self).__init__(*args, **kwargs)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful