Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a ability to select image type of VM #39

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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 ###
62 changes: 0 additions & 62 deletions migrations/versions/45b003a9a66f_.py

This file was deleted.

2 changes: 0 additions & 2 deletions migrations/versions/ac40d51a4114_.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions softserve/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
'''
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions softserve/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions softserve/templates/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ <h3>Create Nodes</h3>
<input type="text" class="form-control" name="node_name" data-toggle="tooltip" title='Should not contain any special characters except underscore' required>
</div>
</div>
<div class='row'>
<div class="form-group col-md-5">
<label for="image">Image type</label>
<select class="form-control" name="image">
<option value="CentOS 7 (PVHVM)">CentOS7</option>
<option value="centos7-devel">CentOS7-devel</option>
</select>
</div>
</div>
<div class='row'>
<div class="form-group col-md-5">
<label for="hours">Number of hours</label>
Expand Down
4 changes: 3 additions & 1 deletion softserve/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down