~ubuntu-branches/ubuntu/vivid/landscape-client/vivid

« back to all changes in this revision

Viewing changes to landscape/lib/juju.py

  • Committer: Package Import Robot
  • Author(s): Andreas Hasenack
  • Date: 2014-11-20 21:03:56 UTC
  • mfrom: (1.1.34)
  • Revision ID: package-import@ubuntu.com-20141120210356-bdl520tpnxddxtm0
Tags: 14.11-0ubuntu1
* New upstream version:
  - Fix regression occurring when performing Landscape-driven release
    upgrades (LP: #1389686)
  - Fix regression occurring when switching the client between different
    Landscape servers (LP #376134)
  - Support reporting QEMU virtualization (LP: #1374501)
  - Bump Juju integration message format (LP: #1369635, LP: #1362506)
  - Drop provisioning registration message (LP: #1362506)
  - Drop cloud registration message (LP: #1342646)
  - Fix handling broken packages (LP: #1326940)
  - Add new Swift usage message type (LP: #1320236)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
1
2
import json
2
3
import logging
3
 
import os.path
4
4
 
5
5
from landscape.lib.fs import read_file
6
6
 
7
7
 
8
8
def get_juju_info(config):
9
9
    """
10
 
    Returns the Juju info or C{None} if the path referenced from
11
 
    L{config} is not a file or that file isn't valid JSON.
 
10
    Returns available Juju info or C{None} if the path referenced from
 
11
    L{config} is not a valid file.
12
12
    """
13
 
    juju_filename = config.juju_filename
14
 
    if not os.path.isfile(juju_filename):
15
 
        return None
16
 
    json_contents = read_file(juju_filename)
 
13
    if not os.path.exists(config.juju_filename):
 
14
        return
 
15
 
 
16
    json_contents = read_file(config.juju_filename)
17
17
    try:
18
18
        juju_info = json.loads(json_contents)
 
19
    # Catch any error the json lib could throw, because we don't know or
 
20
    # care what goes wrong - we'll display a generic error message and
 
21
    # return None in any case.
19
22
    except Exception:
20
23
        logging.exception(
21
 
            "Error attempting to read JSON from %s" % juju_filename)
 
24
            "Error attempting to read JSON from %s" % config.juju_filename)
22
25
        return None
23
 
    else:
24
 
        if "api-addresses" in juju_info:
25
 
            juju_info["api-addresses"] = juju_info["api-addresses"].split()
26
 
        return juju_info
 
26
 
 
27
    juju_info["api-addresses"] = juju_info["api-addresses"].split()
 
28
    return juju_info