Пример #1
0
    def entitle(self, server_id, history, virt_type=None):
        """
        Entitle a server according to the entitlements we have configured.
        """
        log_debug(3, self.entitlements)

        entitle_server = rhnSQL.Procedure("rhn_entitlements.entitle_server")
        # TODO: entitle_server calls can_entitle_server, so we're doing this
        # twice for each successful call. Is it necessary for external error
        # handling or can we ditch it?
        can_entitle_server = rhnSQL.Function(
            "rhn_entitlements.can_entitle_server", rhnSQL.types.NUMBER())

        can_ent = None

        history["entitlement"] = ""

        # Do a quick check to see if both virt entitlements are present. (i.e.
        # activation keys stacked together) If so, give preference to the more
        # powerful virtualization platform and remove the regular virt
        # entitlement from the list.
        found_virt = False
        found_virt_platform = False
        for entitlement in self.entitlements:
            if entitlement[0] == VIRT_ENT_LABEL:
                found_virt = True
            elif entitlement[0] == VIRT_PLATFORM_ENT_LABEL:
                found_virt_platform = True

        for entitlement in self.entitlements:
            if virt_type is not None and entitlement[0] in \
                    (VIRT_ENT_LABEL, VIRT_PLATFORM_ENT_LABEL):
                continue

            # If both virt entitlements are present, skip the least powerful:
            if found_virt and found_virt_platform and entitlement[0] == VIRT_ENT_LABEL:
                log_debug(1, "Virtualization and Virtualization Platform " +
                          "entitlements both present.")
                log_debug(1, "Skipping Virtualization.")
                continue

            try:
                can_ent = can_entitle_server(server_id, entitlement[0])
            except rhnSQL.SQLSchemaError, e:
                can_ent = 0

            try:
                # bugzilla #160077, skip attempting to entitle if we cant
                if can_ent:
                    entitle_server(server_id, entitlement[0])
            except rhnSQL.SQLSchemaError, e:
                log_error("Token failed to entitle server", server_id,
                          self.get_names(), entitlement[0], e.errmsg)
                if e.errno == 20220:
                    # ORA-20220: (servergroup_max_members) - Server group membership
                    # cannot exceed maximum membership
                    raise rhnFault(91,
                                   _("Registration failed: RHN Software service entitlements exhausted: %s") % entitlement[0]), None, sys.exc_info()[2]
                # No idea what error may be here...
                raise rhnFault(90, e.errmsg), None, sys.exc_info()[2]
Пример #2
0
    def management_create_channel(self, dict):
        log_debug(1)
        self._get_and_validate_session(dict)

        config_channel = dict.get('config_channel')
        # XXX Validate the namespace

        config_channel_name = dict.get('config_channel_name') or config_channel
        config_channel_description = dict.get('description') or config_channel

        row = rhnSQL.fetchone_dict(self._query_lookup_config_channel,
                                   org_id=self.org_id,
                                   config_channel=config_channel)
        if row:
            raise rhnFault(4010,
                           "Configuration channel %s already exists" %
                           config_channel,
                           explain=0)

        insert_call = rhnSQL.Function('rhn_config.insert_channel',
                                      rhnSQL.types.NUMBER())
        config_channel_id = insert_call(self.org_id, 'normal',
                                        config_channel_name, config_channel,
                                        config_channel_description)

        rhnSQL.commit()
        return {}
Пример #3
0
    def entitle(self, server_id, history, virt_type=None):
        """
        Entitle a server according to the entitlements we have configured.
        """
        log_debug(3, self.entitlements)

        entitle_server = rhnSQL.Procedure("rhn_entitlements.entitle_server")
        # TODO: entitle_server calls can_entitle_server, so we're doing this
        # twice for each successful call. Is it necessary for external error
        # handling or can we ditch it?
        can_entitle_server = rhnSQL.Function(
            "rhn_entitlements.can_entitle_server", rhnSQL.types.NUMBER())

        can_ent = None

        history["entitlement"] = ""

        for entitlement in self.entitlements:
            if virt_type is not None and entitlement[0] == VIRT_ENT_LABEL:
                continue

            try:
                can_ent = can_entitle_server(server_id, entitlement[0])
            except rhnSQL.SQLSchemaError, e:
                can_ent = 0

            try:
                # bugzilla #160077, skip attempting to entitle if we cant
                if can_ent:
                    entitle_server(server_id, entitlement[0])
            except rhnSQL.SQLSchemaError, e:
                log_error("Token failed to entitle server", server_id,
                          self.get_names(), entitlement[0], e.errmsg)
                #No idea what error may be here...
                raise rhnFault(90, e.errmsg), None, sys.exc_info()[2]
Пример #4
0
 def _insert_revision(self, file):
     insert_call = rhnSQL.Function("rhn_config.insert_revision",
                                   rhnSQL.types.NUMBER())
     file['config_revision_id'] = insert_call(
         file['revision'], file['config_file_id'],
         file.get('config_content_id', None), file['config_info_id'],
         file['config_file_type_id'])
Пример #5
0
    def _push_config_file(self, file):
        config_info_query = self._query_lookup_non_symlink_config_info
        if self._is_link(file) and file.get("symlink"):
            config_info_query = self._query_lookup_symlink_config_info

        # Look up the config info first
        h = rhnSQL.prepare(config_info_query)
        h.execute(**file)
        row = h.fetchone_dict()
        if not row:
            # Hmm
            raise rhnException("This query should always return a row")
        config_info_id = row['id']
        file['config_info_id'] = config_info_id

        # Look up the config file itself
        h = rhnSQL.prepare(self._query_lookup_config_file)
        h.execute(**file)
        row = h.fetchone_dict()
        if row:
            # Yay we already have this file
            # Later down the road, we're going to update modified for this
            # table
            file['config_file_id'] = row['id']
            return

        # Have to insert this config file, gotta use the api to keep quotas up2date...
        insert_call = rhnSQL.Function("rhn_config.insert_file",
                                      rhnSQL.types.NUMBER())
        file['config_file_id'] = insert_call(file['config_channel_id'],
                                             file['path'])
Пример #6
0
def join_server_group(server_id, server_group_id):
    """ Adds a server to a server group """
    # avoid useless reparses caused by different arg types
    server_id = str(server_id)
    server_group_id = str(server_group_id)

    insert_call = rhnSQL.Function("rhn_server.insert_into_servergroup_maybe",
                                  rhnSQL.types.NUMBER())
    ret = insert_call(server_id, server_group_id)
    # return the number of rows inserted - feel free to ignore
    return ret
Пример #7
0
    def entitle(self, server_id, history, virt_type=None):
        """
        Entitle a server according to the entitlements we have configured.
        """
        log_debug(3, self.entitlements)

        # check for bootstrap_entitled and unentitle first
        cur = check_entitlement(server_id, True)
        if cur and 'bootstrap_entitled' in cur:
            remove_ent = rhnSQL.Procedure(
                "rhn_entitlements.remove_server_entitlement")
            remove_ent(server_id, "bootstrap_entitled")

        entitle_server = rhnSQL.Procedure("rhn_entitlements.entitle_server")
        # TODO: entitle_server calls can_entitle_server, so we're doing this
        # twice for each successful call. Is it necessary for external error
        # handling or can we ditch it?
        can_entitle_server = rhnSQL.Function(
            "rhn_entitlements.can_entitle_server", rhnSQL.types.NUMBER())

        can_ent = None

        history["entitlement"] = ""

        for entitlement in self.entitlements:
            if virt_type is not None and entitlement[0] == VIRT_ENT_LABEL:
                continue

            try:
                can_ent = can_entitle_server(server_id, entitlement[0])
            except rhnSQL.SQLSchemaError:
                e = sys.exc_info()[1]
                can_ent = 0

            try:
                # bugzilla #160077, skip attempting to entitle if we cant
                if can_ent:
                    entitle_server(server_id, entitlement[0])
            except rhnSQL.SQLSchemaError:
                e = sys.exc_info()[1]
                log_error("Token failed to entitle server", server_id,
                          self.get_names(), entitlement[0], e.errmsg)
                #No idea what error may be here...
                raise_with_tb(rhnFault(90, e.errmsg), sys.exc_info()[2])
            except rhnSQL.SQLError:
                e = sys.exc_info()[1]
                log_error("Token failed to entitle server", server_id,
                          self.get_names(), entitlement[0], e.args)
                raise_with_tb(rhnFault(90, str(e)), sys.exc_info()[2])
            else:
                history[
                    "entitlement"] = "Entitled as a %s member" % entitlement[1]
Пример #8
0
    def _create_server_import_channel(self, server_id):
        name = "server_import Config Channel for system %d" % server_id
        description = "XXX"

        # server_import and local_override channels that
        # get created need to conform to this label formula:
        # {rhnConfigChannelType.label}-{sid}
        label = "server_import-%d" % server_id

        insert_call = rhnSQL.Function('rhn_config.insert_channel',
                                      rhnSQL.types.NUMBER())
        config_channel_id = insert_call(self.org_id, 'server_import', name,
                                        label, description)

        h = rhnSQL.prepare(self._query_create_server_import_channel)
        h.execute(server_id=server_id,
                  config_channel_id=config_channel_id,
                  position=None)

        return config_channel_id
Пример #9
0
def create_new_user(org_id=None,
                    username=None,
                    password=None,
                    roles=None,
                    encrypt_password=False):
    "Create a new user"
    if org_id is None:
        org_id = create_new_org()
    else:
        org_id = lookup_org_id(org_id)

    if username is None:
        username = "******" % time.time()
    if password is None:
        password = "******" % time.time()
    if encrypt_password:
        password = rhnUser.encrypt_password(password)
    if roles is None:
        roles = []

    login = username
    oracle_contact_id = None
    prefix = "Mr."
    first_names = "First Name %3.f" % time.time()
    last_name = "Last Name %3.f" % time.time()
    genqual = None
    parent_company = None
    company = "ACME"
    title = ""
    phone = ""
    fax = ""
    email = "*****@*****.**" % username
    pin = 0
    first_names_ol = " "
    last_name_ol = " "
    address1 = " "
    address2 = " "
    address3 = " "
    city = " "
    state = " "
    zip_code = " "
    country = " "
    alt_first_names = None
    alt_last_name = None
    contact_call = "N"
    contact_mail = "N"
    contact_email = "N"
    contact_fax = "N"

    f = rhnSQL.Function('create_new_user', rhnSQL.types.NUMBER())
    ret = f(org_id, login, password, oracle_contact_id, prefix, first_names,
            last_name, genqual, parent_company, company, title, phone, fax,
            email, pin, first_names_ol, last_name_ol, address1, address2,
            address3, city, state, zip_code, country, alt_first_names,
            alt_last_name, contact_call, contact_mail, contact_email,
            contact_fax)

    u = rhnUser.search(username)

    if u is None:
        raise Exception("Couldn't create the new user - user not found")

    # Set roles
    h = rhnSQL.prepare("""
        select ug.id
          from rhnUserGroupType ugt, rhnUserGroup ug
         where ug.org_id = :org_id
           and ug.group_type = ugt.id
           and ugt.label = :role
    """)
    create_ugm = rhnSQL.Procedure("rhn_user.add_to_usergroup")
    for role in roles:
        h.execute(org_id=org_id, role=role)
        row = h.fetchone_dict()
        if not row:
            raise InvalidRoleError(org_id, role)

        user_group_id = row['id']
        create_ugm(u.getid(), user_group_id)

    return u
Пример #10
0
def entitlement_grants_service(entitlement, service):
    egs = rhnSQL.Function("rhn_entitlements.entitlement_grants_service",
                          rhnSQL.types.STRING())
    return egs(entitlement, service)
Пример #11
0
 def test_function_1(self):
     "Tests function calls"
     p = rhnSQL.Function("logging.get_log_id", rhnSQL.types.NUMBER())
     ret = p()
     self.failUnless(isinstance(ret, types.FloatType))
Пример #12
0
 def _create_or_update_crash_file(self, server_id, crash_id, filename, path,
                                  filesize):
     insert_call = rhnSQL.Function("insert_crash_file",
                                   rhnSQL.types.NUMBER())
     return insert_call(crash_id, filename, path, filesize)