def add_cluster(): """Add a cluster """ has_ip_address = 'ip_address' in request.json and isinstance( request.json['ip_address'], str) has_ssh_user = '******' in request.json and isinstance( request.json['ssh_user'], str) has_ssh_pwd = 'ssh_password' in request.json and isinstance( request.json['ssh_password'], str) has_ssh_pk = 'ssh_private_key' in request.json and \ isinstance(request.json['ssh_private_key'], str) if not request.json or not has_ip_address or not has_ssh_user or not has_ssh_pwd \ or not has_ssh_pk: return jsonify({ 'success': False, 'message': 'No JSON payload or payload is invalid' }), 400 try: cluster = Cluster(ip_address=request.json['ip_address'], ssh_user=request.json['ssh_user'], ssh_password=request.json['ssh_password'], ssh_private_key=request.json['ssh_private_key']) db.session.add(cluster) db.session.commit() return jsonify({ 'success': True, 'message': 'Cluster created successfully.' }) except IntegrityError as exc: if isinstance(exc.orig, PyMysqlIntegrityError) and isinstance( exc.orig.args, tuple) and len(exc.orig.args) == 2: code, msg = exc.orig.args if code == 1062: # duplicated cluster return jsonify({'success': False, 'message': msg}), 400 raise exc
def _find_by_no(self, no): cluster = Cluster.find_by_no(no) if not cluster: return {'status': 'failure', 'message': 'Cluster not found.'} result = {'status': 'success', 'cluster': cluster} return result
def _find(self, args): clusters = Cluster.find() result = { 'clusters': clusters, 'status': 'success', } return result
def cluster(): #if current_user.is_authenticated: # return redirect(url_for('cluster.cluster')) form = ClusterCreationForm() if form.validate_on_submit(): cluster = Cluster(cluster_name=form.cluster_name.data, description=form.description.data,cluster_type=form.cluster_type.data, cluster_os=form.cluster_os.data, node_count=form.node_count.data) db.session.add(cluster) db.session.commit() flash('Cluster has been created!!') return redirect(url_for('main.index')) return render_template('cluster/cluster.html', title='cluster', form=form)
def create_cluster(): form = ClusterCreateForm() if form.validate_on_submit(): cluster = Cluster() form.populate_obj(cluster) db.session.add(cluster) db.session.commit() flash('Cluster {} created'.format(form.name.data)) audit_log('created cluster', cluster.name) return redirect(url_for('index')) context = get_context() return _render_template( 'generic_form.html', title='New Cluster', form=form, **context)
def index(): form = ClusterForm() clusters = Cluster.query.order_by(Cluster.id.desc()).all() cluster = Cluster() columns = cluster.serialize_columns() clus = [] for c in clusters: clus.append(c.as_dict()) form.business.choices = [(b.id, b.name) for b in Business.query.order_by('name').all()] base_url = url_for('cluster.index') action_url = url_for('cluster.add') return render_template('cluster.html', title='Cluster', rows=clus, columns=columns, base_url=base_url, action_url=action_url, per_page=current_app.config['ROWS_PER_PAGE'], form=form)
def add(): form = ClusterForm() form.business.choices = [(b.id, b.name) for b in Business.query.order_by('name').all()] if form.validate_on_submit(): cluster_active = form.active.data cluster_name = re.sub('[^A-Za-z0-9_]+', '', form.cluname.data) cluster_domainprefix = re.sub('[^A-Za-z0-9_]+', '', form.domainprefix.data) cluster_business_id = form.business.data cluster = Cluster(name=cluster_name, active=cluster_active, domainprefix=cluster_domainprefix, business_id=cluster_business_id) db.session.add(cluster) db.session.commit() return redirect(url_for('cluster.index'))
def populateClusters(self, cluster,cluster_name,environment,region,product_release_number,region_name, product_name,client_names): try: exists_cluster = db.session.query(Cluster.cluster_name).filter_by(cluster_name=cluster_name).filter_by(region=region).scalar() is not None if exists_cluster: print("cluster already exists") else: cluster_value = Cluster(cluster_name=cluster_name, environment=environment,region=region,is_active=True) db.session.add(cluster_value) print("New cluster is added to database") cluster_id = db.session.query(Cluster.cluster_id).filter_by(cluster_name=cluster_name).first() self.populateComponent(cluster_id, cluster,cluster_name,product_release_number, region_name, product_name,client_names) except Exception as ex: date = datetime.utcnow() tb = sys.exc_info()[2] errorMsg = str(date) + " - File: AWSData.py - Function: populateClusters - " + str(ex.args) + " - on line " + str(tb.tb_lineno) + " \r\n" f.write(errorMsg) f.close()