def reboot_by_tag(tag, schedule): """Reboot computers with this tag on this schedule""" api = LANDSCAPE_API(conf.LDS_URI, conf.LDS_KEY, conf.LDS_SECRET, conf.LDS_CA) computerlist = get_computers_by_tag(tag) computers = [] for computer in computerlist: computers.append(int(computer["id"])) api.reboot_computers(computers, schedule) # pylint: disable=no-member
def get_computers_by_tag(tag): """Get the computers with a specific tag""" import landscape_api.base.errors as ldserrors api = LANDSCAPE_API(conf.LDS_URI, conf.LDS_KEY, conf.LDS_SECRET, conf.LDS_CA) try: computers = api.get_computers(query="tag:" + tag) # pylint: disable=no-member except ldserrors.InvalidQueryError: computers = None return computers
def upgrade_by_tag(tag, deliver_after, packages=None, security_only=False, deliver_delay_window=0): """Upgrade all systems with the given tag""" if packages is None: packages = [] api = LANDSCAPE_API(conf.LDS_URI, conf.LDS_KEY, conf.LDS_SECRET, conf.LDS_CA) tag = "tag:" + tag result = api.upgrade_packages(tag, packages, security_only, deliver_after, deliver_delay_window) # pylint: disable=no-member return result
def init(self): if self.https_proxy: os.environ["https_proxy"] = self.https_proxy logger.debug( "[Landscape Importer Module]: Try to open a Landscape connection") uri = "https://landscape.canonical.com/api/" try: if self.ca: self.api = API(uri, self.key, self.secret, self.ca) else: self.api = API(uri, self.key, self.secret) except HTTPError, e: logger.debug("Landscape Module: Error %s" % e) raise
def _landscape_client(): env = EnvironmentConfig() return API( uri=env.uri, access_key=env.access_key, secret_key=env.secret_key, ssl_ca_file=env.ssl_ca_file)
def get_lds_computer_names(): """Get all the computers in LDS""" # https://landscape.canonical.com/static/doc/api/ from landscape_api.base import API as LANDSCAPE_API computers = LANDSCAPE_API(conf.LDS_URI, conf.LDS_KEY, conf.LDS_SECRET, conf.LDS_CA) computers = computers.get_computers() # pylint: disable=no-member computernames = [] for computer in computers: taglist = "" for tag in computer["tags"]: if tag.lower().startswith(conf.PREFIX.lower()): taglist += tag + " " computernames.append([ computer["hostname"].encode("utf-8").rstrip().lower(), 'lds', taglist.encode("utf-8").rstrip() ]) return computernames
def find_sys_with_package(sought_package): """"Look for systems with a specific package installed""" from landscape_api.base import API as LANDSCAPE_API # This file should be based on configuration.py.template import configuration as conf api = LANDSCAPE_API(conf.LDS_URI, conf.LDS_KEY, conf.LDS_SECRET, conf.LDS_CA) packages = api.get_packages(query="NOT tag:testapsw", names=sought_package) all_installed = set() hits = [] for package in packages: installed = package['computers']['installed'] if installed: for system in installed: all_installed.add(system) for system in all_installed: hits.append( api.get_computers(query="id:" + str(system))[0]['hostname'].encode("utf-8")) return hits
def main(): global api api = API(uri, key, secret) computer = find_this_host() if computer: return_tags(computer)