blob: 02526f228288778393c311a6d91bf32a3abbc825 [file] [log] [blame]
Matteo Scandolo48d3d2d2017-08-08 13:05:27 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
Chetan Gaonker0cdccd82017-03-18 02:27:43 +000017from credentials import get_nova_credentials
18from novaclient.client import Client
19
20class novautils(object):
21
22 def __init__(self, net_id, server_id):
23 self.net_id = net_id#'ae0618cf-fa34-4e8b-816d-c1356c409119'
24 self.server_id = server_id#'99889c8d-113f-4a7e-970c-77f1916bfe14'
25
26 def get_nova_intance(self):
27 creds = get_nova_credentials()
28 nvclient= Client(**creds)
29 return nvclient
30
31 def create_instance_v2(self, vm_name):
32 nvclient = self.get_nova_intance()
33 image = nvclient.images.find(name="vsg-1.1")
34 flavor = nvclient.flavors.find(name="m1.tiny")
35 nic = [{'net-id': self.net_id}]
36 instance = nvclient.servers.create(name=self.vm_name, image=image,
37 flavor=flavor,
38 nics=nic)
39 time.sleep(5)
40 return instance
41
42 def get_flavors_list(self):
43 nvclient = self.get_nova_intance()
44 flavors_list = nvclient.flavors.list()
45 return flavors_list
46
47 def get_flavor_details(self):
48 nvclient = self.get_nova_intance()
49 flavors_list = nvclient.flavors.list()
50 for fl in flavors_list:
51 return fl.name, fl.ram, fl.vcpus, fl.disk, fl.id
52
53 def get_servers_list(self):
54 nvclient = self.get_nova_intance()
55 servers = nvclient.servers.list()
56 return servers
57
58 def get_server_details(self):
59 nvclient = self.get_nova_intance()
60 servers = nvclient.servers.get(self.server_id)
61 for s in servers:
62 return s.id, s.name, s.image, s.flavor, s.user_id
63
64 def get_floating_ip_pools(self):
65 nvclient = self.get_nova_intance()
66 ip_list = nvclient.floating_ip_pools.list()
67 return ip_list
68
69 def get_host_list(self):
70 nvclient = self.get_nova_intance()
71 host_list = nvclient.hosts.list()
72 return host_list
73
74 def get_hypervisor_list(self):
75 nvclient = self.get_nova_intance()
76 hyper_list = nvclient.hypervisors.list()
77 return hyper_list
78
79 def get_images_list(self):
80 nvclient = self.get_nova_intance()
81 img_list = nvclient.images.list(detailed=True)
82 return img_list
83
84 def get_aggregates_list(self):
85 nvclient = self.get_nova_intance()
86 return nvclient.aggregates.list()
87
88
89