def test_spec_version_okay(self): spec = {"type": "Foo", "version": "version string"} res = schema.get_spec_version(spec) self.assertEqual(("Foo", "version string"), res) spec = {"type": "Foo", "version": 1.5} res = schema.get_spec_version(spec) self.assertEqual(("Foo", 1.5), res)
def test_spec_version_okay(self): spec = {'type': 'Foo', 'version': 'version string'} res = schema.get_spec_version(spec) self.assertEqual(('Foo', 'version string'), res) spec = {'type': 'Foo', 'version': 1.5} res = schema.get_spec_version(spec) self.assertEqual(('Foo', '1.5'), res)
def __init__(self, name, spec, **kwargs): """Initialize a trigger instance. :param name: The name for the trigger. :param spec: A dictionary containing the detailed trigger spec. :param kwargs: Keyword arguments for initializing the trigger. :returns: An instance of a specific sub-class of BaseTrigger. """ type_name, version = schema.get_spec_version(spec) self.type_name = type_name self.name = name self.id = kwargs.get('id', None) self.physical_id = kwargs.get('physical_id', None) self.desc = kwargs.get('desc', '') self.state = kwargs.get('state', INSUFFICIENT_DATA) self.enabled = kwargs.get('enabled', True) self.severity = kwargs.get('severity', S_LOW) self.links = kwargs.get('links', {}) self.user = kwargs.get('user') self.project = kwargs.get('project') self.domain = kwargs.get('domain') self.created_time = kwargs.get('created_time', None) self.updated_time = kwargs.get('updated_time', None) self.deleted_time = kwargs.get('deleted_time', None) self.spec = spec self.spec_data = schema.Spec(self.spec_schema, spec)
def __init__(self, name, spec, **kwargs): """Initialize a profile instance. :param name: A string that specifies the name for the profile. :param spec: A dictionary containing the detailed policy spec. :param kwargs: Keyword arguments for initializing the policy. :returns: An instance of a specific sub-class of Policy. """ type_name, version = schema.get_spec_version(spec) self.name = name self.spec = spec self.id = kwargs.get('id', None) self.type = kwargs.get('type', '%s-%s' % (type_name, version)) self.permission = kwargs.get('permission', '') self.metadata = kwargs.get('metadata', {}) self.created_time = kwargs.get('created_time', None) self.updated_time = kwargs.get('updated_time', None) self.deleted_time = kwargs.get('deleted_time', None) self.spec_data = schema.Spec(self.spec_schema, self.spec) self.properties = schema.Spec(self.properties_schema, self.spec.get(self.PROPERTIES, {})) if not self.id: # new object needs a context dict self.context = self._init_context() else: self.context = kwargs.get('context')
def __init__(self, name, spec, **kwargs): """Initialize a policy instance. :param name: The name for the policy. :param spec: A dictionary containing the detailed policy spec. :param kwargs: Keyword arguments for initializing the policy. :returns: An instance of a specific sub-class of Policy. """ type_name, version = schema.get_spec_version(spec) type_str = "-".join([type_name, version]) self.name = name self.spec = spec self.id = kwargs.get('id', None) self.type = kwargs.get('type', type_str) self.user = kwargs.get('user') self.project = kwargs.get('project') self.domain = kwargs.get('domain') self.data = kwargs.get('data', {}) self.created_at = kwargs.get('created_at', None) self.updated_at = kwargs.get('updated_at', None) self.spec_data = schema.Spec(self.spec_schema, spec) self.properties = schema.Spec(self.properties_schema, self.spec.get(self.PROPERTIES, {})) self.singleton = True
def __new__(cls, name, spec, **kwargs): """Create a trigger instance based on its type and version. :param name: The name for the trigger. :param spec: A dictionary containing the spec for the trigger. :param kwargs: Keyword arguments for trigger creation. :returns: An instance of a specific sub-class of BaseTrigger. """ type_name, version = schema.get_spec_version(spec) if cls != Trigger: TriggerClass = cls else: TriggerClass = environment.global_env().get_trigger(type_name) return super(Trigger, cls).__new__(TriggerClass)
def __new__(cls, name, spec, **kwargs): """Create a new profile of the appropriate class. :param name: The name for the profile. :param spec: A dictionary containing the spec for the profile. :param kwargs: Keyword arguments for policy creation. :returns: An instance of a specific sub-class of Policy. """ type_name, version = schema.get_spec_version(spec) if cls != Profile: ProfileClass = cls else: ProfileClass = environment.global_env().get_profile(type_name) return super(Profile, cls).__new__(ProfileClass)
def __new__(cls, name, spec, **kwargs): """Create a new profile of the appropriate class. :param name: The name for the profile. :param spec: A dictionary containing the spec for the profile. :param kwargs: Keyword arguments for profile creation. :returns: An instance of a specific sub-class of Profile. """ type_name, version = schema.get_spec_version(spec) type_str = "-".join([type_name, version]) if cls != Profile: ProfileClass = cls else: ProfileClass = environment.global_env().get_profile(type_str) return super(Profile, cls).__new__(ProfileClass)
def __init__(self, name, spec, **kwargs): """Initialize a profile instance. :param name: A string that specifies the name for the profile. :param spec: A dictionary containing the detailed profile spec. :param kwargs: Keyword arguments for initializing the profile. :returns: An instance of a specific sub-class of Profile. """ type_name, version = schema.get_spec_version(spec) self.type_name = type_name self.version = version type_str = "-".join([type_name, version]) self.name = name self.spec = spec self.id = kwargs.get('id', None) self.type = kwargs.get('type', type_str) self.user = kwargs.get('user') self.project = kwargs.get('project') self.domain = kwargs.get('domain') self.metadata = kwargs.get('metadata', {}) self.created_at = kwargs.get('created_at', None) self.updated_at = kwargs.get('updated_at', None) self.spec_data = schema.Spec(self.spec_schema, self.spec) self.properties = schema.Spec(self.properties_schema, self.spec.get(self.PROPERTIES, {}), version) if not self.id: # new object needs a context dict self.context = self._init_context() else: self.context = kwargs.get('context') # initialize clients self._computeclient = None self._networkclient = None self._orchestrationclient = None
def __init__(self, name, spec, **kwargs): """Initialize a profile instance. :param name: A string that specifies the name for the profile. :param spec: A dictionary containing the detailed profile spec. :param kwargs: Keyword arguments for initializing the profile. :returns: An instance of a specific sub-class of Profile. """ type_name, version = schema.get_spec_version(spec) type_str = "-".join([type_name, version]) self.name = name self.spec = spec self.id = kwargs.get('id', None) self.type = kwargs.get('type', type_str) self.user = kwargs.get('user') self.project = kwargs.get('project') self.domain = kwargs.get('domain') self.metadata = kwargs.get('metadata', {}) self.created_at = kwargs.get('created_at', None) self.updated_at = kwargs.get('updated_at', None) self.spec_data = schema.Spec(self.spec_schema, self.spec) self.properties = schema.Spec(self.properties_schema, self.spec.get(self.PROPERTIES, {})) if not self.id: # new object needs a context dict self.context = self._init_context() else: self.context = kwargs.get('context')