forked from ungleich/python-oca
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.py
More file actions
105 lines (83 loc) · 2.75 KB
/
Copy pathtemplate.py
File metadata and controls
105 lines (83 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# -*- coding: UTF-8 -*-
from pool import Pool, PoolElement, Template
class VmTemplate(PoolElement):
METHODS = {
'info' : 'template.info',
'allocate' : 'template.allocate',
'delete' : 'template.delete',
'update' : 'template.update',
'publish' : 'template.publish',
'chown' : 'template.chown',
'instantiate' : 'template.instantiate',
}
XML_TYPES = {
'id' : int,
'uid' : int,
'gid' : int,
'name' : str,
'uname' : str,
'gname' : str,
'regtime' : int,
'template' : ['TEMPLATE', Template]
}
ELEMENT_NAME = 'VMTEMPLATE'
@staticmethod
def allocate(client, template):
'''
Allocates a new template in OpenNebula
``client``
oca.Client object
``group``
a string containing the group name
'''
template_id = client.call(VmTemplate.METHODS['allocate'], template)
return template_id
def __init__(self, xml, client):
super(VmTemplate, self).__init__(xml, client)
self.id = self['ID'] if self['ID'] else None
def update(self, template):
'''
Replaces the template contents.
``template``
The new template contents.
'''
self.client.call(VmTemplate.METHODS['update'], self.id, template)
def publish(self):
'''
Publishes a template.
'''
self.client.call(VmTemplate.METHODS['publish'], self.id, True)
def unpublish(self):
'''
Unpublishes a template.
'''
self.client.call(VmTemplate.METHODS['publish'], self.id, False)
def chown(self, uid=-1, gid=-1):
'''
Changes the ownership of a template.
``uid``
The User ID of the new owner. If set to -1, the owner is not changed.
``gid``
The Group ID of the new group. If set to -1, the group is not changed.
'''
self.client.call(VmTemplate.METHODS['chown'], self.id, uid, gid)
def instantiate(self, name=''):
'''
Creates a VM instance from a VmTemplate
``name``
name of the VM instance
'''
self.client.call(VmTemplate.METHODS['instantiate'], self.id, name)
def __repr__(self):
return '<oca.VmTemplate("%s")>' % self.name
class VmTemplatePool(Pool):
METHODS = {
'info' : 'templatepool.info',
}
def __init__(self, client):
super(VmTemplatePool, self).__init__('VMTEMPLATE_POOL', 'POOL', client)
#def info(self,
def _factory(self, xml):
i = VmTemplate(xml, self.client)
i._convert_types()
return i