Integrated new_ui 'Add Cluster' functionality with back-end

Notes:
* Mongo's Object('sdfsdf') is not JSON serializable, made str(doc['_id'])) to fix
* In my version there is no method .asdict on recordtype, only _asdict
This commit is contained in:
Kirill Ishanov
2013-10-20 04:32:23 -07:00
parent a4eb7b8428
commit c2133435df
3 changed files with 20 additions and 7 deletions

View File

@@ -30,9 +30,10 @@ angular.module('rubick.controllers', []).
}); });
$scope.addCluster = function() { $scope.addCluster = function() {
$scope.newCluster.nodesCount = 20; console.log($scope.newCluster);
$scope.newCluster.status = "Available"; $http.post('/clusters', $scope.newCluster).success(function() {
$scope.clusters.push($scope.newCluster); $scope.clusters.push($scope.newCluster);
});
$scope.newCluster = undefined; $scope.newCluster = undefined;
$('#add-cluster-modal').modal('hide'); $('#add-cluster-modal').modal('hide');
} }

View File

@@ -47,10 +47,21 @@
</div> </div>
</div> </div>
</div> </div>
<div class="field">
<label>SSH Key (for root user)</label>
<div class="ui left labeled icon input">
<textarea ng-model="newCluster.description"></textarea>
<!--<i class="file icon"></i>-->
<!--<div class="ui corner label">-->
<!--<i class="icon asterisk"></i>-->
<!--</div>-->
</div>
</div>
<div class="field"> <div class="field">
<label>IP Address (of any node in management network)</label> <label>IP Address (of any node in management network)</label>
<div class="ui left labeled icon input"> <div class="ui left labeled icon input">
<input type="text" placeholder="172.168.10.5" ng-model="newCluster.ip"> <input type="text" placeholder="172.168.10.5"
ng-model="newCluster.nodes">
<i class="terminal icon"></i> <i class="terminal icon"></i>
<div class="ui corner label"> <div class="ui corner label">
<i class="icon asterisk"></i> <i class="icon asterisk"></i>
@@ -60,7 +71,7 @@
<div class="field"> <div class="field">
<label>SSH Key (for root user)</label> <label>SSH Key (for root user)</label>
<div class="ui left labeled icon input"> <div class="ui left labeled icon input">
<textarea ng-model="newCluster.sshKey"></textarea> <textarea ng-model="newCluster.private_key"></textarea>
<i class="file icon"></i> <i class="file icon"></i>
<div class="ui corner label"> <div class="ui corner label">
<i class="icon asterisk"></i> <i class="icon asterisk"></i>

View File

@@ -37,7 +37,7 @@ class Cluster(recordtype('Cluster',
default=None)): default=None)):
@classmethod @classmethod
def from_doc(klass, doc): def from_doc(klass, doc):
doc['id'] = doc['_id'] doc['id'] = str(doc['_id'])
del doc['_id'] del doc['_id']
return Cluster(**doc) return Cluster(**doc)
@@ -90,11 +90,12 @@ def get_clusters():
@app.route('/clusters', methods=['POST']) @app.route('/clusters', methods=['POST'])
def add_cluster(): def add_cluster():
print request.data
form = ClusterForm.from_json(json.loads(request.data)) form = ClusterForm.from_json(json.loads(request.data))
if form.validate(): if form.validate():
cluster = Cluster() cluster = Cluster()
form.populate_obj(cluster) form.populate_obj(cluster)
get_db()['clusters'].save(cluster.asdict()) get_db()['clusters'].save(cluster._asdict())
return '', 201 return '', 201
else: else:
return json.dumps(dict(errors=form.errors)), 422 return json.dumps(dict(errors=form.errors)), 422