コード例 #1
0
ファイル: test_fields.py プロジェクト: bdelliott/nova
 def setUp(self):
     super(TestCIDR, self).setUp()
     self.field = fields.Field(fields.CIDR())
     good = ['192.168.0.1/24', '192.168.0.0/16', '192.168.0.0/8',
             '192.168.0.0/0', '1.2.3.4/32', '1.2.3.4/22', '0/0',
             '::1/128', '::1/64', '::1/0']
     self.coerce_good_values = [(x, x) for x in good]
     self.coerce_bad_values = ['192.168.0.0', '192.168.0.0/f',
                               '192.168.0.0/foo', '192.168.0.0/33',
                               '::1/129', '192.168.0.0/-1']
     self.to_primitive_values = [(x, x) for x in good]
     self.from_primitive_values = self.to_primitive_values
コード例 #2
0
ファイル: security_group_rule.py プロジェクト: sysuailab/nova
class SecurityGroupRule(base.NovaPersistentObject, base.NovaObject):
    # Version 1.0: Initial version
    VERSION = '1.0'

    fields = {
        'id': fields.IntegerField(),
        'protocol': fields.StringField(nullable=True),
        'from_port': fields.IntegerField(nullable=True),
        'to_port': fields.IntegerField(nullable=True),
        'cidr': fields.Field(fields.CIDR(), nullable=True),
        'parent_group': fields.ObjectField('SecurityGroup', nullable=True),
        'grantee_group': fields.ObjectField('SecurityGroup', nullable=True),
    }

    @staticmethod
    def _from_db_subgroup(context, db_group):
        if db_group is None:
            return None
        return security_group.SecurityGroup._from_db_object(
            context, security_group.SecurityGroup(), db_group)

    @staticmethod
    def _from_db_object(context, rule, db_rule, expected_attrs=None):
        if expected_attrs is None:
            expected_attrs = []
        for field in rule.fields:
            if field in expected_attrs:
                rule[field] = rule._from_db_subgroup(context, db_rule[field])
            elif field not in OPTIONAL_ATTRS:
                rule[field] = db_rule[field]
        rule._context = context
        rule.obj_reset_changes()
        return rule

    @base.remotable_classmethod
    def get_by_id(cls, context, rule_id):
        db_rule = db.security_group_rule_get(context, rule_id)
        return cls._from_db_object(context, cls(), db_rule)