diff --git a/migrations/versions/16740cdbdd7c_added_a_deleted_at_field_in_vm_table.py b/migrations/versions/16740cdbdd7c_added_a_deleted_at_field_in_vm_table.py new file mode 100644 index 0000000..7f5e0fc --- /dev/null +++ b/migrations/versions/16740cdbdd7c_added_a_deleted_at_field_in_vm_table.py @@ -0,0 +1,28 @@ +"""Added a deleted_at field in Vm table + +Revision ID: 16740cdbdd7c +Revises: +Create Date: 2018-03-15 11:35:59.559663 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '16740cdbdd7c' +down_revision = None +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('vm', sa.Column('deleted_at', sa.DateTime(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('vm', 'deleted_at') + # ### end Alembic commands ### diff --git a/migrations/versions/45b003a9a66f_.py b/migrations/versions/45b003a9a66f_.py deleted file mode 100644 index ac91a31..0000000 --- a/migrations/versions/45b003a9a66f_.py +++ /dev/null @@ -1,62 +0,0 @@ -"""empty message - -Revision ID: 45b003a9a66f -Revises: -Create Date: 2018-02-12 15:32:20.685721 - -""" -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '45b003a9a66f' -down_revision = None -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.create_table( - 'user', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('username', sa.String(length=100), nullable=False), - sa.Column('token', sa.String(length=1000), nullable=True), - sa.Column('email', sa.String(length=100), nullable=True), - sa.Column('name', sa.String(length=100), nullable=True), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('email'), - sa.UniqueConstraint('username') - ) - op.create_table( - 'node_request', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=True), - sa.Column('node_name', sa.String(length=100), nullable=False), - sa.Column('node_counts', sa.Integer(), nullable=False), - sa.Column('hours', sa.Integer(), nullable=False), - sa.Column('pubkey', sa.VARCHAR(length=1024), nullable=False), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id') - ) - op.create_table( - 'vm', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('ip_address', sa.VARCHAR(length=45), nullable=True), - sa.Column('vm_name', sa.String(length=100), nullable=False), - sa.Column('details_id', sa.Integer(), nullable=True), - sa.Column('created_at', sa.DateTime(), nullable=True), - sa.Column('state', sa.String(length=10), nullable=True), - sa.ForeignKeyConstraint(['details_id'], ['node_request.id'], ), - sa.PrimaryKeyConstraint('id') - ) - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.drop_table('vm') - op.drop_table('node_request') - op.drop_table('user') - # ### end Alembic commands ### diff --git a/migrations/versions/ac40d51a4114_.py b/migrations/versions/ac40d51a4114_.py index aa6b1df..25cbbb8 100644 --- a/migrations/versions/ac40d51a4114_.py +++ b/migrations/versions/ac40d51a4114_.py @@ -1,9 +1,7 @@ """Add a new column deleted_at in table vm - Revision ID: ac40d51a4114 Revises: 45b003a9a66f Create Date: 2018-03-20 15:23:15.806539 - """ from alembic import op import sqlalchemy as sa diff --git a/softserve/lib.py b/softserve/lib.py index c7a7888..f8e9c04 100644 --- a/softserve/lib.py +++ b/softserve/lib.py @@ -37,7 +37,7 @@ def wrap(*args, **kwargs): @celery.task() -def create_node(counts, name, node_request, pubkey): +def create_node(counts, name, node_request, pubkey, image): ''' Create a node in the cloud provider ''' @@ -47,7 +47,7 @@ def create_node(counts, name, node_request, pubkey): nova = pyrax.cloudservers flavor = nova.flavors.find(name='1 GB General Purpose v1') - image = nova.images.find(name='CentOS 7 (PVHVM)') + image = nova.images.find(name=image) node_request = NodeRequest.query.get(node_request) keypair = nova.keypairs.create(name, pubkey) # create the nodes diff --git a/softserve/model.py b/softserve/model.py index 16004bf..77fee02 100644 --- a/softserve/model.py +++ b/softserve/model.py @@ -30,6 +30,7 @@ class NodeRequest(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) node_name = db.Column(db.String(100), nullable=False) + image_type = db.Column(db.String(20), nullable=False) node_counts = db.Column(db.Integer, nullable=False) hours = db.Column(db.Integer, nullable=False) pubkey = db.Column(db.VARCHAR(1024), nullable=False) diff --git a/softserve/templates/form.html b/softserve/templates/form.html index 9463cd8..c266a85 100755 --- a/softserve/templates/form.html +++ b/softserve/templates/form.html @@ -21,6 +21,15 @@

Create Nodes

+
+
+ + +
+
diff --git a/softserve/views.py b/softserve/views.py index f824905..b2f6152 100644 --- a/softserve/views.py +++ b/softserve/views.py @@ -84,6 +84,7 @@ def get_node_data(): name = request.form['node_name'] hours_ = request.form['hours'] pubkey_ = request.form['pubkey'] + image = request.form['image'] # Validating the hours and node counts if int(counts) > 5 or int(hours_) > 4 or int(counts) > n: @@ -107,12 +108,13 @@ def get_node_data(): node_request = NodeRequest( user_id=g.user.id, node_name=name, + image_type=image, node_counts=counts, hours=hours_, pubkey=pubkey_) db.session.add(node_request) db.session.commit() - create_node.delay(counts, name, node_request.id, pubkey_) + create_node.delay(counts, name, node_request.id, pubkey_, image) flash('Creating your machine. Please wait for a moment.') return redirect('/dashboard') else: