3 # Copyright 2016 RIFT.IO Inc
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 import libcloud
.compute
.providers
19 import libcloud
.compute
.types
21 from gi
.repository
import RwcalYang
27 class Vsphere(core
.Cloud
):
28 """This class implements the abstract methods in the Cloud class.
29 This is the Vsphere CAL driver."""
32 super(Vsphere
, self
).__init
__()
33 self
._driver
_class
= libcloud
.compute
.providers
.get_driver(
34 libcloud
.compute
.providers
.Provider
.VSPHERE
)
36 def driver(self
, account
):
37 return self
._driver
_class
(
38 username
=account
.username
,
39 passwork
=account
.password
,
43 def get_image_list(self
, account
):
45 Return a list of the names of all available images.
47 images
= self
.driver(account
).list_images()
48 return [image
.name
for image
in images
]
50 def create_vm(self
, account
, vminfo
):
52 Create a new virtual machine.
54 @param account - account information used authenticate the create of
56 @param vmfinfo - information about the virtual machine to create
59 node
= self
.driver(account
).ex_create_node_from_template(
61 template
=vminfo
.vsphere
.template
,
64 vminfo
.vm_id
= node
.id
68 def delete_vm(self
, account
, vm_id
):
70 delete a virtual machine.
72 @param vm_id - Instance id of VM to be deleted.
76 self
.driver(account
).destroy_node(node
)
78 def reboot_vm(self
, account
, vm_id
):
80 Reboot a virtual machine.
82 @param vm_id - Instance id of VM to be deleted.
86 self
.driver(account
).reboot_node(node
)