Example #1
0
 def test_getaddrinfo_fallback(self):
     """
     C{get_fqdn} falls back to C{socket.getaddrinfo} with the
     C{AI_CANONNAME} flag if C{socket.getfqdn} returns a local hostname.
     """
     self.addCleanup(setattr, socket, "getfqdn", socket.getfqdn)
     socket.getfqdn = lambda: "localhost6.localdomain6"
     self.assertNotIn("localhost", get_fqdn())
Example #2
0
 def test_default_fqdn(self):
     """
     C{get_fqdn} returns the output of C{socket.getfqdn} if it returns
     something sensible.
     """
     self.addCleanup(setattr, socket, "getfqdn", socket.getfqdn)
     socket.getfqdn = lambda: "foo.bar"
     self.assertEqual("foo.bar", get_fqdn())
Example #3
0
    def _handle_pre_exchange(self):
        """
        An exchange is about to happen.  If we don't have a secure id already
        set, and we have the needed information available, queue a registration
        message with the server.
        """
        # The point of storing this flag is that if we should *not* register
        # now, and then after the exchange we *should*, we schedule an urgent
        # exchange again.  Without this flag we would just spin trying to
        # connect to the server when something is clearly preventing the
        # registration.
        self._should_register = self.should_register()
        if not self._should_register:
            return

        # These are just to shorten the code.
        identity = self._identity
        account_name = identity.account_name

        if not account_name:
            self._reactor.fire("registration-failed", reason="unknown-account")
            return

        tags = identity.tags
        group = identity.access_group
        registration_key = identity.registration_key

        self._message_store.delete_all_messages()

        if not is_valid_tag_list(tags):
            tags = None
            logging.error("Invalid tags provided for registration.")

        message = {
            "type": "register",
            "hostname": get_fqdn(),
            "account_name": account_name,
            "computer_title": identity.computer_title,
            "registration_password": identity.registration_key,
            "tags": tags,
            "container-info": get_container_info(),
            "vm-info": get_vm_info()
        }

        if self._clone_secure_id:
            # We use the secure id here because the registration is encrypted
            # and the insecure id has been already exposed to unencrypted
            # http from the ping server. In addition it's more straightforward
            # to get the computer from the server through it than the insecure
            message["clone_secure_id"] = self._clone_secure_id

        if group:
            message["access_group"] = group

        server_api = self._message_store.get_server_api()
        # If we have juju data to send and if the server is recent enough to
        # know how to handle juju data, then we include it in the registration
        # message. We want to trigger the 3.3 server handler because client
        # version 14.01 has a different format for the juju-info field,
        # so this makes sure that the correct schema is used by the server
        # when validating our message.
        if self._juju_data and is_version_higher(server_api, b"3.3"):
            message["juju-info"] = {
                "environment-uuid": self._juju_data["environment-uuid"],
                "api-addresses": self._juju_data["api-addresses"],
                "machine-id": self._juju_data["machine-id"]
            }

        # The computer is a normal computer, possibly a container.
        with_word = "with" if bool(registration_key) else "without"
        with_tags = "and tags %s " % tags if tags else ""
        with_group = "in access group '%s' " % group if group else ""

        logging.info(u"Queueing message to register with account %r %s%s"
                     "%s a password." %
                     (account_name, with_group, with_tags, with_word))
        self._exchange.send(message)
Example #4
0
LOCAL_ACCOUNT_NAME = "standalone"

HOSTED_PASSWORD = ""
LOCAL_PASSWORD = ""

HOSTED = "hosted"
LOCAL = "local"
MANAGEMENT_TYPE = "management-type"
COMPUTER_TITLE = "computer-title"
LANDSCAPE_HOST = "landscape-host"
ACCOUNT_NAME = "account-name"
PASSWORD = "******"

DEFAULT_DATA = {
    MANAGEMENT_TYPE: NOT_MANAGED,
    COMPUTER_TITLE: get_fqdn(),
    HOSTED: {
        LANDSCAPE_HOST: HOSTED_LANDSCAPE_HOST,
        ACCOUNT_NAME: HOSTED_ACCOUNT_NAME,
        PASSWORD: HOSTED_PASSWORD
    },
    LOCAL: {
        LANDSCAPE_HOST: LOCAL_LANDSCAPE_HOST,
        ACCOUNT_NAME: LOCAL_ACCOUNT_NAME,
        PASSWORD: LOCAL_PASSWORD
    }
}


def derive_server_host_name_from_url(url):
    """