networks: Handle unavailability of device

This commit is contained in:
Sunil Mohan Adapa 2015-10-17 15:11:30 +05:30 committed by James Valleroy
parent 8228440319
commit 96b98fae9f
3 changed files with 42 additions and 37 deletions

View File

@ -79,15 +79,13 @@ def show(request, uuid):
active_connection = None active_connection = None
# Device status # Device status
device = None
if active_connection and active_connection.get_devices(): if active_connection and active_connection.get_devices():
device = active_connection.get_devices()[0] device = active_connection.get_devices()[0]
else: else:
interface_name = connection_status['interface_name'] interface_name = connection_status['interface_name']
if interface_name: if interface_name:
device = network.get_device_by_interface_name(interface_name) device = network.get_device_by_interface_name(interface_name)
else:
# TODO: What to do in this situation?
raise RuntimeError('Could not get device status')
device_status = network.get_status_from_device(device) device_status = network.get_status_from_device(device)

View File

@ -74,6 +74,7 @@
</div> </div>
</div> </div>
{% if device %}
<h3>Device</h3> <h3>Device</h3>
<div class="list-group"> <div class="list-group">
@ -104,6 +105,7 @@
<span class="pull-right">{{ device.description }}</span> <span class="pull-right">{{ device.description }}</span>
</div> </div>
</div> </div>
{% endif %}
<h3>Physical Link</h3> <h3>Physical Link</h3>
@ -130,6 +132,7 @@
SSID SSID
<span class="pull-right">{{ connection.wireless.ssid }}</span> <span class="pull-right">{{ connection.wireless.ssid }}</span>
</div> </div>
{% if device %}
<div class="list-group-item"> <div class="list-group-item">
Speed Speed
<span class="pull-right">{{ device.wireless.bitrate }} Mbit/s</span> <span class="pull-right">{{ device.wireless.bitrate }} Mbit/s</span>
@ -138,6 +141,7 @@
Mode Mode
<span class="pull-right">{{ device.wireless.mode }}</span> <span class="pull-right">{{ device.wireless.mode }}</span>
</div> </div>
{% endif %}
{% if access_point.channel %} {% if access_point.channel %}
<div class="list-group-item"> <div class="list-group-item">
Signal strength Signal strength

View File

@ -161,6 +161,9 @@ def get_status_from_wifi_access_point(device, ssid):
"""Return the current status of an access point.""" """Return the current status of an access point."""
status = {} status = {}
if not ssid or not device:
return status
for access_point in device.get_access_points(): for access_point in device.get_access_points():
if access_point.get_ssid().get_data() == ssid: if access_point.get_ssid().get_data() == ssid:
status['strength'] = access_point.get_strength() status['strength'] = access_point.get_strength()