def run(self):
        orgName = self.get_option('org')
        envName = self.get_option('environment')
        keyName = self.get_option('name')
        keyDescription = self.get_option('description')
        usageLimit = self.get_option('usage_limit')
        view_label = self.get_option("view_label")
        view_name = self.get_option("view_name")
        view_id = self.get_option("view_id")

        if usageLimit is None:
            usageLimit = -1
        else:
            if int(usageLimit) <= 0:
                print >> sys.stderr, _(
                    "Usage limit [ %s ] must be higher than one") % usageLimit
                return os.EX_DATAERR

        environment = get_environment(orgName, envName)

        if view_name or view_label or view_id:
            view = get_content_view(orgName, view_label, view_name, view_id)
            view_id = view['id']
        else:
            view_id = None

        key = self.api.create(environment['id'], keyName, keyDescription,
                              usageLimit, view_id)
        test_record(key,
                    _("Successfully created activation key [ %s ]") % keyName,
                    _("Could not create activation key [ %s ]") % keyName)
Exemple #2
0
    def run(self):
        org_name = self.get_option('org')
        group_name = self.get_option('name')
        env_name = self.get_option('environment')
        view_label = self.get_option('view_label')
        view_id = self.get_option('view_id')
        view_name = self.get_option('view_name')

        system_group = get_system_group(org_name, group_name)
        system_group_id = system_group['id']

        if env_name:
            environment = get_environment(org_name, env_name)
            env_id = environment["id"]
        else:
            env_id = None

        if view_name or view_id or view_label:
            view = get_content_view(org_name, view_label, view_name, view_id)
            view_id = view["id"]
        else:
            view_id = None

        group = self.api.update_systems(org_name, system_group_id, env_id,
                                        view_id)

        if group:
            print (_("Successfully updated systems in group [ %s ]" % group["name"]))
            return os.EX_OK
        else:
            return os.EX_DATAERR
Exemple #3
0
    def run(self):
        envName = self.get_option('environment')
        orgName = self.get_option('org')

        keys = self.get_keys_for_organization(orgName) \
            if envName == None else self.get_keys_for_environment(orgName, envName)

        if not keys:
            if envName == None:
                print _("No keys found in organization [ %s ]") % orgName
            else:
                print _("No keys found in organization [ %(orgName)s ] environment [ %(envName)s ]") \
                    % {'orgName':orgName, 'envName':envName}

            return os.EX_OK

        for k in keys:
            if k['usage_limit'] is None or k['usage_limit'] == -1:
                k['usage'] = str(k['usage_count'])
            else:
                k['usage'] = str(k['usage_count']) + '/' + str(k['usage_limit'])
            if k['content_view_id']:
                view = get_content_view(orgName, view_id=k['content_view_id'])
                k['content_view'] = view["label"]

        self.printer.add_column('id', _("ID"))
        self.printer.add_column('name', _("Name"))
        self.printer.add_column('description', _("Description"), multiline=True)
        self.printer.add_column('usage', _("Usage"))
        self.printer.add_column('environment_id', _("Environment ID"))
        self.printer.add_column('content_view', _("Content View Label"))

        self.printer.set_header(_("Activation Key List"))
        self.printer.print_items(keys)
        return os.EX_OK
Exemple #4
0
    def run(self):
        org_name = self.get_option('org')
        group_name = self.get_option('name')
        env_name = self.get_option('environment')
        view_label = self.get_option('view_label')
        view_id = self.get_option('view_id')
        view_name = self.get_option('view_name')

        system_group = get_system_group(org_name, group_name)
        system_group_id = system_group['id']

        if env_name:
            environment = get_environment(org_name, env_name)
            env_id = environment["id"]
        else:
            env_id = None

        if view_name or view_id or view_label:
            view = get_content_view(org_name, view_label, view_name, view_id)
            view_id = view["id"]
        else:
            view_id = None

        group = self.api.update_systems(org_name, system_group_id, env_id,
                                        view_id)

        if group:
            print(
                _("Successfully updated systems in group [ %s ]" %
                  group["name"]))
            return os.EX_OK
        else:
            return os.EX_DATAERR
Exemple #5
0
    def run(self):
        org_name = self.get_option('org')
        env_name = self.get_option('environment')
        async = self.get_option('async')
        view_label = self.get_option('label')
        view_id = self.get_option('id')
        view_name = self.get_option('name')

        view = get_content_view(org_name, view_label, view_name, view_id)

        environment = get_environment(org_name, env_name)
        env_id = environment["id"]

        task = self.api.promote(view["id"], env_id)

        if not async:
            task = AsyncTask(task)
            run_spinner_in_bg(wait_for_async_task, [task],
                    message=_("Promoting content view, please wait..."))

            return evaluate_task_status(task,
                failed = _("View [ %s ] promotion failed") % view["name"],
                ok =     _("Content view [ %(view)s ] promoted to environment [ %(env)s ]") %
                    {"view": view["name"], "env": environment["name"]},
            )

        else:
            print _("Promotion task [ %s ] was successfully created.") % (task["uuid"])
            return os.EX_OK
Exemple #6
0
    def run(self):
        name = self.get_option('name')
        org = self.get_option('org')
        environment_name = self.get_option('environment')
        activation_keys = self.get_option('activationkey')
        release = self.get_option('release')
        sla = self.get_option('sla')
        facts = dict(self.get_option('fact') or {})
        view_label = self.get_option("content_view")

        environment_id = None
        if environment_name is not None:
            environment_id = get_environment(org, environment_name)['id']

        view_id = None
        if view_label is not None:
            view = get_content_view(org, view_label)
            view_id = view["id"]

        system = self.api.register(name, org, environment_id, activation_keys,
                                   'system', release, sla, facts, view_id)

        test_record(system,
            _("Successfully registered system [ %s ]") % name,
            _("Could not register system [ %s ]") % name
        )
Exemple #7
0
    def run(self):
        org_name = self.get_option('org')
        env_name = self.get_option('env')
        view_label = self.get_option('label')
        view_id = self.get_option('id')
        view_name = self.get_option('name')

        view = get_content_view(org_name, view_label, view_name, view_id)
        if env_name:
            env = get_environment(org_name, env_name)
            env_id = env["id"] if env else None
        else:
            env = get_library(org_name)
            env_id = env["id"] if env else None

        view = self.api.show(org_name, view["id"], env_id)

        view["environments"] = ', '.join(str(x) for x in view["environments"])

        self.printer.add_column('id', _("ID"))
        self.printer.add_column('name', _("Name"))
        self.printer.add_column('label', _("Label"))
        self.printer.add_column('description', _("Description"), multiline=True)
        self.printer.add_column('organization', _('Org'))
        self.printer.add_column('definition', _("Definition"))
        self.printer.add_column('environments', _('Environments'),
                                multiline=True)
        self.printer.add_column('versions', _("Versions"), multiline=True)
        self.printer.add_column('repositories', _('Repos'),
                                multiline=True)

        self.printer.set_header(_("ContentView Info"))
        self.printer.print_item(view)
        return os.EX_OK
Exemple #8
0
    def run(self):
        orgName = self.get_option('org')
        envName = self.get_option('environment')
        keyName = self.get_option('name')
        keyDescription = self.get_option('description')
        usageLimit = self.get_option('usage_limit')
        view_label = self.get_option("view_label")
        view_name = self.get_option("view_name")
        view_id = self.get_option("view_id")

        if usageLimit is None:
            usageLimit = -1
        else:
            if int(usageLimit) <= 0:
                print >> sys.stderr, _("Usage limit [ %s ] must be higher than one") % usageLimit
                return os.EX_DATAERR

        environment = get_environment(orgName, envName)

        if view_name or view_label or view_id:
            view = get_content_view(orgName, view_label, view_name, view_id)
            view_id = view['id']
        else:
            view_id = None


        key = self.api.create(environment['id'], keyName, keyDescription, usageLimit, view_id)
        test_record(key,
            _("Successfully created activation key [ %s ]") % keyName,
            _("Could not create activation key [ %s ]") % keyName
        )
    def run(self):
        orgName = self.get_option('org')
        keyName = self.get_option('name')

        keys = self.api.activation_keys_by_organization(orgName, keyName)

        if len(keys) == 0:
            print >> sys.stderr, _("Could not find activation key [ %s ]") % keyName
            return os.EX_DATAERR
        for akey in keys:
            akey["pools"] = "[ "+ ", ".join([pool["cp_id"] for pool in akey["pools"]]) +" ]"

        if keys[0]['content_view_id']:
            view = get_content_view(orgName, view_id=keys[0]['content_view_id'])
            keys[0]['content_view'] = view['label']

        self.printer.add_column('id', _("ID"))
        self.printer.add_column('name', _("Name"))
        self.printer.add_column('description', _("Description"), multiline=True)
        self.printer.add_column('usage_limit', _("Usage Limit"), \
            value_formatter=lambda x: "unlimited" if x == -1 else x)
        self.printer.add_column('environment_id', _("Environment ID"))
        self.printer.add_column('system_template_id', _("System Template ID"))
        self.printer.add_column('content_view', _("Content View"), value_formatter=lambda x: "[ %s ]" % x)
        self.printer.add_column('pools', _("Pools"), multiline=True, show_with=printer.VerboseStrategy)
        self.printer.set_header(_("Activation Key Info"))
        self.printer.print_item(keys[0])
        return os.EX_OK
Exemple #10
0
    def run(self):
        org_name = self.get_option('org')
        env_name = self.get_option('env')
        view_label = self.get_option('label')
        view_id = self.get_option('id')
        view_name = self.get_option('name')

        view = get_content_view(org_name, view_label, view_name, view_id)
        if env_name:
            env = get_environment(org_name, env_name)
            env_id = env["id"] if env else None
        else:
            env = get_library(org_name)
            env_id = env["id"] if env else None

        view = self.api.show(org_name, view["id"], env_id)

        self.printer.add_column('id', _("ID"))
        self.printer.add_column('name', _("Name"))
        self.printer.add_column('label', _("Label"))
        self.printer.add_column('description', _("Description"), multiline=True)
        self.printer.add_column('organization', _('Org'))
        self.printer.add_column('definition', _("Definition"))
        self.printer.add_column('environments', _('Environments'),
                                multiline=True)
        self.printer.add_column('versions', _("Versions"), multiline=True)
        self.printer.add_column('repositories', _('Repos'),
                                multiline=True)

        self.printer.set_header(_("ContentView Info"))
        self.printer.print_item(view)
        return os.EX_OK
Exemple #11
0
    def run(self):
        org_name = self.get_option('org')
        env_name = self.get_option('environment')
        async = self.get_option('async')
        view_label = self.get_option('label')
        view_id = self.get_option('id')
        view_name = self.get_option('name')

        view = get_content_view(org_name, view_label, view_name, view_id)

        environment = get_environment(org_name, env_name)
        env_id = environment["id"]

        task = self.api.promote(view["id"], env_id)

        if not async:
            task = AsyncTask(task)
            run_spinner_in_bg(wait_for_async_task, [task],
                    message=_("Promoting content view, please wait..."))

            return evaluate_task_status(task,
                failed = _("View [ %s ] promotion failed") % view["name"],
                ok =     _("Content view [ %(view)s ] promoted to environment [ %(env)s ]") %
                    {"view": view["name"], "env": environment["name"]},
            )

        else:
            print _("Promotion task [ %s ] was successfully created.") % (task["uuid"])
            return os.EX_OK
    def run(self):
        orgName = self.get_option('org')
        envName = self.get_option('environment')
        keyName = self.get_option('name')
        keyDescription = self.get_option('description')
        templateName = self.get_option('template')
        usageLimit = self.get_option('usage_limit')
        view_label = self.get_option('view')

        if usageLimit is None:
            usageLimit = -1
        else:
            if int(usageLimit) <= 0:
                print >> sys.stderr, _("Usage limit [ %s ] must be higher than one") % usageLimit
                return os.EX_DATAERR

        environment = get_environment(orgName, envName)

        try:
            templateId = self.get_template_id(environment['id'], templateName)
        except OptionException:
            print >> sys.stderr, _("Couldn't find template [ %s ]") % templateName
            return os.EX_DATAERR

        if view_label is not None:
            view = get_content_view(orgName, view_label)
            view_id = view['id']
        else:
            view_id = None

        key = self.api.create(environment['id'], keyName, keyDescription, usageLimit, templateId, view_id)
        test_record(key,
            _("Successfully created activation key [ %s ]") % keyName,
            _("Could not create activation key [ %s ]") % keyName
        )
Exemple #13
0
    def run(self):
        name = self.get_option('name')
        org = self.get_option('org')
        environment_name = self.get_option('environment')
        activation_keys = self.get_option('activationkey')
        release = self.get_option('release')
        sla = self.get_option('sla')
        facts = dict(self.get_option('fact') or {})
        view_name = self.get_option("view_name")
        view_label = self.get_option("view_label")
        view_id = self.get_option("view_id")

        environment_id = None
        if environment_name is not None:
            environment_id = get_environment(org, environment_name)['id']

        if view_label or view_name:
            view = get_content_view(org, view_label, view_name)
            view_id = view["id"]

        system = self.api.register(name, org, environment_id, activation_keys,
                                   'system', release, sla, facts, view_id)

        test_record(system,
                    _("Successfully registered system [ %s ]") % name,
                    _("Could not register system [ %s ]") % name)
Exemple #14
0
    def run(self):
        orgName = self.get_option("org")
        envName = self.get_option("environment")
        prodName = self.get_option("product")
        prodLabel = self.get_option("product_label")
        prodId = self.get_option("product_id")
        listDisabled = self.has_option("disabled")
        content_view_name = self.get_option("view_name")
        content_view_label = self.get_option("view_label")
        content_view_id = self.get_option("view_id")

        batch_add_columns(
            self.printer,
            {"id": _("ID")},
            {"name": _("Name")},
            {"label": _("Label")},
            {"content_type": _("Type")},
            {"package_count": _("Package Count")},
            {"puppet_module_count": _("Puppet Module Count")},
        )

        self.printer.add_column("last_sync", _("Last Sync"), formatter=format_sync_time)

        if content_view_name or content_view_label or content_view_id:
            content_view = get_content_view(orgName, content_view_label, content_view_name, content_view_id)
            content_view_id = content_view["id"]

        prodIncluded = prodName or prodLabel or prodId
        if prodIncluded and envName:
            env = get_environment(orgName, envName)
            prod = get_product(orgName, prodName, prodLabel, prodId)

            self.printer.set_header(
                _("Repo List For Org %(org_name)s Environment %(env_name)s Product %(prodName)s")
                % {"org_name": orgName, "env_name": env["name"], "prodName": prodName}
            )
            repos = self.api.repos_by_env_product(env["id"], prod["id"], None, listDisabled, content_view_id)
            self.printer.print_items(repos)

        elif prodIncluded:
            prod = get_product(orgName, prodName, prodLabel, prodId)
            self.printer.set_header(
                _("Repo List for Product %(prodName)s in Org %(orgName)s ") % {"prodName": prodName, "orgName": orgName}
            )
            repos = self.api.repos_by_product(orgName, prod["id"], listDisabled)
            self.printer.print_items(repos)

        else:
            env = get_environment(orgName, envName)
            self.printer.set_header(
                _("Repo List For Org %(orgName)s Environment %(env_name)s")
                % {"orgName": orgName, "env_name": env["name"]}
            )
            repos = self.api.repos_by_org_env(orgName, env["id"], listDisabled, content_view_id)
            self.printer.print_items(repos)

        return os.EX_OK
Exemple #15
0
    def run(self):
        orgName = self.get_option("org")
        keyName = self.get_option("name")
        envName = self.get_option("env")
        newKeyName = self.get_option("new_name")
        keyDescription = self.get_option("description")
        usageLimit = self.get_option("usage_limit")
        add_poolids = self.get_option("add_poolid") or []
        remove_poolids = self.get_option("remove_poolid") or []
        view_label = self.get_option("view_label")
        view_name = self.get_option("view_name")
        view_id = self.get_option("view_id")
        remove_view = self.get_option("remove_view")

        if envName != None:
            environment = get_environment(orgName, envName)
        else:
            environment = None

        keys = self.api.activation_keys_by_organization(orgName, keyName)
        if len(keys) == 0:
            print >> sys.stderr, _("Could not find activation key [ %s ]") % keyName
            return os.EX_DATAERR
        key = keys[0]

        if remove_view:
            view_id = False
        elif view_name or view_label or view_id:
            view = get_content_view(orgName, view_label, view_name, view_id)
            view_id = view["id"]
        else:
            view_id = None

        key = self.api.update(
            orgName,
            key["id"],
            environment["id"] if environment != None else None,
            newKeyName,
            keyDescription,
            usageLimit,
            view_id,
        )

        for poolid in add_poolids:
            self.api.add_pool(orgName, key["id"], poolid)
        for poolid in remove_poolids:
            self.api.remove_pool(orgName, key["id"], poolid)

        if key != None:
            print _("Successfully updated activation key [ %s ]") % key["name"]
            return os.EX_OK
        else:
            return os.EX_DATAERR
Exemple #16
0
    def run(self):
        mode = get_katello_mode()
        orgName = self.get_option('org')
        keyName = self.get_option('name')
        if mode == 'katello':
            envName = self.get_option('env')
        else:
            envName = None
        newKeyName = self.get_option('new_name')
        keyDescription = self.get_option('description')
        usageLimit = self.get_option('usage_limit')
        add_poolids = self.get_option('add_poolid') or []
        remove_poolids = self.get_option('remove_poolid') or []
        if mode == 'katello':
            view_label = self.get_option("view_label")
            view_name = self.get_option("view_name")
            view_id = self.get_option("view_id")
        else:
            view_label = None
            view_name = None
            view_id = None

        if envName != None:
            environment = get_environment(orgName, envName)
        else:
            environment = None

        keys = self.api.activation_keys_by_organization(orgName, keyName)
        if len(keys) == 0:
            print >> sys.stderr, _("Could not find activation key [ %s ]") % keyName
            return os.EX_DATAERR
        key = keys[0]

        if view_name or view_label or view_id:
            view = get_content_view(orgName, view_label, view_name, view_id)
            view_id = view['id']
        else:
            view_id = None

        key = self.api.update(orgName, key['id'], environment['id'] if environment != None else None,
            newKeyName, keyDescription, usageLimit, view_id)

        for poolid in add_poolids:
            self.api.add_pool(orgName, key['id'], poolid)
        for poolid in remove_poolids:
            self.api.remove_pool(orgName, key['id'], poolid)

        if key != None:
            print _("Successfully updated activation key [ %s ]") % key['name']
            return os.EX_OK
        else:
            return os.EX_DATAERR
    def run(self):
        org_name           = self.get_option('org')
        def_label          = self.get_option('label')
        def_name           = self.get_option('name')
        def_id             = self.get_option('id')
        content_view_label = self.get_option('view')

        cvd = get_cv_definition(org_name, def_label, def_name, def_id)
        content_view = get_content_view(org_name, content_view_label)

        content_views = self.def_api.content_views(cvd['id'])
        content_views = [f['id'] for f in content_views]
        self.update_content_views(cvd, content_views, content_view)
        return os.EX_OK
    def run(self):
        orgName = self.get_option('org')
        keyName = self.get_option('name')
        envName = self.get_option('env')
        newKeyName = self.get_option('new_name')
        keyDescription = self.get_option('description')
        usageLimit = self.get_option('usage_limit')
        add_poolids = self.get_option('add_poolid') or []
        remove_poolids = self.get_option('remove_poolid') or []
        view_label = self.get_option("view_label")
        view_name = self.get_option("view_name")
        view_id = self.get_option("view_id")
        remove_view = self.get_option("remove_view")

        if envName != None:
            environment = get_environment(orgName, envName)
        else:
            environment = None

        keys = self.api.activation_keys_by_organization(orgName, keyName)
        if len(keys) == 0:
            print >> sys.stderr, _(
                "Could not find activation key [ %s ]") % keyName
            return os.EX_DATAERR
        key = keys[0]

        if remove_view:
            view_id = False
        elif view_name or view_label or view_id:
            view = get_content_view(orgName, view_label, view_name, view_id)
            view_id = view['id']
        else:
            view_id = None

        key = self.api.update(
            orgName, key['id'],
            environment['id'] if environment != None else None, newKeyName,
            keyDescription, usageLimit, view_id)

        for poolid in add_poolids:
            self.api.add_pool(orgName, key['id'], poolid)
        for poolid in remove_poolids:
            self.api.remove_pool(orgName, key['id'], poolid)

        if key != None:
            print _("Successfully updated activation key [ %s ]") % key['name']
            return os.EX_OK
        else:
            return os.EX_DATAERR
    def run(self):
        orgName = self.get_option('org')
        keyName = self.get_option('name')
        envName = self.get_option('env')
        newKeyName = self.get_option('new_name')
        keyDescription = self.get_option('description')
        templateName = self.get_option('template')
        usageLimit = self.get_option('usage_limit')
        add_poolids = self.get_option('add_poolid') or []
        remove_poolids = self.get_option('remove_poolid') or []
        view_label = self.get_option("view")

        if envName != None:
            environment = get_environment(orgName, envName)
        else:
            environment = None

        keys = self.api.activation_keys_by_organization(orgName, keyName)
        if len(keys) == 0:
            print >> sys.stderr, _("Could not find activation key [ %s ]") % keyName
            return os.EX_DATAERR
        key = keys[0]

        if view_label is not None:
            view = get_content_view(orgName, view_label)
            view_id = view['id']
        else:
            view_id = None

        try:
            templateId = self.get_template_id(key['environment_id'], templateName)
        except OptionException:
            print >> sys.stderr, _("Couldn't find template [ %s ]") % (templateName)
            return os.EX_DATAERR

        key = self.api.update(orgName, key['id'], environment['id'] if environment != None else None,
            newKeyName, keyDescription, templateId, usageLimit, view_id)

        for poolid in add_poolids:
            self.api.add_pool(orgName, key['id'], poolid)
        for poolid in remove_poolids:
            self.api.remove_pool(orgName, key['id'], poolid)

        if key != None:
            print _("Successfully updated activation key [ %s ]") % key['name']
            return os.EX_OK
        else:
            return os.EX_DATAERR
Exemple #20
0
    def run(self):
        org_name = self.get_option('org')
        view_label = self.get_option('label')
        view_id = self.get_option('id')
        view_name = self.get_option('name')

        view = get_content_view(org_name, view_label, view_name, view_id)

        if len(view["environments"]) > 1:
            print _("Content view [ %s ] cannot be deleted since it is in non-library environments.") \
                    % (view["name"])
            return os.EX_DATAERR
        else:
            self.api.delete(org_name, view["id"])
            print _("Content view [ %s ] was successfully deleted.") % (view["name"])
            return os.EX_OK
Exemple #21
0
    def run(self):
        org_name = self.get_option('org')
        env_name = self.get_option('environment')
        sys_name = self.get_option('name')
        new_name = self.get_option('new_name')
        new_environment_name = self.get_option('new_environment')
        new_description = self.get_option('description')
        new_location = self.get_option('location')
        new_release = self.get_option('release')
        new_sla = self.get_option('sla')
        sys_uuid = self.get_option('uuid')
        view_name = self.get_option("view_name")
        view_label = self.get_option("view_label")
        view_id = self.get_option("view_id")
        remove_view = self.get_option("remove_view")

        system = get_system(org_name, sys_name, env_name, sys_uuid)
        new_environment = get_environment(org_name, new_environment_name)

        updates = {}
        if new_name:
            updates['name'] = new_name
        if new_description:
            updates['description'] = new_description
        if new_location:
            updates['location'] = new_location
        if new_release:
            updates['releaseVer'] = new_release
        if new_sla:
            updates['serviceLevel'] = new_sla
        if new_environment_name:
            new_environment = get_environment(org_name, new_environment_name)
            updates['environment_id'] = new_environment['id']

        if remove_view:
            updates["content_view_id"] = False
        elif view_label or view_name or view_id:
            updates["content_view_id"] = get_content_view(org_name, view_label,
                                                          view_name, view_id)["id"]

        response = self.api.update(system['uuid'], updates)

        test_record(response,
            _("Successfully updated system [ %s ]") % system['name'],
            _("Could not update system [ %s ]") % system['name']
        )
    def run(self):
        org_name           = self.get_option('org')
        def_label          = self.get_option('label')
        def_name           = self.get_option('name')
        def_id             = self.get_option('id')
        content_view_label = self.get_option('view_label')
        content_view_name  = self.get_option('view_name')
        content_view_id    = self.get_option('view_id')

        cvd = get_cv_definition(org_name, def_label, def_name, def_id)
        content_view = get_content_view(org_name, content_view_label, content_view_name,
                                        content_view_id)

        content_views = self.api.content_views(cvd['id'])
        content_views = [f['id'] for f in content_views]
        self.update_content_views(cvd, content_views, content_view)
        return os.EX_OK
Exemple #23
0
    def run(self):
        org_name = self.get_option('org')
        env_name = self.get_option('environment')
        sys_name = self.get_option('name')
        new_name = self.get_option('new_name')
        new_environment_name = self.get_option('new_environment')
        new_description = self.get_option('description')
        new_location = self.get_option('location')
        new_release = self.get_option('release')
        new_sla = self.get_option('sla')
        sys_uuid = self.get_option('uuid')
        view_name = self.get_option("view_name")
        view_label = self.get_option("view_label")
        view_id = self.get_option("view_id")
        remove_view = self.get_option("remove_view")

        system = get_system(org_name, sys_name, env_name, sys_uuid)
        new_environment = get_environment(org_name, new_environment_name)

        updates = {}
        if new_name:
            updates['name'] = new_name
        if new_description:
            updates['description'] = new_description
        if new_location:
            updates['location'] = new_location
        if new_release:
            updates['releaseVer'] = new_release
        if new_sla is not None:
            updates['serviceLevel'] = new_sla
        if new_environment_name:
            new_environment = get_environment(org_name, new_environment_name)
            updates['environment_id'] = new_environment['id']

        if remove_view:
            updates["content_view_id"] = False
        elif view_label or view_name or view_id:
            updates["content_view_id"] = get_content_view(
                org_name, view_label, view_name, view_id)["id"]

        response = self.api.update(system['uuid'], updates)

        test_record(response,
                    _("Successfully updated system [ %s ]") % system['name'],
                    _("Could not update system [ %s ]") % system['name'])
Exemple #24
0
    def run(self):
        org_name = self.get_option("org")
        env_name = self.get_option("environment")
        sys_name = self.get_option("name")
        new_name = self.get_option("new_name")
        new_environment_name = self.get_option("new_environment")
        new_description = self.get_option("description")
        new_location = self.get_option("location")
        new_release = self.get_option("release")
        new_sla = self.get_option("sla")
        sys_uuid = self.get_option("uuid")
        view_label = self.get_option("view")

        system = get_system(org_name, sys_name, env_name, sys_uuid)
        new_environment = get_environment(org_name, new_environment_name)

        updates = {}
        if new_name:
            updates["name"] = new_name
        if new_description:
            updates["description"] = new_description
        if new_location:
            updates["location"] = new_location
        if new_release:
            updates["releaseVer"] = new_release
        if new_sla:
            updates["serviceLevel"] = new_sla
        if new_environment_name:
            new_environment = get_environment(org_name, new_environment_name)
            updates["environment_id"] = new_environment["id"]

        if view_label is not None:
            updates["content_view_id"] = get_content_view(org_name, view_label)["id"]

        response = self.api.update(system["uuid"], updates)

        test_record(
            response,
            _("Successfully updated system [ %s ]") % system["name"],
            _("Could not update system [ %s ]") % system["name"],
        )
Exemple #25
0
    def run(self):
        envName = self.get_option("environment")
        orgName = self.get_option("org")

        keys = (
            self.get_keys_for_organization(orgName)
            if envName == None
            else self.get_keys_for_environment(orgName, envName)
        )

        if not keys:
            if envName == None:
                print _("No keys found in organization [ %s ]") % orgName
            else:
                print _("No keys found in organization [ %(orgName)s ] environment [ %(envName)s ]") % {
                    "orgName": orgName,
                    "envName": envName,
                }

            return os.EX_OK

        for k in keys:
            if k["usage_limit"] is None or k["usage_limit"] == -1:
                k["usage"] = str(k["usage_count"])
            else:
                k["usage"] = str(k["usage_count"]) + "/" + str(k["usage_limit"])
            if k["content_view_id"]:
                view = get_content_view(orgName, view_id=k["content_view_id"])
                k["content_view"] = view["name"]

        self.printer.add_column("id", _("ID"))
        self.printer.add_column("name", _("Name"))
        self.printer.add_column("description", _("Description"), multiline=True)
        self.printer.add_column("usage", _("Usage"))
        self.printer.add_column("environment_id", _("Environment ID"))
        self.printer.add_column("content_view", _("Content View"))

        self.printer.set_header(_("Activation Key List"))
        self.printer.print_items(keys)
        return os.EX_OK
    def run(self):
        envName = self.get_option('environment')
        orgName = self.get_option('org')

        keys = self.get_keys_for_organization(orgName) \
            if envName == None else self.get_keys_for_environment(orgName, envName)

        if not keys:
            if envName == None:
                print _("No keys found in organization [ %s ]") % orgName
            else:
                print _("No keys found in organization [ %(orgName)s ] environment [ %(envName)s ]") \
                    % {'orgName':orgName, 'envName':envName}

            return os.EX_OK

        for k in keys:
            if k['usage_limit'] is None or k['usage_limit'] == -1:
                k['usage'] = str(k['usage_count'])
            else:
                k['usage'] = str(k['usage_count']) + '/' + str(
                    k['usage_limit'])
            if k['content_view_id']:
                view = get_content_view(orgName, view_id=k['content_view_id'])
                k['content_view'] = view["name"]

        self.printer.add_column('id', _("ID"))
        self.printer.add_column('name', _("Name"))
        self.printer.add_column('description',
                                _("Description"),
                                multiline=True)
        self.printer.add_column('usage', _("Usage"))
        self.printer.add_column('environment_id', _("Environment ID"))
        self.printer.add_column('content_view', _("Content View"))

        self.printer.set_header(_("Activation Key List"))
        self.printer.print_items(keys)
        return os.EX_OK
    def run(self):
        orgName = self.get_option('org')
        keyName = self.get_option('name')

        keys = self.api.activation_keys_by_organization(orgName, keyName)

        if len(keys) == 0:
            print >> sys.stderr, _(
                "Could not find activation key [ %s ]") % keyName
            return os.EX_DATAERR
        for akey in keys:
            akey["pools"] = "[ " + ", ".join(
                [pool["cp_id"] for pool in akey["pools"]]) + " ]"

        if keys[0]['content_view_id']:
            view = get_content_view(orgName,
                                    view_id=keys[0]['content_view_id'])
            keys[0]['content_view'] = view['label']

        self.printer.add_column('id', _("ID"))
        self.printer.add_column('name', _("Name"))
        self.printer.add_column('description',
                                _("Description"),
                                multiline=True)
        self.printer.add_column('usage_limit', _("Usage Limit"), \
            value_formatter=lambda x: "unlimited" if x == -1 else x)
        self.printer.add_column('environment_id', _("Environment ID"))
        self.printer.add_column('content_view',
                                _("Content View"),
                                value_formatter=lambda x: "[ %s ]" % x)
        self.printer.add_column('pools',
                                _("Pools"),
                                multiline=True,
                                show_with=printer.VerboseStrategy)
        self.printer.set_header(_("Activation Key Info"))
        self.printer.print_item(keys[0])
        return os.EX_OK
Exemple #28
0
    def run(self):
        name = self.get_option("name")
        org = self.get_option("org")
        environment_name = self.get_option("environment")
        activation_keys = self.get_option("activationkey")
        release = self.get_option("release")
        sla = self.get_option("sla")
        facts = dict(self.get_option("fact") or {})
        view_label = self.get_option("content_view")

        environment_id = None
        if environment_name is not None:
            environment_id = get_environment(org, environment_name)["id"]

        view_id = None
        if view_label is not None:
            view = get_content_view(org, view_label)
            view_id = view["id"]

        system = self.api.register(name, org, environment_id, activation_keys, "system", release, sla, facts, view_id)

        test_record(
            system, _("Successfully registered system [ %s ]") % name, _("Could not register system [ %s ]") % name
        )
Exemple #29
0
    def run(self):
        org_name = self.get_option('org')
        view_label = self.get_option('label')
        view_id = self.get_option('id')
        view_name = self.get_option('name')
        async = self.get_option('async')

        view = get_content_view(org_name, view_label, view_name, view_id)

        task = self.api.refresh(view["id"])

        if not async:
            task = AsyncTask(task)
            run_spinner_in_bg(wait_for_async_task, [task],
                              message=_("Refreshing view, please wait..."))

            return evaluate_task_status(task,
                ok =     _("Content view [ %s ] was successfully refreshed.") % view["name"],
                failed = _("View [ %s ] refresh failed") % view["name"]
            )

        else:
            print _("Refresh task [ %s ] was successfully created.") % (task["uuid"])
            return os.EX_OK
Exemple #30
0
    def run(self):
        org_name = self.get_option('org')
        view_label = self.get_option('label')
        view_id = self.get_option('id')
        view_name = self.get_option('name')
        async = self.get_option('async')

        view = get_content_view(org_name, view_label, view_name, view_id)

        task = self.api.refresh(view["id"])

        if not async:
            task = AsyncTask(task)
            run_spinner_in_bg(wait_for_async_task, [task],
                              message=_("Refreshing view, please wait..."))

            return evaluate_task_status(task,
                ok =     _("Content view [ %s ] was successfully refreshed.") % view["name"],
                failed = _("View [ %s ] refresh failed") % view["name"]
            )

        else:
            print _("Refresh task [ %s ] was successfully created.") % (task["uuid"])
            return os.EX_OK
Exemple #31
0
 def content_view_id(self, options):
     view = get_content_view(self.org_name, options['label'])
     return view['id']
Exemple #32
0
 def content_view_id(self, options):
     view = get_content_view(self.org_name, **options)
     return view['id']
Exemple #33
0
 def content_view_id(self, options):
     view = get_content_view(self.org_name, **options)
     return view['id']