Logo Search packages:      
Sourcecode: ubuntu-sso-client version File versions  Download package

def ubuntu_sso::auth::AuthorisationClient::acquire_access_token_if_online (   self,
  description = None,
  store = False 
)

Check to see if we are online before trying to acquire

Definition at line 274 of file auth.py.

00274                                                                            :
        """Check to see if we are online before trying to acquire"""
        # Get NetworkManager state
        logger.debug("Checking whether we are online")
        try:
            nm = dbus.SystemBus().get_object('org.freedesktop.NetworkManager',
                                             '/org/freedesktop/NetworkManager',
                                             follow_name_owner_changes=True)
        except dbus.exceptions.DBusException:
            logger.warn("Unable to connect to NetworkManager. Trying anyway.")
            self.acquire_access_token(description, store)
        else:
            iface = dbus.Interface(nm, 'org.freedesktop.NetworkManager')

            def got_state(state):
                """Handler for when state() call succeeds."""
                if state == NM_STATE_CONNECTED:
                    logger.debug("We are online")
                    self.acquire_access_token(description, store)
                elif state == NM_STATE_CONNECTING:
                    logger.debug("We are currently going online")
                    # attach to NM's StateChanged signal
                    signal_match = nm.connect_to_signal(
                        signal_name="StateChanged",
                        handler_function=self.connection_established,
                        dbus_interface="org.freedesktop.NetworkManager")
                    # stash the details so the handler_function can get at them
                    self.saved_acquire_details = (signal_match, description,
                                                  store)
                else:
                    # NM is not connected: fail
                    logger.debug("We are not online")

            def got_error(error):
                """Handler for D-Bus errors when calling state()."""
                if error.get_dbus_name() == \
                        'org.freedesktop.DBus.Error.ServiceUnknown':
                    logger.debug("NetworkManager not available.")
                    self.acquire_access_token(description, store)
                else:
                    logger.error("Error contacting NetworkManager: %s" % \
                                     str(error))


            iface.state(reply_handler=got_state, error_handler=got_error)

    def connection_established(self, state):


Generated by  Doxygen 1.6.0   Back to index