本文整理汇总了Python中pyrsistent.freeze函数的典型用法代码示例。如果您正苦于以下问题:Python freeze函数的具体用法?Python freeze怎么用?Python freeze使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了freeze函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_without_image_id
def test_without_image_id(self):
"""
Create server that has missing image in it in various ways.
(for the case of BFV)
"""
for image in ({}, {'id': None}, ""):
self.servers[0]['image'] = image
self.assertEqual(
NovaServer.from_server_details_json(self.servers[0]),
NovaServer(id='a',
state=ServerState.ACTIVE,
image_id=None,
flavor_id='valid_flavor',
created=self.createds[0],
servicenet_address='',
links=freeze(self.servers[0]['links']),
json=freeze(self.servers[0])))
del self.servers[0]['image']
self.assertEqual(
NovaServer.from_server_details_json(self.servers[0]),
NovaServer(id='a',
state=ServerState.ACTIVE,
image_id=None,
flavor_id='valid_flavor',
created=self.createds[0],
servicenet_address='',
links=freeze(self.servers[0]['links']),
json=freeze(self.servers[0])))
开发者ID:rackerlabs,项目名称:otter,代码行数:28,代码来源:test_model.py
示例2: test_without_image_id
def test_without_image_id(self):
"""
Create server that has missing image in it in various ways.
(for the case of BFV)
"""
for image in ({}, {"id": None}):
self.servers[0]["image"] = image
self.assertEqual(
NovaServer.from_server_details_json(self.servers[0]),
NovaServer(
id="a",
state=ServerState.ACTIVE,
image_id=None,
flavor_id="valid_flavor",
created=self.createds[0][1],
servicenet_address="",
links=freeze(self.links[0]),
json=freeze(self.servers[0]),
),
)
del self.servers[0]["image"]
self.assertEqual(
NovaServer.from_server_details_json(self.servers[0]),
NovaServer(
id="a",
state=ServerState.ACTIVE,
image_id=None,
flavor_id="valid_flavor",
created=self.createds[0][1],
servicenet_address="",
links=freeze(self.links[0]),
json=freeze(self.servers[0]),
),
)
开发者ID:pratikmallya,项目名称:otter,代码行数:34,代码来源:test_model.py
示例3: from_server_details_json
def from_server_details_json(cls, server_json):
"""
Create a :obj:`NovaServer` instance from a server details JSON
dictionary, although without any 'server' or 'servers' initial resource
key.
See
http://docs.rackspace.com/servers/api/v2/cs-devguide/content/
Get_Server_Details-d1e2623.html
:return: :obj:`NovaServer` instance
"""
try:
server_state = ServerState.lookupByName(server_json['status'])
except ValueError:
server_state = ServerState.UNKNOWN_TO_OTTER
if server_json.get("OS-EXT-STS:task_state", "") == "deleting":
server_state = ServerState.DELETED
metadata = server_json.get('metadata', {})
return cls(
id=server_json['id'],
state=server_state,
created=timestamp_to_epoch(server_json['created']),
image_id=server_json.get('image', {}).get('id'),
flavor_id=server_json['flavor']['id'],
links=freeze(server_json['links']),
desired_lbs=_lbs_from_metadata(metadata),
servicenet_address=_servicenet_address(server_json),
json=freeze(server_json))
开发者ID:pratikmallya,项目名称:otter,代码行数:30,代码来源:model.py
示例4: data_from_arg
def data_from_arg(arg):
"""extract data from a constructor arg and make immutable.
Parameters
----------
arg : dict, pmap, int, float, str
Data payloas as passed to one of the constructors. If dict or
pmap, that is used as the data payload, if other value, then
presumed to be a simple payload of {'value': arg}.
Returns
-------
pyrsistent.pmap
Immutable dict-like object
Raises
------
EventException
Raised on bad arg input.
"""
if isinstance(arg, dict):
return freeze(arg)
elif is_pmap(arg):
return copy.copy(arg)
elif isinstance(arg, int) or isinstance(arg, float) or isinstance(arg, str):
return freeze({'value': arg})
else:
raise EventException('Could not interpret data from {a}'.format(a=arg))
开发者ID:esnet,项目名称:pypond,代码行数:28,代码来源:event.py
示例5: set_in
def set_in(mapping, keys, new_value):
"""
Take the old dictionary and traverses the dictionary via the list of
keys. The returned dictionary will be the same as the old dictionary,
but with the resultant value set as ``new_value``.
Note that if more than 1 key is passed, and any of the keys (except for the
last) do not already exist, raises KeyError or IndexError.
Note that the new value does not need to be a pyrsistent data structure -
this function will freeze everything first.
:param dict mapping: The dictionary to change values for.
:param iterable keys: An ordered collection of keys
:param new_value: The value to set the keys to
:return: A copy of the old dictionary as PMap, with the new value.
"""
if len(keys) < 1:
raise ValueError("Must provide one or more keys")
if isinstance(mapping, dict):
mapping = freeze(mapping)
if len(keys) == 1:
return mapping.set(keys[0], freeze(new_value))
else:
child = mapping.get(keys[0], pmap())
return mapping.set(keys[0], set_in(child, keys[1:], new_value))
开发者ID:rackerlabs,项目名称:otter,代码行数:29,代码来源:fp.py
示例6: setUp
def setUp(self):
self.tenant_id = 'tenant-id'
self.group_id = 'group-id'
self.state = GroupState(self.tenant_id, self.group_id, 'group-name',
{}, {}, None, {}, False,
ScalingGroupStatus.ACTIVE, desired=2)
self.group = mock_group(self.state, self.tenant_id, self.group_id)
self.lc = {'args': {'server': {'name': 'foo'}, 'loadBalancers': []}}
self.desired_lbs = s(CLBDescription(lb_id='23', port=80))
self.servers = (
server('a', ServerState.ACTIVE, servicenet_address='10.0.0.1',
desired_lbs=self.desired_lbs,
links=freeze([{'href': 'link1', 'rel': 'self'}])),
server('b', ServerState.ACTIVE, servicenet_address='10.0.0.2',
desired_lbs=self.desired_lbs,
links=freeze([{'href': 'link2', 'rel': 'self'}]))
)
self.state_active = {}
self.cache = [thaw(self.servers[0].json), thaw(self.servers[1].json)]
self.gsgi = GetScalingGroupInfo(tenant_id='tenant-id',
group_id='group-id')
self.manifest = { # Many details elided!
'state': self.state,
'launchConfiguration': self.lc,
}
self.gsgi_result = (self.group, self.manifest)
self.now = datetime(1970, 1, 1)
开发者ID:pratikmallya,项目名称:otter,代码行数:27,代码来源:test_service.py
示例7: test_success
def test_success(self):
"""
The data is returned as a tuple of ([NovaServer], [CLBNode/RCv3Node]).
"""
clb_nodes = [CLBNode(node_id='node1', address='ip1',
description=CLBDescription(lb_id='lb1', port=80))]
rcv3_nodes = [RCv3Node(node_id='node2', cloud_server_id='a',
description=RCv3Description(lb_id='lb2'))]
eff = get_all_launch_server_data(
'tid',
'gid',
self.now,
get_scaling_group_servers=_constant_as_eff(
('tid', 'gid', self.now), self.servers),
get_clb_contents=_constant_as_eff((), clb_nodes),
get_rcv3_contents=_constant_as_eff((), rcv3_nodes))
expected_servers = [
server('a', ServerState.ACTIVE, servicenet_address='10.0.0.1',
links=freeze([{'href': 'link1', 'rel': 'self'}]),
json=freeze(self.servers[0])),
server('b', ServerState.ACTIVE, created=1,
servicenet_address='10.0.0.2',
links=freeze([{'href': 'link2', 'rel': 'self'}]),
json=freeze(self.servers[1]))
]
self.assertEqual(resolve_stubs(eff),
{'servers': expected_servers,
'lb_nodes': clb_nodes + rcv3_nodes})
开发者ID:glyph,项目名称:otter,代码行数:30,代码来源:test_gathering.py
示例8: test_success
def test_success(self):
"""
The data is returned as a tuple of ([NovaServer], [CLBNode/RCv3Node]).
"""
clb_nodes = [CLBNode(node_id="node1", address="ip1", description=CLBDescription(lb_id="lb1", port=80))]
rcv3_nodes = [RCv3Node(node_id="node2", cloud_server_id="a", description=RCv3Description(lb_id="lb2"))]
eff = get_all_convergence_data(
"tid",
"gid",
self.now,
get_scaling_group_servers=_constant_as_eff(("tid", "gid", self.now), self.servers),
get_clb_contents=_constant_as_eff((), clb_nodes),
get_rcv3_contents=_constant_as_eff((), rcv3_nodes),
)
expected_servers = [
server(
"a",
ServerState.ACTIVE,
servicenet_address="10.0.0.1",
links=freeze([{"href": "link1", "rel": "self"}]),
json=freeze(self.servers[0]),
),
server(
"b",
ServerState.ACTIVE,
created=1,
servicenet_address="10.0.0.2",
links=freeze([{"href": "link2", "rel": "self"}]),
json=freeze(self.servers[1]),
),
]
self.assertEqual(resolve_stubs(eff), (expected_servers, clb_nodes + rcv3_nodes))
开发者ID:pratikmallya,项目名称:otter,代码行数:34,代码来源:test_gathering.py
示例9: test_expand_path
def test_expand_path():
assert expand_path(freeze({'foo': 1, 'bar': 2}), [], [any]) == [
['bar'],
['foo'],
]
assert expand_path(freeze({'foo': {'bar': {'baz': 1}}}), [], [any, any, any]) == [
['foo', 'bar', 'baz']
]
assert expand_path(freeze({'foo': {'bar': {'baz': 1, 'qux': 4}}}), [], ['foo', any, any]) == [
['foo', 'bar', 'baz'],
['foo', 'bar', 'qux']
]
开发者ID:boxed,项目名称:instar-py,代码行数:12,代码来源:test_transform.py
示例10: test_without_address
def test_without_address(self):
"""
Handles server json that does not have "addresses" in it.
"""
self.assertEqual(
NovaServer.from_server_details_json(self.servers[0]),
NovaServer(id='a',
state=ServerState.ACTIVE,
image_id='valid_image',
flavor_id='valid_flavor',
created=self.createds[0],
servicenet_address='',
links=freeze(self.servers[0]['links']),
json=freeze(self.servers[0])))
开发者ID:rackerlabs,项目名称:otter,代码行数:14,代码来源:test_model.py
示例11: test_broken_predicate
def test_broken_predicate():
broken_predicates = [
lambda: None,
lambda a, b, c: None,
lambda a, b, c, d=None: None,
lambda *args: None,
lambda **kwargs: None,
]
for pred in broken_predicates:
try:
freeze({}).transform([pred], None)
assert False
except ValueError as e:
assert str(e) == "callable in transform path must take 1 or 2 arguments"
开发者ID:tobgu,项目名称:pyrsistent,代码行数:14,代码来源:transform_test.py
示例12: test_with_servicenet
def test_with_servicenet(self):
"""
Create server that has servicenet IP in it.
"""
self.assertEqual(
NovaServer.from_server_details_json(self.servers[1]),
NovaServer(id='b',
state=ServerState.BUILD,
image_id='valid_image',
flavor_id='valid_flavor',
created=self.createds[1],
servicenet_address='10.0.0.1',
links=freeze(self.servers[1]['links']),
json=freeze(self.servers[1])))
开发者ID:rackerlabs,项目名称:otter,代码行数:14,代码来源:test_model.py
示例13: test_without_private
def test_without_private(self):
"""
Creates server that does not have private/servicenet IP in it.
"""
self.servers[0]['addresses'] = {'public': 'p'}
self.assertEqual(
NovaServer.from_server_details_json(self.servers[0]),
NovaServer(id='a',
state=ServerState.ACTIVE,
image_id='valid_image',
flavor_id='valid_flavor',
created=self.createds[0],
servicenet_address='',
links=freeze(self.servers[0]['links']),
json=freeze(self.servers[0])))
开发者ID:rackerlabs,项目名称:otter,代码行数:15,代码来源:test_model.py
示例14: test_remove_pclass
def test_remove_pclass():
class MyClass(PClass):
a = field()
b = field()
m = freeze({'foo': MyClass(a=1, b=2)})
assert m.transform(['foo', 'b'], discard) == {'foo': MyClass(a=1)}
开发者ID:coventry,项目名称:pyrsistent,代码行数:7,代码来源:transform_test.py
示例15: latest
def latest(**kwargs):
[latest] = filter_records(
records=url_records(
url_mangle(URL_LATEST_TEMPLATE, kwargs),
UbuntuBase,
),
search_record=filter_for_pclass(
pclass_type=UbuntuBase,
pclass_kwargs=dict(
(k, kwargs[k])
for k in ("ubuntu_name", "ubuntu_variant", "release_cycle")
)
)
)
return filter_records(
records=url_records(
url_mangle(URL_DETAILS_TEMPLATE, kwargs),
UbuntuDetail,
),
search_record=filter_for_pclass(
pclass_type=UbuntuDetail,
pclass_kwargs=freeze(kwargs).set(
"release_date", latest.release_date,
)
)
)
开发者ID:332054781,项目名称:flocker,代码行数:26,代码来源:ubuntu.py
示例16: prepare_launch_config
def prepare_launch_config(scaling_group_uuid, launch_config):
"""
Prepare a launch_config for the specified scaling_group.
This is responsible for returning a copy of the launch config that
has metadata and unique server names added.
:param IScalingGroup scaling_group: The scaling group this server is
getting launched for.
:param dict launch_config: The complete launch_config args we want to build
servers from.
:return dict: The prepared launch config.
"""
launch_config = freeze(launch_config)
lb_descriptions = json_to_LBConfigs(launch_config.get('loadBalancers', []))
launch_config = prepare_server_launch_config(
scaling_group_uuid, launch_config, lb_descriptions)
suffix = generate_server_name()
launch_config = set_server_name(launch_config, suffix)
return thaw(launch_config)
开发者ID:meker12,项目名称:otter,代码行数:25,代码来源:launch_server_v1.py
示例17: test_key_value_predicate
def test_key_value_predicate():
m = freeze({
'foo': 1,
'bar': 2,
})
assert m.transform([
lambda k, v: (k, v) == ('foo', 1),
], lambda v: v * 3) == {"foo": 3, "bar": 2}
开发者ID:tobgu,项目名称:pyrsistent,代码行数:8,代码来源:transform_test.py
示例18: set_route_mapping
def set_route_mapping(self, route_mapping):
"""
Record a new route mapping.
:param route_mapping: A new value for the private ``_route_mapping``
attribute.
"""
self._route_mapping = freeze(route_mapping)
开发者ID:LeastAuthority,项目名称:leastauthority.com,代码行数:8,代码来源:_router.py
示例19: test_create_servers
def test_create_servers(self):
"""Logs :obj:`CreateServer`."""
cfg = {'configgy': 'configged', 'nested': {'a': 'b'}}
cfg2 = {'configgy': 'configged', 'nested': {'a': 'c'}}
creates = pbag([
CreateServer(server_config=freeze(cfg)),
CreateServer(server_config=freeze(cfg)),
CreateServer(server_config=freeze(cfg2))
])
self.assert_logs(creates, [
Log('convergence-create-servers',
fields={'num_servers': 2, 'server_config': cfg,
'cloud_feed': True}),
Log('convergence-create-servers',
fields={'num_servers': 1, 'server_config': cfg2,
'cloud_feed': True})
])
开发者ID:rackerlabs,项目名称:otter,代码行数:17,代码来源:test_logging.py
示例20: test_deleting_server
def test_deleting_server(self):
"""
A server whose "OS-EXT-STS:task_state" is "deleting" will be considered
as DELETED
"""
self.servers[0]["OS-EXT-STS:task_state"] = "deleting"
self.assertEqual(
NovaServer.from_server_details_json(self.servers[0]),
NovaServer(id='a',
state=ServerState.DELETED,
image_id='valid_image',
flavor_id='valid_flavor',
created=self.createds[0],
desired_lbs=pset(),
servicenet_address='',
links=freeze(self.servers[0]['links']),
json=freeze(self.servers[0])))
开发者ID:rackerlabs,项目名称:otter,代码行数:17,代码来源:test_model.py
注:本文中的pyrsistent.freeze函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论