1
|
|
|
from libcloud.compute.base import NodeAuthPassword |
2
|
|
|
from libcloud.common.dimensiondata import DimensionDataServerCpuSpecification |
3
|
|
|
from lib import actions |
4
|
|
|
|
5
|
|
|
__all__ = [ |
6
|
|
|
'CreateVMMcp1Action', |
7
|
|
|
] |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
class CreateVMMcp1Action(actions.BaseAction): |
11
|
|
|
|
12
|
|
|
def run(self, region, location, network_id, image_name, |
13
|
|
|
name, |
14
|
|
|
description, is_started, password, |
15
|
|
|
memory_gb, cpu_count, cpu_speed, cores_per_socket): |
16
|
|
|
driver = self._get_compute_driver(region) |
17
|
|
|
root_pw = NodeAuthPassword(password) |
18
|
|
|
location = driver.ex_get_location_by_id(location) |
19
|
|
|
|
20
|
|
|
images = driver.list_images(location=location) |
21
|
|
|
|
22
|
|
|
image = list(filter(lambda x: x.name == image_name, |
23
|
|
|
images))[0] |
24
|
|
|
networks = driver.list_networks(location) |
25
|
|
|
network = list(filter(lambda x: x.id == network_id, |
26
|
|
|
networks))[0] |
27
|
|
|
cpu = None |
28
|
|
|
if cpu_count is not None: |
29
|
|
|
cpu = DimensionDataServerCpuSpecification( |
30
|
|
|
cpu_count=cpu_count, |
31
|
|
|
cores_per_socket=cores_per_socket, |
32
|
|
|
performance=cpu_speed |
33
|
|
|
) |
34
|
|
|
|
35
|
|
|
node = driver.create_node(name=name, image=image, |
36
|
|
|
auth=root_pw, |
37
|
|
|
ex_description=description, |
38
|
|
|
ex_network=network, |
39
|
|
|
ex_cpu_specification=cpu, |
40
|
|
|
ex_memory_gb=memory_gb, |
41
|
|
|
ex_is_started=is_started) |
42
|
|
|
return self.resultsets.formatter(node) |
43
|
|
|
|