update from RIFT as of 696b75d2fe9fb046261b08c616f1bcf6c0b54a9b second try
[osm/SO.git] / rwcal / rift / cal / client.py
1 """
2 #
3 # Copyright 2016 RIFT.IO Inc
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17
18 @file client.py
19 @author Varun Prasad(varun.prasad@riftio.com)
20 @date 2016-06-14
21 """
22
23 import os
24
25 import gi
26 gi.require_version('RwcalYang', '1.0')
27 gi.require_version('RwCal', '1.0')
28 gi.require_version('RwLog', '1.0')
29
30 from gi.repository import RwcalYang
31
32 import rift.cal.utils as cal_utils
33
34
35 class CloudsimClient(cal_utils.CloudSimCalMixin):
36 """Cloudsim client that handles interactions with the server.
37 """
38 def __init__(self, log):
39 super().__init__()
40 self.log = log
41
42 @property
43 def images(self):
44 _, images = self.cal.get_image_list(self.account)
45 return images.imageinfo_list or []
46
47 @property
48 def vlinks(self):
49 _, vlinks = self.cal.get_virtual_link_list(self.account)
50 return vlinks.virtual_link_info_list or []
51
52 @property
53 def vdus(self):
54 _, vdus = self.cal.get_vdu_list(self.account)
55 return vdus.vdu_info_list or []
56
57 def upload_image(self, location, name=None):
58 """Onboard image to cloudsim server."""
59
60 image = RwcalYang.YangData_RwProject_Project_VimResources_ImageinfoList()
61 image.name = name or os.path.basename(location)
62 image.location = location
63 image.disk_format = "qcow2"
64 rc, image.id = self.cal.create_image(self.account, image)
65
66 self.log.info("Image created: {}".format(image.as_dict()))
67
68 return image