equal
deleted
inserted
replaced
99 Return Host from an (expanded) config section. |
99 Return Host from an (expanded) config section. |
100 |
100 |
101 name - (expanded) name of host |
101 name - (expanded) name of host |
102 domain - domain for host |
102 domain - domain for host |
103 config - host config fields to parse |
103 config - host config fields to parse |
104 |
104 |
|
105 Fields can either be scalar string values, or instance'd dicts. If a field has both a non-instance'd value and instance'd values, |
|
106 the non-instance'd value will be use instance=None: |
|
107 |
105 Raises ValueError. |
108 Raises ValueError. |
106 """ |
109 """ |
107 |
110 |
108 fields = { } |
111 fields = { } |
109 extensions = fields['extensions'] = { } |
112 extensions = fields['extensions'] = { } |
113 |
116 |
114 if extension: |
117 if extension: |
115 f = extensions.setdefault(extension, {}) |
118 f = extensions.setdefault(extension, {}) |
116 else: |
119 else: |
117 f = fields |
120 f = fields |
118 |
121 |
119 if not instance and field not in f: |
122 if instance: |
|
123 if field not in f: |
|
124 f[field] = { } |
|
125 elif not isinstance(f[field], dict): |
|
126 # convert to dict |
|
127 f[field] = {None: f[field]} |
|
128 |
|
129 f[field][instance] = value |
|
130 else: |
120 f[field] = value |
131 f[field] = value |
121 |
|
122 elif field not in f: |
|
123 f[field] = {instance: value} |
|
124 elif isinstance(f[field], dict): |
|
125 f.setdefault(field, {})[instance] = value |
|
126 else: |
|
127 raise ValueError("override instanced {field} value: {value}".format(field=field, value=value)) |
|
128 |
132 |
129 return Host.build(name, domain, **fields) |
133 return Host.build(name, domain, **fields) |
130 |
134 |
131 def apply_hosts (parent, name, config): |
135 def apply_hosts (parent, name, config): |
132 """ |
136 """ |