Added ip, mac, fqdn attrs to Node. Agent updated.
This commit is contained in:
parent
8797cdf8b5
commit
06e8c59aa3
2
.gitignore
vendored
2
.gitignore
vendored
@ -12,4 +12,4 @@
|
|||||||
/.vagrant
|
/.vagrant
|
||||||
|
|
||||||
# artifact from config handler
|
# artifact from config handler
|
||||||
test.server.com.json
|
080000000001.json
|
||||||
|
@ -11,6 +11,8 @@ module NodeAgent
|
|||||||
end
|
end
|
||||||
|
|
||||||
data = { :fqdn => node["fqdn"],
|
data = { :fqdn => node["fqdn"],
|
||||||
|
:mac => node["macaddress"],
|
||||||
|
:ip => node["ipaddress"],
|
||||||
:block_device => node["block_device"].to_hash,
|
:block_device => node["block_device"].to_hash,
|
||||||
:interfaces => interfaces,
|
:interfaces => interfaces,
|
||||||
:cpu => node["cpu"].to_hash,
|
:cpu => node["cpu"].to_hash,
|
||||||
|
@ -23,8 +23,9 @@ class EnvironmentForm(forms.Form):
|
|||||||
def validate_node_metadata(value):
|
def validate_node_metadata(value):
|
||||||
if value is not None:
|
if value is not None:
|
||||||
if isinstance(value, dict):
|
if isinstance(value, dict):
|
||||||
for field in ('block_device', 'interfaces', 'cpu', 'memory'):
|
for field in ('block_device', 'interfaces', 'cpu', 'memory', \
|
||||||
if not field in value:
|
'fqdn', 'ip', 'mac'):
|
||||||
|
if not field in value or value[field] == "":
|
||||||
raise ValidationError("Node metadata '%s' \
|
raise ValidationError("Node metadata '%s' \
|
||||||
field is required" % field)
|
field is required" % field)
|
||||||
else:
|
else:
|
||||||
@ -44,6 +45,9 @@ class NodeUpdateForm(forms.Form):
|
|||||||
metadata = Field(required=False, validators=[validate_node_metadata])
|
metadata = Field(required=False, validators=[validate_node_metadata])
|
||||||
status = ChoiceField(required=False, choices=Node.NODE_STATUSES)
|
status = ChoiceField(required=False, choices=Node.NODE_STATUSES)
|
||||||
name = CharField(max_length=100, required=False)
|
name = CharField(max_length=100, required=False)
|
||||||
|
fqdn = CharField(max_length=255, required=False)
|
||||||
|
ip = CharField(max_length=15, required=False)
|
||||||
|
mac = CharField(max_length=17, required=False)
|
||||||
roles = Field(required=False, validators=[validate_node_roles])
|
roles = Field(required=False, validators=[validate_node_roles])
|
||||||
environment_id = IntegerField(required=False)
|
environment_id = IntegerField(required=False)
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ class NodeCollectionHandler(BaseHandler):
|
|||||||
allowed_methods = ('GET', 'POST')
|
allowed_methods = ('GET', 'POST')
|
||||||
model = Node
|
model = Node
|
||||||
fields = ('id', 'name', 'environment_id', 'metadata',
|
fields = ('id', 'name', 'environment_id', 'metadata',
|
||||||
'status', ('roles', ()))
|
'status', 'mac', 'fqdn', 'ip', ('roles', ()))
|
||||||
|
|
||||||
def read(self, request):
|
def read(self, request):
|
||||||
return Node.objects.all()
|
return Node.objects.all()
|
||||||
|
@ -32,4 +32,7 @@ class Node(models.Model):
|
|||||||
status = models.CharField(max_length=30, choices=NODE_STATUSES,
|
status = models.CharField(max_length=30, choices=NODE_STATUSES,
|
||||||
default='online')
|
default='online')
|
||||||
metadata = JSONField()
|
metadata = JSONField()
|
||||||
|
mac = models.CharField(max_length=17)
|
||||||
|
ip = models.CharField(max_length=15)
|
||||||
|
fqdn = models.CharField(max_length=255)
|
||||||
roles = models.ManyToManyField(Role, related_name='nodes')
|
roles = models.ManyToManyField(Role, related_name='nodes')
|
||||||
|
@ -45,16 +45,14 @@ def create_chef_config(environment_id, callback=None):
|
|||||||
["role[" + x.name + "]" for x in n.roles.all()]
|
["role[" + x.name + "]" for x in n.roles.all()]
|
||||||
solo_json['all_roles'] = nodes_per_role
|
solo_json['all_roles'] = nodes_per_role
|
||||||
|
|
||||||
# FIXME!! change name to MAC address!
|
|
||||||
filepath = os.path.join(settings.CHEF_CONF_FOLDER,
|
filepath = os.path.join(settings.CHEF_CONF_FOLDER,
|
||||||
n.name + '.json')
|
n.id + '.json')
|
||||||
f = open(filepath, 'w')
|
f = open(filepath, 'w')
|
||||||
f.write(json.dumps(solo_json))
|
f.write(json.dumps(solo_json))
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
if callback:
|
if callback:
|
||||||
# FIXME!! change name to IP address!
|
job = group(subtask(callback, args=(n.ip, )) for n in nodes)
|
||||||
job = group(subtask(callback, args=(n.name, )) for n in nodes)
|
|
||||||
result = job.apply_async()
|
result = job.apply_async()
|
||||||
return True
|
return True
|
||||||
return True
|
return True
|
||||||
|
@ -14,7 +14,10 @@ class TestHandlers(TestCase):
|
|||||||
self.old_meta = {'block_device': 'value',
|
self.old_meta = {'block_device': 'value',
|
||||||
'interfaces': 'val2',
|
'interfaces': 'val2',
|
||||||
'cpu': 'asf',
|
'cpu': 'asf',
|
||||||
'memory': 'sd'
|
'memory': 'sd',
|
||||||
|
'ip': '192.168.124.185',
|
||||||
|
'mac': '08:00:27:99:8F:33',
|
||||||
|
'fqdn': 'test.server.com'
|
||||||
}
|
}
|
||||||
self.another_environment = Environment(id=2,
|
self.another_environment = Environment(id=2,
|
||||||
name='Another environment')
|
name='Another environment')
|
||||||
@ -51,7 +54,10 @@ class TestHandlers(TestCase):
|
|||||||
self.new_meta = {'block_device': 'new-val',
|
self.new_meta = {'block_device': 'new-val',
|
||||||
'interfaces': 'd',
|
'interfaces': 'd',
|
||||||
'cpu': 'u',
|
'cpu': 'u',
|
||||||
'memory': 'a'
|
'memory': 'a',
|
||||||
|
'ip': '10.1.1.1',
|
||||||
|
'mac': '09:02:FB:AA:AB:AC',
|
||||||
|
'fqdn': 'new.com'
|
||||||
}
|
}
|
||||||
self.meta_json = json.dumps(self.new_meta)
|
self.meta_json = json.dumps(self.new_meta)
|
||||||
|
|
||||||
@ -153,6 +159,7 @@ class TestHandlers(TestCase):
|
|||||||
resp = self.client.put(self.node_url,
|
resp = self.client.put(self.node_url,
|
||||||
json.dumps({'metadata': self.new_meta}),
|
json.dumps({'metadata': self.new_meta}),
|
||||||
"application/json")
|
"application/json")
|
||||||
|
print resp.content
|
||||||
self.assertEquals(resp.status_code, 200)
|
self.assertEquals(resp.status_code, 200)
|
||||||
|
|
||||||
nodes_from_db = Node.objects.filter(id=self.node.id)
|
nodes_from_db = Node.objects.filter(id=self.node.id)
|
||||||
@ -214,6 +221,18 @@ class TestHandlers(TestCase):
|
|||||||
self.assertEquals(len(nodes_from_db), 1)
|
self.assertEquals(len(nodes_from_db), 1)
|
||||||
self.assertEquals(nodes_from_db[0].metadata, self.old_meta)
|
self.assertEquals(nodes_from_db[0].metadata, self.old_meta)
|
||||||
|
|
||||||
|
def test_put_returns_400_if_ipaddress_empty(self):
|
||||||
|
meta = self.new_meta.copy()
|
||||||
|
meta['ip'] = ""
|
||||||
|
resp = self.client.put(self.node_url,
|
||||||
|
json.dumps({'metadata': meta}),
|
||||||
|
"application/json")
|
||||||
|
self.assertEquals(resp.status_code, 400)
|
||||||
|
|
||||||
|
nodes_from_db = Node.objects.filter(id=self.node.id)
|
||||||
|
self.assertEquals(len(nodes_from_db), 1)
|
||||||
|
self.assertEquals(nodes_from_db[0].metadata, self.old_meta)
|
||||||
|
|
||||||
def test_put_returns_400_if_no_cpu_attr(self):
|
def test_put_returns_400_if_no_cpu_attr(self):
|
||||||
meta = self.new_meta.copy()
|
meta = self.new_meta.copy()
|
||||||
del meta['cpu']
|
del meta['cpu']
|
||||||
|
Loading…
Reference in New Issue
Block a user