Still wip
This commit is contained in:
parent
c6df20ad7b
commit
00ac4e3a0b
@ -3,14 +3,5 @@ handler: ansible
|
||||
version: 1.0.0
|
||||
|
||||
input:
|
||||
ip:
|
||||
schema: str!
|
||||
value:
|
||||
ssh_key:
|
||||
schema: str!
|
||||
value:
|
||||
ssh_user:
|
||||
schema: str!
|
||||
value:
|
||||
hosts:
|
||||
schema: [{name: str!, ip: str!}]
|
||||
|
@ -14,4 +14,7 @@ input:
|
||||
# value:
|
||||
name:
|
||||
schema: str
|
||||
value:
|
||||
value: a node
|
||||
location_id:
|
||||
schema: str!
|
||||
value: $uuid
|
||||
|
@ -12,3 +12,7 @@ input:
|
||||
name:
|
||||
schema: str!
|
||||
value: ssh
|
||||
location_id:
|
||||
schema: str!
|
||||
value:
|
||||
reverse: True
|
||||
|
@ -3,3 +3,11 @@ input:
|
||||
transports:
|
||||
schema: [{user: str, password: str, port: int!, key: str, name: str!}]
|
||||
value: []
|
||||
transports_id:
|
||||
schema: str!
|
||||
value: $uuid
|
||||
reverse: True
|
||||
location_id:
|
||||
schema: str!
|
||||
value:
|
||||
reverse: True
|
||||
|
@ -87,8 +87,23 @@ class Resource(object):
|
||||
self.virtual_resource = None
|
||||
|
||||
def auto_extend_inputs(self, inputs):
|
||||
inputs.setdefault('location_id', {'value': md5(self.name + uuid4().hex).hexdigest(),
|
||||
# inputs.setdefault('location_id', {'value': md5(self.name + uuid4().hex).hexdigest(),
|
||||
# 'schema': 'str!'})
|
||||
inputs.setdefault('location_id', {'value': "",
|
||||
'schema': 'str!'})
|
||||
inputs.setdefault('transports_id', {'value': "",
|
||||
'schema': 'str'})
|
||||
for inp in ('transports_id', 'location_id'):
|
||||
if inputs[inp]['value'] == '$uuid':
|
||||
inputs[inp]['value'] = md5(self.name + uuid4().hex).hexdigest()
|
||||
|
||||
def transports(self):
|
||||
inputs = self.resource_inputs()
|
||||
location_id = inputs['transports_id']
|
||||
print 'tu'
|
||||
print location_id.backtrack_value(lazy_val='transports')
|
||||
print 'tu2'
|
||||
|
||||
|
||||
@property
|
||||
def actions(self):
|
||||
|
@ -46,17 +46,50 @@ def guess_mapping(emitter, receiver):
|
||||
|
||||
return guessed
|
||||
|
||||
def extend_mapping_by_defaults(mapping):
|
||||
if isinstance(mapping, set):
|
||||
mapping.add('location_id')
|
||||
else:
|
||||
mapping['location_id'] = 'location_id'
|
||||
|
||||
def location_and_transports(emitter, receiver, orig_mapping):
|
||||
|
||||
def _remove_from_mapping(single):
|
||||
if single in orig_mapping:
|
||||
if isinstance(orig_mapping, dict):
|
||||
del orig_mapping[single]
|
||||
elif isinstance(orig_mapping, set):
|
||||
orig_mapping.remove(single)
|
||||
|
||||
def _single(single):
|
||||
emitter_single = emitter.db_obj.meta_inputs[single]
|
||||
receiver_single = receiver.db_obj.meta_inputs[single]
|
||||
emitter_single_reverse = emitter_single.get('reverse')
|
||||
receiver_single_reverse = receiver_single.get('reverse')
|
||||
print emitter_single, receiver_single
|
||||
# connect in other direction
|
||||
if emitter_single_reverse:
|
||||
connect_single(receiver, single, emitter, single)
|
||||
_remove_from_mapping(single)
|
||||
return
|
||||
if isinstance(orig_mapping, dict):
|
||||
orig_mapping[single] = single
|
||||
# if we have reverse then do it in reverse way
|
||||
# if emitter_single.get('reverse'):
|
||||
# connect_single(receiver, single, emitter, single)
|
||||
# # maybe already connected somewhere, then don't create this relation
|
||||
# if not emitter.resource_inputs()[single].backtrack_value():
|
||||
# connect_single(receiver, single, emitter, single)
|
||||
# elif not receiver_single.get('reverse', False):
|
||||
# # maybe already connected somewhere, then don't create this relation
|
||||
# if not receiver.resource_inputs()[single].backtrack_value():
|
||||
# if isinstance(orig_mapping, dict):
|
||||
# orig_mapping[single] = single
|
||||
|
||||
for single in ('transports_id', 'location_id'):
|
||||
_single(single)
|
||||
return
|
||||
|
||||
|
||||
def connect(emitter, receiver, mapping=None, events=None):
|
||||
mapping = mapping or guess_mapping(emitter, receiver)
|
||||
|
||||
extend_mapping_by_defaults(mapping)
|
||||
|
||||
location_and_transports(emitter, receiver, mapping)
|
||||
|
||||
if isinstance(mapping, set):
|
||||
mapping = {src: src for src in mapping}
|
||||
@ -102,7 +135,8 @@ def connect_single(emitter, src, receiver, dst):
|
||||
# Check for cycles
|
||||
# TODO: change to get_paths after it is implemented in drivers
|
||||
if emitter_input in receiver_input.receivers.as_set():
|
||||
raise Exception('Prevented creating a cycle')
|
||||
raise Exception('Prevented creating a cycle on %s::%s' % (emitter.name,
|
||||
emitter_input.name))
|
||||
|
||||
log.debug('Connecting {}::{} -> {}::{}'.format(
|
||||
emitter.name, emitter_input.name, receiver.name, receiver_input.name
|
||||
|
@ -445,6 +445,13 @@ class DBResourceInput(DBObject):
|
||||
if not inputs:
|
||||
return self
|
||||
|
||||
# if lazy_val is None:
|
||||
# return self.value
|
||||
# print self.resource.name
|
||||
# print [x.name for x in self.resource.inputs.as_set()]
|
||||
# _input = next(x for x in self.resource.inputs.as_set() if x.name == lazy_val)
|
||||
# return _input.backtrack_value()
|
||||
# # return self.value
|
||||
if self.is_list:
|
||||
if not self.is_hash:
|
||||
return [backtrack_func(i) for i in inputs]
|
||||
|
Loading…
Reference in New Issue
Block a user