Patched virsh serverprovider, devstack deploy engine to use ServerDTO

server provider now returns a DTO object

Change-Id: I08b9f4c634ce77700f9f23387de55a1c83cd8a47
This commit is contained in:
Alexei Kornienko 2013-09-09 12:02:26 +03:00
parent 158327368b
commit 11a55dbeb0
3 changed files with 17 additions and 15 deletions

View File

@ -5,9 +5,9 @@
"name": "VirshProvider",
"connection": "alex@performance-01",
"template_name": "stack-01-devstack-template"
"template_user": "alex",
},
"vm_count": 1,
"template_user": "alex",
"services": {
"admin_password": "71789845d5ceb06f9609",
"nova": {

View File

@ -28,7 +28,6 @@ class DevstackDeployment(engine.EngineFactory):
'''Deploys Devstack cloud.
deploy config example:
"deploy": {
"template_user": "ubuntu", # vm user to launch devstack
"vm_provider": {
"name": "%name%",
...
@ -52,7 +51,7 @@ class DevstackDeployment(engine.EngineFactory):
self.start_devstack(vm)
self._vms.append(vm)
identity_host = {'host': self._vms[0]['ip']}
identity_host = {'host': self._vms[0].ip}
return {
'identity': {
@ -82,8 +81,8 @@ class DevstackDeployment(engine.EngineFactory):
cmd = 'scp %(opts)s %(config)s %(usr)s@%(host)s:~/devstack/localrc' % {
'opts': '-o StrictHostKeyChecking=no',
'config': config_path,
'usr': self._config['template_user'],
'host': vm['ip']
'usr': vm.user,
'host': vm.ip
}
subprocess.check_call(cmd, shell=True)
@ -93,8 +92,8 @@ class DevstackDeployment(engine.EngineFactory):
def start_devstack(self, vm):
cmd = 'ssh %(opts)s %(usr)s@%(host)s devstack/stack.sh' % {
'opts': '-o StrictHostKeyChecking=no',
'usr': self._config['template_user'],
'host': vm['ip']
'usr': vm.user,
'host': vm.ip
}
subprocess.check_call(cmd, shell=True)
return True

View File

@ -31,6 +31,7 @@ class VirshProvider(provider.ProviderFactory):
"name": "VirshProvider",
"connection": "alex@performance-01", # ssh connection to vms host
"template_name": "stack-01-devstack-template", # vm image template
"template_user": "ubuntu", # vm user to launch devstack
},
'''
@ -59,11 +60,13 @@ class VirshProvider(provider.ProviderFactory):
cmd = 'virsh --connect=%s start %s' % (virt_url, vm_name)
subprocess.check_call(cmd, shell=True)
return {
'id': id,
'name': vm_name,
'ip': self._determine_vm_ip(vm_name),
}
return provider.ServerDTO(
vm_name,
self._determine_vm_ip(vm_name),
self._config['template_user'],
None,
self._config.get('template_password')
)
def destroy_vms(self, vm_uuids):
'''Destroy already created vms by vm_uuids.'''
@ -72,14 +75,14 @@ class VirshProvider(provider.ProviderFactory):
def destroy_vm(self, vm):
'''Destroy single vm and delete all allocated resources.'''
print('Destroy VM %s' % vm['name'])
print('Destroy VM %s' % vm.uuid)
vconnection = self._get_virt_connection_url(self._config['connection'])
cmd = 'virsh --connect=%s destroy %s' % (vconnection, vm['name'])
cmd = 'virsh --connect=%s destroy %s' % (vconnection, vm.uuid)
subprocess.check_call(cmd, shell=True)
cmd = 'virsh --connect=%s undefine %s --remove-all-storage' % (
vconnection, vm['name'])
vconnection, vm.uuid)
subprocess.check_call(cmd, shell=True)
return True