示例#1
0
    def run(self):
        systemGroupApi = SystemGroupAPI()

        org_name = self.get_option('org')
        group_name = self.get_option('name')
        type_in = self.get_option('type')

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

        errata = systemGroupApi.errata(org_name,
                                       system_group_id,
                                       type_in=type_in)

        batch_add_columns(self.printer, {'errata_id': _("ID")},
                          {'title': _("Title")}, {'type': _("Type")})
        self.printer.add_column('systems', _('# Systems'), formatter=len)
        self.printer.add_column('systems',
                                _("Systems"),
                                multiline=True,
                                show_with=printer.VerboseStrategy)

        self.printer.set_header(
            _("Errata for system group %(org_name)s in organization %(org_name)s"
              ) % {
                  'group_name': group_name,
                  'org_name': org_name
              })
        self.printer.print_items(errata)

        return os.EX_OK
示例#2
0
def get_system_group(org_name, system_group_name):
    system_group_api = SystemGroupAPI()

    system_group = system_group_api.system_group_by_name(org_name, system_group_name)
    if system_group == None:
        raise ApiDataError(_("Could not find system group [ %s ] within organization [ %s ]") % (system_group_name, org_name))
    return system_group
示例#3
0
def get_system_group(org_name, system_group_name):
    system_group_api = SystemGroupAPI()

    system_group = system_group_api.system_group_by_name(
        org_name, system_group_name)
    if system_group == None:
        raise ApiDataError(_("Could not find system group [ %(system_group_name)s ] " \
            "within organization [ %(org_name)s ]") \
            % {'system_group_name':system_group_name, 'org_name':org_name})
    return system_group
示例#4
0
    def run(self):
        org_name = self.get_option('org')
        sys_name = self.get_option('name')
        system_group_names = self.get_option('system_group_names')
        sys_uuid = self.get_option('uuid')

        query = {}
        update_dict_unless_none(query, "name", sys_name)
        update_dict_unless_none(query, "uuid", sys_uuid)
        system = self.api.systems_by_org(org_name, query)

        if system is None or len(system) == 0:
            return os.EX_DATAERR
        elif len(system) > 1:
            print constants.OPT_ERR_SYSTEM_AMBIGUOUS
            return os.EX_DATAERR
        else:
            system = system[0]

        system_groups = SystemGroupAPI().system_groups(
            org_name, {'name': system_group_names})

        if system_groups is None:
            return os.EX_DATAERR

        system_group_ids = [group["id"] for group in system_groups]

        system = self.api.add_system_groups(system["uuid"], system_group_ids)

        if system != None:
            print _("Successfully added system groups to system [ %s ]"
                    ) % system['name']
            return os.EX_OK
        else:
            return os.EX_DATAERR
示例#5
0
    def run(self):
        org_name = self.get_option('org')
        name = self.get_option('name')
        system_group_name = self.get_option('system_group_name')

        activation_key = self.api.activation_keys_by_organization(
            org_name, name)

        if activation_key is None:
            return os.EX_DATAERR
        else:
            activation_key = activation_key[0]

        system_group = SystemGroupAPI().system_groups(
            org_name, {'name': system_group_name})

        if system_group is None:
            return os.EX_DATAERR
        else:
            system_group = system_group[0]

        activation_key = self.api.remove_system_group(org_name,
                                                      activation_key["id"],
                                                      system_group['id'])

        if activation_key != None:
            print _(
                "Successfully removed system group from activation key [ %s ]"
            ) % activation_key['name']
            return os.EX_OK
        else:
            return os.EX_DATAERR
示例#6
0
文件: system.py 项目: beav/katello
    def run(self):
        org_name = self.get_option('org')
        name = self.get_option('name')
        system_group_names = self.get_option('system_group_names')

        system = self.api.systems_by_org(org_name, {'name': name})

        if system is None:
            return os.EX_DATAERR
        else:
            system = system[0]

        system_groups = SystemGroupAPI().system_groups(
            org_name, {'name': system_group_names})

        if system_groups is None:
            return os.EX_DATAERR

        system_group_ids = [group["id"] for group in system_groups]

        system = self.api.remove_system_groups(system["uuid"],
                                               system_group_ids)

        if system != None:
            print _("Successfully removed system groups from system [ %s ]"
                    ) % system['name']
            return os.EX_OK
        else:
            return os.EX_DATAERR
示例#7
0
    def _fetch_org_key_group(self):
        """ return array (org_name, activation_key, system_group) based on command line options """
        org_name = self.get_option('org')
        name = self.get_option('name')
        system_group_name = self.get_option('system_group_name')

        activation_key = self.api.activation_keys_by_organization(
            org_name, name)

        if activation_key:
            activation_key = activation_key[0]
        else:
            print >> sys.stderr, _(
                "Could not find activation key [ %s ]") % name
            return None, None, None

        system_group = SystemGroupAPI().system_groups(
            org_name, {'name': system_group_name})

        if system_group:
            system_group = system_group[0]
        else:
            print >> sys.stderr, _(
                "Could not find system group [ %s ]") % system_group_name
            return None, None, None

        return org_name, activation_key, system_group
示例#8
0
文件: errata.py 项目: icewwn/katello
    def run(self):
        systemGroupApi = SystemGroupAPI()

        org_name = self.get_option('org')
        group_name = self.get_option('name')
        type_in = self.get_option('type')

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

        errata = systemGroupApi.errata(org_name, system_group_id, type_in=type_in)

        batch_add_columns(self.printer, 'id', 'title', 'type')
        self.printer.add_column('systems', _('# Systems'), formatter=len)
        self.printer.add_column('systems', multiline=True, show_with=printer.VerboseStrategy)

        self.printer.set_header(_("Errata for system group %s in organization %s") % (group_name, org_name))
        self.printer.print_items(errata)

        return os.EX_OK
示例#9
0
    def run(self):
        systemGroupApi = SystemGroupAPI()

        org_name = self.get_option("org")
        group_name = self.get_option("name")
        type_in = self.get_option("type")

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

        errata = systemGroupApi.errata(org_name, system_group_id, type_in=type_in)

        batch_add_columns(self.printer, {"id": _("ID")}, {"title": _("Title")}, {"type": _("Type")})
        self.printer.add_column("systems", _("# Systems"), formatter=len)
        self.printer.add_column("systems", _("Systems"), multiline=True, show_with=printer.VerboseStrategy)

        self.printer.set_header(
            _("Errata for system group %(org_name)s in organization %(org_name)s")
            % {"group_name": group_name, "org_name": org_name}
        )
        self.printer.print_items(errata)

        return os.EX_OK
示例#10
0
    def run(self):
        systemGroupApi = SystemGroupAPI()

        org_name = self.get_option('org')
        group_name = self.get_option('name')
        type_in = self.get_option('type')

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

        errata = systemGroupApi.errata(org_name, system_group_id, type_in=type_in)
        for erratum in errata:
            erratum['applicable_consumers'] = [x['name'] for x in erratum['applicable_consumers']]


        batch_add_columns(self.printer, {'errata_id': _("ID")}, {'title': _("Title")}, {'type': _("Type")})
        self.printer.add_column('applicable_consumers', _('# Systems'), formatter=len)
        self.printer.add_column('applicable_consumers', _("Systems"), multiline=True, show_with=printer.VerboseStrategy)

        self.printer.set_header(_("Errata for system group %(org_name)s in organization %(org_name)s")
            % {'group_name':group_name, 'org_name':org_name})
        self.printer.print_items(errata)

        return os.EX_OK
示例#11
0
 def __init__(self):
     super(SystemGroupAction, self).__init__()
     self.api = SystemGroupAPI()
示例#12
0
class SystemGroup():
    api = SystemGroupAPI()

    def system_groups(self, org):
        return self.api.system_groups(org['label'])

    def system_group(self, org, system_group_id, query=None):
        return self.api.system_group(org['label'], system_group_id, query)

    def system_group_systems(self, org, system_group_id, query=None):
        return self.api.system_group_systems(org['label'], system_group_id,
                                             query)

    def create(self, org, name=None, description=None, max_systems=-1):

        if name is None:
            name = "%s-system-group" % generate_name()

        if description is None:
            description = "Generated automatically."

        return self.api.create(org['label'], name, description, max_systems)

    def copy(self,
             org,
             system_group_id,
             new_name=None,
             description=None,
             max_systems=-1):

        if new_name is None:
            new_name = "%s-copied-system-group" % generate_name()

        if description is None:
            description = "Copied automatically."

        return self.api.copy(org['label'], system_group_id, new_name,
                             description, max_systems)

    def update(self,
               org,
               system_group_id,
               name=None,
               description=None,
               max_systems=-1):
        return self.api.delete(org['label'], )

    def delete(self, org, system_group_id, delete_systems=False):
        return self.api.delete(org['label'], system_group_id, delete_systems)

    def add_systems(self, org, system_group_id, system_ids):
        return self.api.add_systems(org['label'], system_group_id, system_ids)

    def remove_systems(self, org, system_group_id, system_ids):
        return self.api.remove_systems(org['label'], system_group_id,
                                       system_ids)

    def install_packages(self, org, system_group_id, packages):
        return self.install_packages(org['label'], system_group_id, packages)

    def update_packages(self, org, system_group_id, packages):
        return self.api.update_packages(org['label'], system_group_id,
                                        packages)

    def remove_packages(self, org, system_group_id, packages):
        return self.api.remove_packages(org['label'], system_group_id,
                                        packages)

    def install_package_groups(self, org, system_group_id, packages):
        return self.install_package_groups(org['label'], system_group_id,
                                           packages)

    def update_package_groups(self, org, system_group_id, packages):
        return self.api.update_package_groups(org['label'], system_group_id,
                                              packages)

    def remove_package_groups(self, org, system_group_id, packages):
        return self.api.remove_package_groups(org['label'], system_group_id,
                                              packages)

    def errata(self, org, system_group_id, type_in=None):
        return self.api.errata(org['label'], system_group_id, type_in)

    def install_errata(self, org, system_group_id, errata):
        return self.api.install_errata(org['label'], system_group_id, errata)

    def update_systems(self, org, system_group_id, env, view):
        return self.api.update_systems(org['label'], system_group_id,
                                       env['id'], view['id'])