本文整理汇总了Python中solar.core.signals.connect函数的典型用法代码示例。如果您正苦于以下问题:Python connect函数的具体用法?Python connect怎么用?Python connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_input_dict_type
def test_input_dict_type(self):
sample_meta_dir = self.make_resource_meta("""
id: sample
handler: ansible
version: 1.0.0
input:
values:
schema: {a: int, b: int}
value: {}
""")
sample1 = self.create_resource('sample1', sample_meta_dir, {'values':
{'a': 1,
'b': 2}})
sample2 = self.create_resource('sample2', sample_meta_dir)
xs.connect(sample1, sample2)
self.assertEqual(sample1.args['values'], sample2.args['values'])
# Check update
sample1.update({'values': {'a': 2}})
self.assertEqual(sample1.args['values'], {'a': 2})
self.assertEqual(sample1.args['values'], sample2.args['values'], )
# Check disconnect
# TODO: should sample2.value be reverted to original value?
sample1.disconnect(sample2)
sample1.update({'values': {'a': 3}})
self.assertEqual(sample1.args['values'], {'a': 3})
示例2: connect_list_to_each
def connect_list_to_each(self, resources, args={}, events=None):
"""Connect each resource in self.resources to each resource in resources.
args -- optional list of arguments
"{emitter_num}" -- substitutes for emitter's index in args (from
self.resources)
"{receiver_num}" -- substitutes for receiver's index in args (from
resources argument)
"""
for emitter_num, emitter in enumerate(self.resources):
for receiver_num, receiver in enumerate(resources.resources):
kwargs = {
'emitter_num': emitter_num,
'receiver_num': receiver_num,
}
args_fmt = self.args_fmt(args, kwargs)
signals.connect(
emitter,
receiver,
mapping=args_fmt,
events=events
)
示例3: setup_resources
def setup_resources():
ModelMeta.remove_all()
node2 = vr.create('node2', 'resources/ro_node/', {
'ip': '10.0.0.4',
'ssh_key': '/vagrant/.vagrant/machines/solar-dev2/virtualbox/private_key',
'ssh_user': 'vagrant'
})[0]
solar_bootstrap2 = vr.create('solar_bootstrap2', 'resources/solar_bootstrap', {'master_ip': '10.0.0.2'})[0]
signals.connect(node2, solar_bootstrap2)
has_errors = False
for r in locals().values():
if not isinstance(r, resource.Resource):
continue
print 'Validating {}'.format(r.name)
errors = validation.validate_resource(r)
if errors:
has_errors = True
print 'ERROR: %s: %s' % (r.name, errors)
if has_errors:
sys.exit(1)
示例4: deploy
def deploy(filename):
with open(filename) as f:
config = yaml.load(f)
workdir = config['workdir']
resource_save_path = os.path.join(workdir, config['resource-save-path'])
# Clean stuff first
db.clear()
xs.Connections.clear()
shutil.rmtree(resource_save_path, ignore_errors=True)
os.makedirs(resource_save_path)
# Create resources first
for resource_definition in config['resources']:
name = resource_definition['name']
model = os.path.join(workdir, resource_definition['model'])
args = resource_definition.get('args', {})
log.debug('Creating %s %s %s %s', name, model, resource_save_path, args)
xr.create(name, model, resource_save_path, args=args)
# Create resource connections
for connection in config['connections']:
emitter = db.get_resource(connection['emitter'])
receiver = db.get_resource(connection['receiver'])
mapping = connection.get('mapping')
log.debug('Connecting %s %s %s', emitter.name, receiver.name, mapping)
xs.connect(emitter, receiver, mapping=mapping)
# Run all tests
if 'test-suite' in config:
log.debug('Running tests from %s', config['test-suite'])
test_suite = __import__(config['test-suite'], {}, {}, ['main'])
test_suite.main()
示例5: create_virtual_resource
def create_virtual_resource(vr_name, template):
resources = template["resources"]
connections = []
created_resources = []
cwd = os.getcwd()
for resource in resources:
name = resource["id"]
base_path = os.path.join(cwd, resource["from"])
args = resource["values"]
new_resources = create(name, base_path, args, vr_name)
created_resources += new_resources
if not is_virtual(base_path):
for key, arg in args.items():
if isinstance(arg, basestring) and "::" in arg:
emitter, src = arg.split("::")
connections.append((emitter, name, {src: key}))
db = load_all()
for emitter, reciver, mapping in connections:
emitter = db[emitter]
reciver = db[reciver]
signals.connect(emitter, reciver, mapping)
return created_resources
示例6: connect_with_events
def connect_with_events(self, receiver, mapping=None, events=None,
use_defaults=False):
signals.connect(self, receiver, mapping=mapping)
if use_defaults:
api.add_default_events(self, receiver)
if events:
api.add_events(self.name, events)
示例7: test_revert_removed_child
def test_revert_removed_child():
res1 = orm.DBResource(id='test1', name='test1', base_path='x')
res1.save()
res1.add_input('a', 'str', '9')
res2 = orm.DBResource(id='test2', name='test2', base_path='x')
res2.save()
res2.add_input('a', 'str', 0)
res1 = resource.load('test1')
res2 = resource.load('test2')
signals.connect(res1, res2)
staged_log = change.stage_changes()
assert len(staged_log) == 2
for item in staged_log:
operations.move_to_commited(item.log_action)
res2.remove()
staged_log = change.stage_changes()
assert len(staged_log) == 1
logitem = next(staged_log.collection())
operations.move_to_commited(logitem.log_action)
with mock.patch.object(resource, 'read_meta') as mread:
mread.return_value = {'input': {'a': {'schema': 'str!'}}}
change.revert(logitem.uid)
res2 = resource.load('test2')
assert res2.args == {'a': '9'}
示例8: test_no_cycles
def test_no_cycles(self):
sample_meta_dir = self.make_resource_meta("""
id: sample
handler: ansible
version: 1.0.0
input:
value:
schema: str!
value:
""")
sample1 = self.create_resource(
'sample1', sample_meta_dir, {'value': 'x'}
)
sample2 = self.create_resource(
'sample2', sample_meta_dir, {'value': 'y'}
)
xs.connect(sample1, sample2)
with self.assertRaisesRegexp(
Exception,
'Prevented creating a cycle'):
xs.connect(sample2, sample1)
示例9: test_revert_removed_child
def test_revert_removed_child():
res1 = orm.DBResource(id="test1", name="test1", base_path="x") # NOQA
res1.save()
res1.add_input("a", "str", "9")
res2 = orm.DBResource(id="test2", name="test2", base_path="x") # NOQA
res2.save()
res2.add_input("a", "str", 0)
res1 = resource.load("test1")
res2 = resource.load("test2")
signals.connect(res1, res2)
staged_log = change.stage_changes()
assert len(staged_log) == 2
for item in staged_log:
operations.move_to_commited(item.log_action)
res2.remove()
staged_log = change.stage_changes()
assert len(staged_log) == 1
logitem = next(staged_log.collection())
operations.move_to_commited(logitem.log_action)
with mock.patch.object(resource, "read_meta") as mread:
mread.return_value = {"input": {"a": {"schema": "str!"}}}
change.revert(logitem.uid)
res2 = resource.load("test2")
assert res2.args == {"a": "9"}
示例10: prepare_nodes
def prepare_nodes(nodes_count):
resources = vr.create("nodes", "templates/nodes_with_transports.yaml", {"count": nodes_count})
nodes = [x for x in resources if x.name.startswith("node")]
resources = vr.create("nodes_network", "templates/nodes_network.yaml", {"count": nodes_count})
nodes_sdn = [x for x in resources if x.name.startswith("node")]
r = {}
for node, node_sdn in zip(nodes, nodes_sdn):
r[node.name] = node
r[node_sdn.name] = node_sdn
# LIBRARIAN
librarian = vr.create("librarian_{}".format(node.name), "resources/librarian", {})[0]
r[librarian.name] = librarian
node.connect(librarian, {})
# NETWORKING
# TODO(bogdando) node's IPs should be populated as br-mgmt IPs, but now are hardcoded in templates
signals.connect(node, node_sdn)
node_sdn.connect_with_events(librarian, {"module": "modules"}, {})
evapi.add_dep(librarian.name, node_sdn.name, actions=("run", "update"))
signals.connect(node, node_sdn)
node_sdn.connect_with_events(librarian, {"module": "modules"}, {})
evapi.add_dep(librarian.name, node_sdn.name, actions=("run", "update"))
return r
示例11: connect_list_to_each
def connect_list_to_each(self, resources, mapping=None, events=None):
"""Connect each resource in self.resources to each resource in resources.
mapping -- optional mapping
"{emitter_num}" -- substitutes for emitter's index in mapping (from
self.resources)
"{receiver_num}" -- substitutes for receiver's index in mapping (from
resources argument)
"""
mapping = mapping or {}
for emitter_num, emitter in enumerate(self.resources):
for receiver_num, receiver in enumerate(resources.resources):
kwargs = {
'emitter_num': emitter_num,
'receiver_num': receiver_num,
}
mapping_fmt = self.args_fmt(mapping, kwargs)
signals.connect(
emitter,
receiver,
mapping=mapping_fmt,
events=events
)
示例12: prepare_nodes
def prepare_nodes(nodes_count):
resources = cr.create('nodes', 'templates/nodes', {"count": nodes_count})
nodes = resources.like('node')
resources = cr.create('nodes_network', 'templates/nodes_network', {"count": nodes_count})
nodes_sdn = resources.like('node')
r = {}
for node, node_sdn in zip(nodes, nodes_sdn):
r[node.name] = node
r[node_sdn.name] = node_sdn
# LIBRARIAN
librarian = cr.create('librarian_{}'.format(node.name), 'resources/librarian', {})[0]
r[librarian.name] = librarian
node.connect(librarian, {})
# NETWORKING
# TODO(bogdando) node's IPs should be populated as br-mgmt IPs, but now are hardcoded in templates
signals.connect(node, node_sdn)
node_sdn.connect_with_events(librarian, {'module': 'modules'}, {})
evapi.add_dep(librarian.name, node_sdn.name, actions=('run', 'update'))
signals.connect(node, node_sdn)
node_sdn.connect_with_events(librarian, {'module': 'modules'}, {})
evapi.add_dep(librarian.name, node_sdn.name, actions=('run', 'update'))
return r
示例13: test_hash_input_with_multiple_connections
def test_hash_input_with_multiple_connections(self):
sample_meta_dir = self.make_resource_meta("""
id: sample
handler: ansible
version: 1.0.0
input:
ip:
schema: str!
value:
""")
receiver_meta_dir = self.make_resource_meta("""
id: receiver
handler: ansible
version: 1.0.0
input:
ip:
schema: str!
value:
server:
schema: {ip: str!}
""")
sample = self.create_resource('sample',
sample_meta_dir,
args={'ip': '10.0.0.1'})
receiver = self.create_resource('receiver', receiver_meta_dir)
xs.connect(sample, receiver, mapping={'ip': ['ip', 'server:ip']})
self.assertEqual(sample.args['ip'], receiver.args['ip'])
self.assertDictEqual({'ip': sample.args['ip']},
receiver.args['server'], )
示例14: test_simple_observer_unsubscription
def test_simple_observer_unsubscription(self):
sample_meta_dir = self.make_resource_meta("""
id: sample
handler: ansible
version: 1.0.0
input:
ip:
schema: str
value:
""")
sample = self.create_resource('sample', sample_meta_dir, {'ip': None})
sample1 = self.create_resource('sample1', sample_meta_dir,
{'ip': '10.0.0.1'})
sample2 = self.create_resource('sample2', sample_meta_dir,
{'ip': '10.0.0.2'})
xs.connect(sample1, sample)
self.assertEqual(sample1.args['ip'], sample.args['ip'])
xs.connect(sample2, sample)
self.assertEqual(sample2.args['ip'], sample.args['ip'])
# sample should be unsubscribed from sample1 and subscribed to sample2
sample2.update({'ip': '10.0.0.3'})
self.assertEqual(sample2.args['ip'], sample.args['ip'])
示例15: test_hash_input_with_list
def test_hash_input_with_list(self):
sample_meta_dir = self.make_resource_meta("""
id: sample
handler: ansible
version: 1.0.0
input:
ip:
schema: str!
value:
port:
schema: int!
value:
""")
receiver_meta_dir = self.make_resource_meta("""
id: receiver
handler: ansible
version: 1.0.0
input:
server:
schema: [{ip: str!, port: int!}]
""")
sample1 = self.create_resource('sample1',
sample_meta_dir,
args={'ip': '10.0.0.1',
'port': 5000})
receiver = self.create_resource('receiver', receiver_meta_dir)
xs.connect(sample1,
receiver,
mapping={
'ip': 'server:ip',
'port': 'server:port'
})
self.assertItemsEqual(
[{'ip': sample1.args['ip'],
'port': sample1.args['port']}],
receiver.args['server'], )
sample2 = self.create_resource('sample2',
sample_meta_dir,
args={'ip': '10.0.0.2',
'port': 5001})
xs.connect(sample2,
receiver,
mapping={
'ip': 'server:ip',
'port': 'server:port'
})
self.assertItemsEqual(
[{'ip': sample1.args['ip'],
'port': sample1.args['port']}, {'ip': sample2.args['ip'],
'port': sample2.args['port']}],
receiver.args['server'], )
sample1.disconnect(receiver)
self.assertItemsEqual(
[{'ip': sample2.args['ip'],
'port': sample2.args['port']}],
receiver.args['server'], )