SUSE Manager/temporary-channel-access-via-activation-key

From MicroFocusInternationalWiki
Revision as of 12:06, 18 October 2016 by Lucidd (Talk | contribs) (Example via Python)

Jump to: navigation, search

This page describes how a salt minion registered with SUSE Manager can request temporary access to channels associated with an Activation Key. This can be useful for giving for example a docker build access to SUSE Manager channels.

For this Feature we introduced the new XMLRPC function activationkey.listChannels with the following parameters.

  • the minionId of the minion calling the function.
  • a minion specific password which will be automatically available to each minion via its pillar data.
  • the activation key containing the channels to be accessed.

The returned list will contain a structure for each channel containing

  • channel label
  • channel name
  • channel url
  • temporarily valid access token for the channel

For more details see the SUSE Manager XMLRPC API Documentation for the activationkey.listChannel function.

Example via Python

import xmlrpclib
import yaml
import salt.client
import subprocess

# Accessing minion id and pillar data via python library
caller = salt.client.Caller()
MANAGER_HOST = caller.cmd("config.get", "master")
MINION_ID = caller.cmd("config.get", "id")
MACHINE_PASSWORD = caller.cmd("pillar.get", "machine_password")

# Accessing minin id and pillar data via salt-call command line (this is useful for languages that do not have a library for salt).
MANAGER_HOST = subprocess.check_output(["salt-call", "--local", "--out", "newline_values_only", "config.get", "master"]).strip()
MINION_ID = subprocess.check_output(["salt-call", "--local", "--out", "newline_values_only", "config.get", "id"])
MACHINE_PASSWORD = subprocess.check_output(["salt-call", "--out", "newline_values_only", "pillar.get", "machine_password"])

MANAGER_URL = "http://{0}/rpc/api".format(MANAGER_HOST)

client = xmlrpclib.Server(MANAGER_URL, verbose=0)

result = client.activationkey.listChannels(MINION_ID, MACHINE_PASSWORD, ACTIVATION_KEY)
for item in result:
  print yaml.safe_dump(item, default_flow_style=False)