Added ip, mac, fqdn attrs to Node. Agent updated.

This commit is contained in:
Mike Scherbakov 2012-06-04 18:25:48 +04:00
parent 8797cdf8b5
commit 06e8c59aa3
7 changed files with 36 additions and 10 deletions

2
.gitignore vendored
View File

@ -12,4 +12,4 @@
/.vagrant
# artifact from config handler
test.server.com.json
080000000001.json

View File

@ -11,6 +11,8 @@ module NodeAgent
end
data = { :fqdn => node["fqdn"],
:mac => node["macaddress"],
:ip => node["ipaddress"],
:block_device => node["block_device"].to_hash,
:interfaces => interfaces,
:cpu => node["cpu"].to_hash,

View File

@ -23,8 +23,9 @@ class EnvironmentForm(forms.Form):
def validate_node_metadata(value):
if value is not None:
if isinstance(value, dict):
for field in ('block_device', 'interfaces', 'cpu', 'memory'):
if not field in value:
for field in ('block_device', 'interfaces', 'cpu', 'memory', \
'fqdn', 'ip', 'mac'):
if not field in value or value[field] == "":
raise ValidationError("Node metadata '%s' \
field is required" % field)
else:
@ -44,6 +45,9 @@ class NodeUpdateForm(forms.Form):
metadata = Field(required=False, validators=[validate_node_metadata])
status = ChoiceField(required=False, choices=Node.NODE_STATUSES)
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])
environment_id = IntegerField(required=False)

View File

@ -104,7 +104,7 @@ class NodeCollectionHandler(BaseHandler):
allowed_methods = ('GET', 'POST')
model = Node
fields = ('id', 'name', 'environment_id', 'metadata',
'status', ('roles', ()))
'status', 'mac', 'fqdn', 'ip', ('roles', ()))
def read(self, request):
return Node.objects.all()

View File

@ -32,4 +32,7 @@ class Node(models.Model):
status = models.CharField(max_length=30, choices=NODE_STATUSES,
default='online')
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')

View File

@ -45,16 +45,14 @@ def create_chef_config(environment_id, callback=None):
["role[" + x.name + "]" for x in n.roles.all()]
solo_json['all_roles'] = nodes_per_role
# FIXME!! change name to MAC address!
filepath = os.path.join(settings.CHEF_CONF_FOLDER,
n.name + '.json')
n.id + '.json')
f = open(filepath, 'w')
f.write(json.dumps(solo_json))
f.close()
if callback:
# FIXME!! change name to IP address!
job = group(subtask(callback, args=(n.name, )) for n in nodes)
job = group(subtask(callback, args=(n.ip, )) for n in nodes)
result = job.apply_async()
return True
return True

View File

@ -14,7 +14,10 @@ class TestHandlers(TestCase):
self.old_meta = {'block_device': 'value',
'interfaces': 'val2',
'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,
name='Another environment')
@ -51,7 +54,10 @@ class TestHandlers(TestCase):
self.new_meta = {'block_device': 'new-val',
'interfaces': 'd',
'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)
@ -153,6 +159,7 @@ class TestHandlers(TestCase):
resp = self.client.put(self.node_url,
json.dumps({'metadata': self.new_meta}),
"application/json")
print resp.content
self.assertEquals(resp.status_code, 200)
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(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):
meta = self.new_meta.copy()
del meta['cpu']