コード例 #1
0
ファイル: models.py プロジェクト: jwmatthews/splice-server
 def pre_save(cls, sender, document, **kwargs):
     for attr_name in ["created", "updated"]:
         if isinstance(getattr(document, attr_name), basestring):
             setattr(document, attr_name,
                     convert_to_datetime(getattr(document, attr_name)))
     if document.attrs:
         document.attrs = sanitize_dict_for_mongo(document.attrs)
コード例 #2
0
ファイル: utils.py プロジェクト: jwmatthews/splice-server
    def test_sanitize_dict_for_mongo(self):
        bad_dot_key = "bad.value.with.dots"
        fixed_bad_dot_key = "bad_dot_value_dot_with_dot_dots"
        bad_dollar_key = "dolla$dolla$"
        fixed_bad_dollar_key = "dolla_dollarsign_dolla_dollarsign_"
        a = {bad_dot_key: "1",
             bad_dollar_key: "2"}
        sanitized = utils.sanitize_dict_for_mongo(a)
        self.assertEquals(len(sanitized), 2)
        self.assertTrue(sanitized.has_key(fixed_bad_dot_key))
        self.assertTrue(sanitized.has_key(fixed_bad_dollar_key))
        self.assertEquals(sanitized[fixed_bad_dot_key], a[bad_dot_key])
        self.assertEquals(sanitized[fixed_bad_dollar_key], a[bad_dollar_key])

        expected_same = utils.sanitize_dict_for_mongo(sanitized)
        self.assertEquals(expected_same, sanitized)
コード例 #3
0
ファイル: models.py プロジェクト: jwmatthews/splice-server
 def pre_save(cls, sender, document, **kwargs):
     if isinstance(document.date, basestring):
         document.date = convert_to_datetime(document.date)
     if document.facts:
         document.facts = sanitize_dict_for_mongo(document.facts)
     # Ensure no duplicate entries are stored for document.tracker
     if document.tracker:
         document.tracker = list(set(document.tracker))
コード例 #4
0
def init_facts(num_instances):
    global FACTS
    for index in range(0, num_instances):
        inst_id = INSTANCE_IDS[index]
        facts = Facts().get_facts()
        facts['net.interface.eth0.mac_address'] = inst_id
        facts = utils.sanitize_dict_for_mongo(facts)
        FACTS.append(facts)
    return FACTS
コード例 #5
0
ファイル: checkin.py プロジェクト: jwmatthews/splice-server
    def record_usage(self, identity, consumer_identifier, facts, allowed_products, unallowed_products):
        """
        @param identity consumer's identity
        @type identity: str

        @param consumer_identifier means of uniquely identifying different instances with same consumer identity
            an example could be a mac address
        @type consumer_identifier: str

        @param facts system facts
        @type facts: {}

        @param allowed_products:    list of product ids that are
                                    installed and entitled for usage by consumer
        @type allowed_products: [str]

        @param unallowed_products:  list of product ids that are
                                    installed but _not_ entitled for usage by consumer
        @type unallowed_products: [str]
        """
        try:
            sanitized_facts = utils.sanitize_dict_for_mongo(facts)
            _LOG.info("Record usage for '%s' with "
                        "allowed_products '%s', "
                        "unallowed_products '%s' "
                        "on instance with identifier '%s' and facts <%s>" %\
                (identity, allowed_products, unallowed_products,
                 consumer_identifier, sanitized_facts))
            consumer_uuid_str = str(identity.uuid)
            prod_usage = ProductUsage(
                consumer=consumer_uuid_str,
                splice_server=self.get_this_server().uuid,
                instance_identifier=consumer_identifier,
                allowed_product_info=allowed_products,
                unallowed_product_info=unallowed_products,
                facts=sanitized_facts,
                date=datetime.now())
            prod_usage.save()
        except Exception, e:
            _LOG.exception(e)
コード例 #6
0
ファイル: models.py プロジェクト: jwmatthews/splice-server
 def pre_save(cls, sender, document, **kwargs):
     if isinstance(document.date, basestring):
         document.date = convert_to_datetime(document.date)
     if document.facts:
         document.facts = sanitize_dict_for_mongo(document.facts)