View | Details | Raw Unified | Return to bug 18613
Collapse All | Expand All

(-)umc/modules/univention/management/console/handlers/uvmm/uvmmd.py (-4 / +4 lines)
Lines 171-177 Link Here
171
		req = protocol.Request_GROUP_LIST()
171
		req = protocol.Request_GROUP_LIST()
172
		if not self.send( req.pack() ):
172
		if not self.send( req.pack() ):
173
			raise ConnectionError()
173
			raise ConnectionError()
174
		
174
175
		groups = self.recv_blocking()
175
		groups = self.recv_blocking()
176
176
177
		tree_data = []
177
		tree_data = []
Lines 215-226 Link Here
215
				group.append( node_info.data )
215
				group.append( node_info.data )
216
216
217
		return group
217
		return group
218
		
218
219
	def get_node_tree( self ):
219
	def get_node_tree( self ):
220
		req = protocol.Request_GROUP_LIST()
220
		req = protocol.Request_GROUP_LIST()
221
		if not self.send( req.pack() ):
221
		if not self.send( req.pack() ):
222
			raise ConnectionError()
222
			raise ConnectionError()
223
		
223
224
		groups = self.recv_blocking()
224
		groups = self.recv_blocking()
225
225
226
		tree_data = []
226
		tree_data = []
Lines 291-297 Link Here
291
		if not self.send( req.pack() ):
291
		if not self.send( req.pack() ):
292
			raise ConnectionError()
292
			raise ConnectionError()
293
		return self.recv_blocking()
293
		return self.recv_blocking()
294
		
294
295
if __name__ == '__main__':
295
if __name__ == '__main__':
296
	notifier.init()
296
	notifier.init()
297
297
(-)umc/modules/univention/management/console/handlers/uvmm/__init__.py (-13 / +30 lines)
Lines 195-200 Link Here
195
		umch.simpleHandler.__init__( self, command_description )
195
		umch.simpleHandler.__init__( self, command_description )
196
		self.uvmm = uvmmd.Client( auto_connect = False )
196
		self.uvmm = uvmmd.Client( auto_connect = False )
197
		self.device_wizard = DeviceWizard( 'uvmm/device/create' )
197
		self.device_wizard = DeviceWizard( 'uvmm/device/create' )
198
		self.domain_wizard = InstanceWizard( 'uvmm/domain/create' )
198
199
199
	@staticmethod
200
	@staticmethod
200
	def _getattr( object, attr, default = '' ):
201
	def _getattr( object, attr, default = '' ):
Lines 639-645 Link Here
639
			self.finished( object.id(), res )
640
			self.finished( object.id(), res )
640
641
641
	def uvmm_domain_state( self, object ):
642
	def uvmm_domain_state( self, object ):
642
		ud.debug( ud.ADMIN, ud.INFO, 'Domain State' )		
643
		ud.debug( ud.ADMIN, ud.INFO, 'Domain State' )
643
		res = umcp.Response( object )
644
		res = umcp.Response( object )
644
645
645
		ud.debug( ud.ADMIN, ud.INFO, 'Domain State: change to %s' % object.options[ 'state' ] )
646
		ud.debug( ud.ADMIN, ud.INFO, 'Domain State: change to %s' % object.options[ 'state' ] )
Lines 653-659 Link Here
653
			self.finished( object.id(), res )
654
			self.finished( object.id(), res )
654
655
655
	def uvmm_domain_create( self, object ):
656
	def uvmm_domain_create( self, object ):
656
		ud.debug( ud.ADMIN, ud.INFO, 'Domain create' )		
657
		ud.debug( ud.ADMIN, ud.INFO, 'Device create' )
657
		( success, res ) = TreeView.safely_get_tree( self.uvmm, object, ( 'group', 'node', 'domain' ) )
658
		( success, res ) = TreeView.safely_get_tree( self.uvmm, object, ( 'group', 'node', 'domain' ) )
658
		if not success:
659
		if not success:
659
			self.finished(object.id(), res)
660
			self.finished(object.id(), res)
Lines 661-674 Link Here
661
662
662
		node_uri = self.uvmm.node_name2uri( object.options[ 'node' ] )
663
		node_uri = self.uvmm.node_name2uri( object.options[ 'node' ] )
663
		node = self.uvmm.get_node_info( node_uri )
664
		node = self.uvmm.get_node_info( node_uri )
664
		content = self._dlg_domain_settings( object, node, None )
665
665
666
		res.dialog[ 0 ].set_dialog( umcd.Section( _( 'Add virtual instance' ), content, hideable = False ) )
666
		self.domain_wizard.action( object, node )
667
		page = self.domain_wizard.setup( object )
668
		res.dialog[ 0 ].set_dialog( page )
667
669
668
		self.finished(object.id(), res)
670
		self.finished(object.id(), res)
671
		# ud.debug( ud.ADMIN, ud.INFO, 'Domain create' )
672
		# ( success, res ) = TreeView.safely_get_tree( self.uvmm, object, ( 'group', 'node', 'domain' ) )
673
		# if not success:
674
		# 	self.finished(object.id(), res)
675
		# 	return
669
676
677
		# node_uri = self.uvmm.node_name2uri( object.options[ 'node' ] )
678
		# node = self.uvmm.get_node_info( node_uri )
679
		# content = self._dlg_domain_settings( object, node, None )
680
681
		# res.dialog[ 0 ].set_dialog( umcd.Section( _( 'Add virtual instance' ), content, hideable = False ) )
682
683
		# self.finished(object.id(), res)
684
670
	def uvmm_domain_remove_images( self, object ):
685
	def uvmm_domain_remove_images( self, object ):
671
		ud.debug( ud.ADMIN, ud.INFO, 'Domain remove images' )		
686
		ud.debug( ud.ADMIN, ud.INFO, 'Domain remove images' )
672
		( success, res ) = TreeView.safely_get_tree( self.uvmm, object, ( 'group', 'node', 'domain' ) )
687
		( success, res ) = TreeView.safely_get_tree( self.uvmm, object, ( 'group', 'node', 'domain' ) )
673
		if not success:
688
		if not success:
674
			self.finished(object.id(), res)
689
			self.finished(object.id(), res)
Lines 694-700 Link Here
694
				lst.add_row( [ umcd.Cell( umcd.Text( '' ), attributes = { 'width' : '10' } ), umcd.Cell( chk_button, attributes = { 'colspan' : '2' } ) ] )
709
				lst.add_row( [ umcd.Cell( umcd.Text( '' ), attributes = { 'width' : '10' } ), umcd.Cell( chk_button, attributes = { 'colspan' : '2' } ) ] )
695
710
696
			opts = copy.copy( object.options )
711
			opts = copy.copy( object.options )
697
			opts[ 'drives' ] = []			
712
			opts[ 'drives' ] = []
698
			back = umcp.SimpleCommand( 'uvmm/domain/overview', options = opts )
713
			back = umcp.SimpleCommand( 'uvmm/domain/overview', options = opts )
699
			req = umcp.SimpleCommand( 'uvmm/domain/remove', options = opts )
714
			req = umcp.SimpleCommand( 'uvmm/domain/remove', options = opts )
700
			fail_overview_cmd = umcp.SimpleCommand( 'uvmm/domain/overview', options = opts )
715
			fail_overview_cmd = umcp.SimpleCommand( 'uvmm/domain/overview', options = opts )
Lines 703-717 Link Here
703
			button = umcd.Button( _( 'Remove' ), actions = [ umcd.Action( req, boxes ), umcd.Action( success_overview_cmd, status_range = umcd.Action.SUCCESS ), umcd.Action( fail_overview_cmd, status_range = umcd.Action.FAILURE ) ] )
718
			button = umcd.Button( _( 'Remove' ), actions = [ umcd.Action( req, boxes ), umcd.Action( success_overview_cmd, status_range = umcd.Action.SUCCESS ), umcd.Action( fail_overview_cmd, status_range = umcd.Action.FAILURE ) ] )
704
			lst.add_row( [ '' ] )
719
			lst.add_row( [ '' ] )
705
			lst.add_row( [ umcd.Cell( cancel, attributes = { 'align' : 'right', 'colspan' : '2' } ), umcd.Cell( button, attributes = { 'align' : 'right' } ) ] )
720
			lst.add_row( [ umcd.Cell( cancel, attributes = { 'align' : 'right', 'colspan' : '2' } ), umcd.Cell( button, attributes = { 'align' : 'right' } ) ] )
706
			
721
707
		res.dialog[ 0 ].set_dialog( umcd.Section( _( 'Remove the virtual instance %(instance)s?' ) % { 'instance' : domain_info.name }, lst, hideable = False ) )
722
		res.dialog[ 0 ].set_dialog( umcd.Section( _( 'Remove the virtual instance %(instance)s?' ) % { 'instance' : domain_info.name }, lst, hideable = False ) )
708
		self.finished(object.id(), res)
723
		self.finished(object.id(), res)
709
		
724
710
	def uvmm_domain_remove( self, object ):
725
	def uvmm_domain_remove( self, object ):
711
		ud.debug( ud.ADMIN, ud.INFO, 'Domain remove' )		
726
		ud.debug( ud.ADMIN, ud.INFO, 'Domain remove' )
712
		res = umcp.Response( object )
727
		res = umcp.Response( object )
713
728
714
		
729
715
		# remove domain
730
		# remove domain
716
		node_uri = self.uvmm.node_name2uri( object.options[ 'node' ] )
731
		node_uri = self.uvmm.node_name2uri( object.options[ 'node' ] )
717
		domain_info = self.uvmm.get_domain_info( node_uri, object.options[ 'domain' ] )
732
		domain_info = self.uvmm.get_domain_info( node_uri, object.options[ 'domain' ] )
Lines 725-738 Link Here
725
			self.finished( object.id(), res, report = _( 'The instance <i>%(domain)s</i> was removed successfully' ) % { 'domain' : object.options[ 'domain' ] } )
740
			self.finished( object.id(), res, report = _( 'The instance <i>%(domain)s</i> was removed successfully' ) % { 'domain' : object.options[ 'domain' ] } )
726
741
727
	def uvmm_device_create( self, object ):
742
	def uvmm_device_create( self, object ):
728
		ud.debug( ud.ADMIN, ud.INFO, 'Device create' )		
743
		ud.debug( ud.ADMIN, ud.INFO, 'Device create' )
729
		( success, res ) = TreeView.safely_get_tree( self.uvmm, object, ( 'group', 'node', 'domain' ) )
744
		( success, res ) = TreeView.safely_get_tree( self.uvmm, object, ( 'group', 'node', 'domain' ) )
730
		if not success:
745
		if not success:
731
			self.finished(object.id(), res)
746
			self.finished(object.id(), res)
732
			return
747
			return
748
		node_uri = self.uvmm.node_name2uri( object.options[ 'node' ] )
749
		node = self.uvmm.get_node_info( node_uri )
733
750
734
		self.device_wizard.action( object )
751
		self.device_wizard.action( object, node )
735
		page = self.device_wizard.setup( object )
752
		page = self.device_wizard.setup( object )
736
		res.dialog[ 0 ].set_dialog( page )
753
		res.dialog[ 0 ].set_dialog( page )
737
		
754
738
		self.finished(object.id(), res)
755
		self.finished(object.id(), res)
(-)umc/modules/univention/management/console/handlers/uvmm/wizards.py (-8 / +103 lines)
Lines 45-56 Link Here
45
		self.title = title
45
		self.title = title
46
		self.description = description
46
		self.description = description
47
		self.options = []
47
		self.options = []
48
		self.actions = []
48
		self.buttons = []
49
		self.buttons = []
49
50
50
	def setup( self, command, options, prev = True, next = True, finish = False ):
51
	def setup( self, command, options, prev = True, next = True, finish = False ):
51
		wizard = umcd.Wizard( self.title )
52
		wizard = umcd.Wizard( self.title )
52
		wizard._content.add_row( [ umcd.Fill( 2, self.description ), ] )
53
		wizard._content.add_row( [ umcd.Fill( 2, str( self.description ) ), ] )
53
		wizard._content.add_row( [ umcd.Fill( 2, umcd.Text( '' ) ), ] )
54
		wizard._content.add_row( [ umcd.Fill( 2, '' ), ] )
54
		items = []
55
		items = []
55
		for option in self.options:
56
		for option in self.options:
56
			if hasattr( option, 'option' ):
57
			if hasattr( option, 'option' ):
Lines 58-64 Link Here
58
				if option.option in options:
59
				if option.option in options:
59
					option.default = options[ option.option ]
60
					option.default = options[ option.option ]
60
			wizard._content.add_row( [ option, ] )
61
			wizard._content.add_row( [ option, ] )
61
		wizard._content.add_row( [ umcd.Fill( 2, umcd.Text( '' ) ), ] )
62
		wizard._content.add_row( [ umcd.Fill( 2, '' ), ] )
63
		if self.actions:
64
			# add already collected options to actions
65
			for button in self.actions:
66
				for action in button.actions:
67
					action.command.options.update( options )
68
			wizard._content.add_row( [ umcd.List( content = [ self.actions, ], attributes = { 'colspan' : '2' } ), ] )
69
			wizard._content.add_row( [ umcd.Fill( 2, '' ), ] )
70
62
		if not self.buttons:
71
		if not self.buttons:
63
			if next:
72
			if next:
64
				opts = copy.copy( options )
73
				opts = copy.copy( options )
Lines 136-147 Link Here
136
145
137
		return self[ self.current ]
146
		return self[ self.current ]
138
147
148
	def reset( self ):
149
		self.current = None
150
139
class DeviceWizard( IWizard ):
151
class DeviceWizard( IWizard ):
140
	def __init__( self, command ):
152
	def __init__( self, command ):
141
		IWizard.__init__( self, command )
153
		IWizard.__init__( self, command )
142
		self.title = _( 'Add a device' )
154
		self.title = _( 'Add a device' )
143
		self.pool_syntax = DynamicSelect( _( 'Storage pool' ) )
155
		self.pool_syntax = DynamicSelect( _( 'Storage pool' ) )
144
		self.pool_syntax.update_choices( [ '/var/lib/libvirt/images', '/var/lib/xen/images' ] )
156
		# self.pool_syntax.update_choices( [ '/var/lib/libvirt/images', '/var/lib/xen/images' ] )
145
		self.image_syntax = DynamicSelect( _( 'Device image' ) )
157
		self.image_syntax = DynamicSelect( _( 'Device image' ) )
146
158
147
		# page 0
159
		# page 0
Lines 171-176 Link Here
171
		page = Page( self.title, _( 'The following device will be create:' ) )
183
		page = Page( self.title, _( 'The following device will be create:' ) )
172
		self.append( page )
184
		self.append( page )
173
185
186
	def action( self, object, node ):
187
		self.node = node
188
		if self.current == None:
189
			# read pool
190
			self.pool_syntax.update_choices( [ storage.name for storage in self.node.storages ] )
191
192
		return IWizard.action( object )
193
174
	def next( self, object ):
194
	def next( self, object ):
175
		if self.current == 0: #which device type?
195
		if self.current == 0: #which device type?
176
			if object.options[ 'device-type' ] == 'disk':
196
			if object.options[ 'device-type' ] == 'disk':
Lines 216-233 Link Here
216
		self.node = None
236
		self.node = None
217
		self.profile_syntax = DynamicSelect( _( 'Profiles' ) )
237
		self.profile_syntax = DynamicSelect( _( 'Profiles' ) )
218
		self.profile_syntax.update_choices( [ item[ 'name' ] for item in self.udm.get_profiles() ] )
238
		self.profile_syntax.update_choices( [ item[ 'name' ] for item in self.udm.get_profiles() ] )
239
		self.arch_syntax = DynamicSelect( _( 'Architecture' ) )
240
		self.virttech_syntax = DynamicSelect( _( 'Virtualisation Technique' ) )
241
		self.device_wizard = DeviceWizard( command )
242
		self.device_wizard_active = False
243
		self.actions[ 'new-device' ] = self.new_device
219
244
220
		# page 0
245
		# page 0
221
		page = Page( self.title, _( 'By selecting a profile for the virtual instance most of the settings will be filled out with default values. In the following steps these values may be modified.' ) )
246
		page = Page( self.title, _( 'By selecting a profile for the virtual instance most of the settings will be filled out with default values. In the following step these values may be modified.' ) )
222
		page.options.append( umcd.make( ( 'instance-profile', self.profile_syntax ) ) )
247
		page.options.append( umcd.make( ( 'instance-profile', self.profile_syntax ) ) )
223
		self.append( page )
248
		self.append( page )
224
249
225
		# page 1
250
		# page 1
226
		page = Page( self.title, _( '' ) )
251
		page = Page( self.title, _( 'The settings shown below are all read from the selected profile. Please verify that these values fits your environment. At least the name for the virtual instance should be modified.' ) )
227
		page.options.append( umcd.make( ( 'instance-name', umc.String( _( 'Name' ) ) ) ) )
252
		page.options.append( umcd.make( ( 'name', umc.String( _( 'Name' ) ) ) ) )
228
		page.options.append( umcd.make( ( 'instance-arch', umc.String( _( 'Name' ) ) ) ) )
253
		page.options.append( umcd.make( ( 'arch', self.arch_syntax ) ) )
254
		page.options.append( umcd.make( ( 'type', self.virttech_syntax ) ) )
255
		page.options.append( umcd.make( ( 'memory', umc.String( _( 'Memory' ) ) ) ) )
256
		page.options.append( umcd.make( ( 'cpus', NumberSelect( _( 'CPUs' ) ) ) ) )
257
		page.options.append( umcd.make( ( 'vnc', umc.Boolean( _( 'VNC' ) ) ) ) )
258
		page.options.append( umcd.make( ( 'kblayout', KBLayoutSelect( _( 'Keyboard layout' ) ) ) ) )
229
		self.append( page )
259
		self.append( page )
230
260
261
		# page 2
262
		page = Page( self.title, _( 'The virtual instance will be created with the following settings. ' ) )
263
		# FIXME: show settings
264
		page.options.append( umcd.HTML( _( '<b>Attached devices</b>' ) ) )
265
		# FIXME: show devices
266
		page.options.append( umcd.Text( _( "You may now add additional devices by clicking the button 'Add device'" ) ) )
267
		add_btn = umcd.Button( _( 'Add device' ), 'uvmm/add', ( umcd.Action( umcp.SimpleCommand( command, options = { 'action' : 'new-device' } ) ), ) )
268
		page.actions.append( add_btn )
269
		self.append( page )
270
231
	def action( self, object, node ):
271
	def action( self, object, node ):
232
		self.node = node
272
		self.node = node
273
		# at startup
274
		if self.current == None:
275
			# read capabilities
276
			types = []
277
			archs = []
278
			for template in node.capabilities:
279
				if not template.virt_tech in types:
280
					types.append( template.virt_tech )
281
				if not template.arch in archs:
282
					archs.append( template.arch )
283
			self.virttech_syntax.update_choices( types )
284
			self.arch_syntax.update_choices( archs )
233
		return IWizard.action( self, object )
285
		return IWizard.action( self, object )
286
287
	def next( self, object ):
288
		if self.device_wizard_active:
289
			return self.device_wizard.next( object )
290
		if self.current == 0:
291
			profile = self.udm.get_profile( object.options[ 'instance-profile' ] )
292
			object.options[ 'name' ] = profile[ 'name_prefix' ]
293
			object.options[ 'arch' ] = profile[ 'virttech' ]
294
			object.options[ 'memory' ] = profile[ 'ram' ]
295
			object.options[ 'cpus' ] = profile[ 'cpus' ]
296
			object.options[ 'vnc' ] = profile[ 'vnc' ]
297
			object.options[ 'kblayout' ] = profile[ 'kblayout' ]
298
299
		return IWizard.next( self, object )
300
301
	def prev( self, object ):
302
		if self.device_wizard_active:
303
			return self.device_wizard.prev( object )
304
305
		return IWizard.prev( self, object )
306
307
	def finish( self, object ):
308
		if self.device_wizard_active:
309
			self.device_wizard_active = False
310
			# FIXME: read result, temporarily store the device in UVMM data structure
311
			self.device_wizard.reset()
312
			return self[ self.current ]
313
		else:
314
			pass # FIXME: create instance
315
316
	def new_device( self, object ):
317
		# all next, prev and finished events must be redirected to the device wizard
318
		self.device_wizard_active = True
319
		return self.device_wizard.next( object )
320
321
	def setup( self, object ):
322
		if self.device_wizard_active:
323
			return self.device_wizard.setup( object )
324
		return IWizard.setup( self, object )
325
326
	def reset( self ):
327
		# FIXME: reset list of devices
328
		IWizard.reset( self )
(-)umc/modules/univention/management/console/handlers/uvmm/udm.py (+9 lines)
Lines 62-67 Link Here
62
62
63
		return res
63
		return res
64
64
65
	def get_profile( self, name ):
66
		try:
67
			res = univention.admin.modules.lookup( uvmm_profile, self.co, self.lo, filter = 'cn=%s' % name, scope='one', base = self.base, required = False, unique = True )
68
		except univention.admin.uexceptions.base, e:
69
			ud.debug( ud.ADMIN, ud.ERROR, 'UVMM/UDM: get_profiles: error while searching for template: %s' % str( e ) )
70
			return {}
71
72
		return res[ 0 ]
73
65
if __name__ == '__main__':
74
if __name__ == '__main__':
66
	udm = Client()
75
	udm = Client()
67
	print udm.get_profiles()
76
	print udm.get_profiles()

Return to bug 18613