Skip to content

Commit 8e6f011

Browse files
committed
renamed scripts folder
1 parent 41c3621 commit 8e6f011

12 files changed

Lines changed: 163 additions & 2 deletions
File renamed without changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
from django.conf import settings
3+
4+
# NOVA CONFIGS
5+
NOVA_FLOATING_IP_CREATION = True
6+
NOVA_FLOATING_IP_POOL = 'public'
7+
8+
NOVA_IMAGE_NAME = "ubuntu"
9+
10+
NOVA_QUOTA_INSTANCES = -1
11+
NOVA_QUOTA_CORES = -1
12+
NOVA_QUOTA_RAM = -1
13+
NOVA_QUOTA_FIXED_IPS = -1
14+
NOVA_QUOTA_FLOATING_IPS = -1
15+
16+
NOVA_VM_FLAVOR = "traffic"
17+
NOVA_VM_FLAVOR_RAM = 2048 # In Mega Bytes
18+
NOVA_VM_FLAVOR_VCPUS = 1
19+
NOVA_VM_FLAVOR_DISK = 10 # In Giga Bytes
20+
21+
22+
# GLANCE CONFIGS
23+
GLANCE_ENDPOINT = "http://172.168.2.40:9292"
24+
25+
GLANCE_IMAGE_NAME = NOVA_IMAGE_NAME
26+
GLANCE_IMAGE_PATH = os.path.join(settings.MEDIA_ROOT, os.path.join("osimages", "ubuntu.img"))
27+
GLANCE_IMAGE_DISK_FORMAT = "qcow2"
28+
GLANCE_IMAGE_CONTAINER_FORMAT = "bare"
29+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from glanceclient.v2 import client as glance_client
2+
from openstackclientutils import OpenStackClientUtils
3+
from config import *
4+
5+
6+
class GlanceClientUtils(OpenStackClientUtils):
7+
client_class = glance_client.Client
8+
9+
def __init__(self, **credentials):
10+
super(GlanceClientUtils, self).__init__(**credentials)
11+
self.glance = self.get_client_instance()
12+
13+
def upload_image(self):
14+
image = self.glance.images.create(
15+
disk_format=GLANCE_IMAGE_DISK_FORMAT,
16+
container_format=GLANCE_IMAGE_CONTAINER_FORMAT,
17+
name=GLANCE_IMAGE_NAME)
18+
self.glance.images.upload(image.id, open(GLANCE_IMAGE_PATH, 'rb'))
19+
return image

ntt_tool/apps/cloud/scripts/keystoneclientutils.py renamed to ntt_tool/apps/cloud/openstackscripts/keystoneclientutils.py

File renamed without changes.

ntt_tool/apps/cloud/scripts/neutronclientutils.py renamed to ntt_tool/apps/cloud/openstackscripts/neutronclientutils.py

File renamed without changes.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import time
2+
import os
3+
from novaclient.v1_1 import client as nova_client
4+
from novaclient.exceptions import NotFound
5+
from openstackclientutils import OpenStackClientUtils
6+
from keystoneclientutils import KeystoneClientUtils
7+
from glanceclientutils import GlanceClientUtils
8+
from config import *
9+
10+
11+
class NovaClientUtils(OpenStackClientUtils):
12+
client_class = nova_client.Client
13+
14+
def __init__(self, **credentials):
15+
super(NovaClientUtils, self).__init__(**credentials)
16+
self.nova = self.get_client_instance()
17+
18+
def assign_floating_ip(self, instance):
19+
if NOVA_FLOATING_IP_CREATION:
20+
floating_ip = self.nova.floating_ips.create(NOVA_FLOATING_IP_POOL)
21+
instance.add_floating_ip(floating_ip)
22+
return True
23+
return False
24+
25+
def launch_vm(self, tenant_id, network_id, vm_name):
26+
"""
27+
Launches VM on given tenant and network
28+
:param tenant_id:
29+
:param network_id:
30+
:param vm_name:
31+
:return: VM instance
32+
"""
33+
self.nova.quotas.update(tenant_id,
34+
instances=NOVA_QUOTA_INSTANCES,
35+
cores=NOVA_QUOTA_CORES,
36+
ram=NOVA_QUOTA_RAM,
37+
fixed_ips=NOVA_QUOTA_FIXED_IPS,
38+
floating_ips=NOVA_QUOTA_FLOATING_IPS)
39+
40+
user_data = None
41+
user_data_file_path = os.path.join(os.path.dirname(__file__), 'user.txt')
42+
with open(user_data_file_path, 'r') as f:
43+
user_data = f.read()
44+
45+
image = None
46+
try:
47+
image = self.nova.images.find(name=NOVA_IMAGE_NAME)
48+
except NotFound:
49+
# Uploading image if does not exist.
50+
keystone_credentials = {
51+
"username": self.credentials.get("username"),
52+
"password": self.credentials.get("api_key"),
53+
"auth_url": self.credentials.get("auth_url"),
54+
"tenant_name": self.credentials.get("project_id")
55+
}
56+
keystone = KeystoneClientUtils(**keystone_credentials)
57+
glance = GlanceClientUtils(endpoint=GLANCE_ENDPOINT,
58+
token=keystone.get_token())
59+
image = glance.upload_image()
60+
61+
# Creating flavor
62+
flavor = None
63+
try:
64+
flavor = self.nova.flavors.find(name=NOVA_VM_FLAVOR)
65+
except NotFound:
66+
flavor = self.nova.flavors.create(name=NOVA_VM_FLAVOR,
67+
ram=NOVA_VM_FLAVOR_RAM,
68+
vcpus=NOVA_VM_FLAVOR_VCPUS,
69+
disk=NOVA_VM_FLAVOR_DISK)
70+
# Launching VM
71+
instance = self.nova.servers.create(name=vm_name,
72+
image=image,
73+
flavor=flavor,
74+
key_name="admin",
75+
nics=[{'net-id': network_id}],
76+
userdata=user_data)
77+
78+
# Waiting and querying instance till instance status becomes active
79+
while instance.status == 'BUILD':
80+
time.sleep(10)
81+
instance = self.nova.servers.get(instance.id)
82+
83+
# Assigning floating IP to the instance
84+
self.assign_floating_ip(instance)
85+
86+
return {
87+
"instance_name": vm_name,
88+
"instance_status": instance.status
89+
}
90+
91+
92+
93+
94+
95+

ntt_tool/apps/cloud/scripts/openstackclientutils.py renamed to ntt_tool/apps/cloud/openstackscripts/openstackclientutils.py

File renamed without changes.

‎ntt_tool/apps/cloud/openstackscripts/openstackcredentials.py‎

Whitespace-only changes.

ntt_tool/apps/cloud/scripts/tenantnetworkdiscovery.py renamed to ntt_tool/apps/cloud/openstackscripts/tenantnetworkdiscovery.py

File renamed without changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#cloud-config
2+
chpasswd:
3+
list: |
4+
root:ubuntu
5+
ubuntu:ubuntu
6+
expire: False
7+
ssh_pwauth: True

0 commit comments

Comments
 (0)