Skip to content

Commit 874c96c

Browse files
mguezuragasysradium
authored andcommitted
Allow template instantiation with extra template attributes (python-oca#37)
1 parent 8f84999 commit 874c96c

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

oca/template.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,18 @@ def chown(self, uid=-1, gid=-1):
7979
'''
8080
self.client.call(VmTemplate.METHODS['chown'], self.id, uid, gid)
8181

82-
def instantiate(self, name=''):
82+
def instantiate(self, name='', pending=False, extra_template=''):
8383
'''
8484
Creates a VM instance from a VmTemplate
8585
8686
``name``
8787
name of the VM instance
88+
``pending``
89+
False to create the VM on pending (default), True to create it on hold.
90+
``extra_template``
91+
A string containing an extra template to be merged with the one being instantiated
8892
'''
89-
self.client.call(VmTemplate.METHODS['instantiate'], self.id, name)
93+
self.client.call(VmTemplate.METHODS['instantiate'], self.id, name, pending, extra_template)
9094

9195
def __repr__(self):
9296
return '<oca.VmTemplate("%s")>' % self.name

oca/tests/test_template.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,28 @@ def test_instantiate_with_default_name(self):
5656
template = oca.VmTemplate(self.xml, self.client)
5757
template.instantiate()
5858
self.client.call.assert_called_once_with('template.instantiate',
59-
'1', '')
59+
'1', '', False, '')
6060

6161
def test_instantiate_with_custom_name(self):
6262
self.client.call = Mock()
6363
template = oca.VmTemplate(self.xml, self.client)
6464
template.instantiate('asd')
6565
self.client.call.assert_called_once_with('template.instantiate',
66-
'1', 'asd')
66+
'1', 'asd', False, '')
67+
68+
def test_instantiate_with_default_name_and_context(self):
69+
self.client.call = Mock()
70+
template = oca.VmTemplate(self.xml, self.client)
71+
template.instantiate('', False, 'VCPU=4')
72+
self.client.call.assert_called_once_with('template.instantiate',
73+
'1', '', False, 'VCPU=4')
74+
75+
def test_instantiate_with_custom_name_and_context(self):
76+
self.client.call = Mock()
77+
template = oca.VmTemplate(self.xml, self.client)
78+
template.instantiate('asd', False, 'VCPU=4')
79+
self.client.call.assert_called_once_with('template.instantiate',
80+
'1', 'asd', False, 'VCPU=4')
6781

6882
def test_repr(self):
6983
self.client.call = Mock()

0 commit comments

Comments
 (0)