Beispiel #1
0
def providers_save(socket_path,
                   api_version,
                   args,
                   show_json=False,
                   testmode=0):
    """Save a provider's profile to a TOML file

    :param socket_path: Path to the Unix socket to use for API communication
    :type socket_path: str
    :param api_version: Version of the API to talk to. eg. "0"
    :type api_version: str
    :param args: List of remaining arguments from the cmdline
    :type args: list of str
    :param show_json: Set to True to show the JSON output instead of the human readable output
    :type show_json: bool
    :param testmode: unused in this function
    :type testmode: int

    providers save <provider> <profile>

    """
    if len(args) == 0:
        log.error("save is missing the provider name")
        return 1
    if len(args) == 1:
        log.error("save is missing the profile name")
        return 1

    api_route = client.api_url(api_version, "/upload/providers")
    r = client.get_url_json(socket_path, api_route)
    results = r["providers"]
    if not results:
        return 0

    if show_json:
        print(json.dumps(results, indent=4))
    else:
        if args[0] not in results:
            log.error("%s is not a valid provider", args[0])
            return 1
        if args[1] not in results[args[0]]["profiles"]:
            log.error("%s is not a valid %s profile", args[1], args[0])
            return 1

        profile = {
            "provider": args[0],
            "profile": args[1],
            "settings": results[args[0]]["profiles"][args[1]]
        }
        with open(toml_filename(args[1]), "w") as f:
            f.write(toml.dumps(profile))

    return 0
Beispiel #2
0
def blueprints_save(socket_path, api_version, args, show_json=False):
    """Save the blueprint to a TOML file

    :param socket_path: Path to the Unix socket to use for API communication
    :type socket_path: str
    :param api_version: Version of the API to talk to. eg. "0"
    :type api_version: str
    :param args: List of remaining arguments from the cmdline
    :type args: list of str
    :param show_json: Set to True to show the JSON output instead of the human readable output
    :type show_json: bool

    blueprints save <blueprint,...>        Save the blueprint to a file, <blueprint-name>.toml
    """
    for blueprint in argify(args):
        api_route = client.api_url(
            api_version, "/blueprints/info/%s?format=toml" % blueprint)
        blueprint_toml = client.get_url_raw(socket_path, api_route)
        open(toml_filename(blueprint), "w").write(blueprint_toml)

    return 0
Beispiel #3
0
 def test_toml_filename(self):
     """Return the recipe's toml filename"""
     self.assertEqual(toml_filename("http server"), "http-server.toml")