~tribaal/charms/trusty/landscape-client/put-install-hook-in-its-own-file

« back to all changes in this revision

Viewing changes to hooks/common.py

Make sure the juju-info file is written to disk before trying to
register the client with the server, so that information about the
Juju environment is sent to the server at registration time.

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
                # backwards compatibility with landscape-client in precise.
72
72
                setattr(self.config, "registration_password", value)
73
73
        self.config.write()
74
 
        return self.try_to_register()
 
74
        is_configured_enough = all([
 
75
            self.config.get("account_name"),
 
76
            self.config.get("computer_title"),
 
77
            os.path.exists(
 
78
                os.path.join(self.config.data_path, "juju-info.json"))])
 
79
        if is_configured_enough:
 
80
            return self.try_to_register()
 
81
        else:
 
82
            print ("Need account-name, computer-title and juju-info to"
 
83
                   " proceed, skipping")
 
84
            return 0
75
85
 
76
86
    def clear_registration(self):
77
87
        """
106
116
        if configured:
107
117
            print "Client already registered, skipping"
108
118
            return 0
109
 
        if not config.get("account_name") or not config.get("computer_title"):
110
 
            print "Need account-name and computer-title to proceed, skipping"
111
 
            return 0
112
119
        try:
113
120
            setup(config)
114
121
        except ConfigurationError as error: