예제 #1
0
파일: vm.py 프로젝트: mattmb/spoke
def store_delete(vm_name):
    from spoke.lib.vm_storage import SpokeVMStorageXen
    vms = SpokeVMStorageXen(hv_uri)
    try:
        result = vms.delete(vm_name)
    except error.SpokeError as e:
        result = common.handle_error(e)
    return result
예제 #2
0
파일: test_vm.py 프로젝트: KrisSaxton/spoke
 def test_create_vm(self):
     """Create a virtual machine object; return True."""
     vm = SpokeVMStorageXen(self.hv_uri)
     self.assertTrue(vm.create(self.vm_name, self.vm_uuid, self.vm_mem, 
                              self.vm_cpu, self.vm_family,
                              self.vm_storage_layout, self.vm_network_layout, 
                              self.vm_install, self.vm_disks,
                              self.vm_interfaces))
     vm.conn.close()
예제 #3
0
파일: vm.py 프로젝트: KrisSaxton/spoke
def store_delete(vm_name):
    try:
        conf = _spoke_config(_salt_config('config'))
        hv_uri = conf.get('VM', 'hv_uri')
        vms = SpokeVMStorageXen(hv_uri)
        result = vms.delete(vm_name)
    except error.SpokeError as e:
        result = common.handle_error(e)
    return result
예제 #4
0
파일: test_vm.py 프로젝트: KrisSaxton/spoke
 def test_create_vm(self):
     """Create a virtual machine object; return True."""
     vm = SpokeVMStorageXen(self.hv_uri)
     self.assertTrue(
         vm.create(self.vm_name, self.vm_uuid, self.vm_mem, self.vm_cpu,
                   self.vm_family, self.vm_storage_layout,
                   self.vm_network_layout, self.vm_install, self.vm_disks,
                   self.vm_interfaces))
     vm.conn.close()
예제 #5
0
파일: vm.py 프로젝트: KrisSaxton/spoke
def store_create(vm_family, vm_name, vm_uuid, vm_mem, vm_cpu,
                 vm_storage_layout, vm_network_layout, vm_install=False):
    try:
        conf = _spoke_config(_salt_config('config'))
        hv_uri = conf.get('VM', 'hv_uri')
        vms = SpokeVMStorageXen(hv_uri)
        result = vms.create(vm_name, vm_uuid, vm_mem, vm_cpu, vm_family,
                            vm_storage_layout, vm_network_layout, vm_install)
    except error.SpokeError as e:
        result = common.handle_error(e)
    return result
예제 #6
0
파일: test_vm.py 프로젝트: KrisSaxton/spoke
 def test_get_vm(self):
     """Retrieve a virtual machine; return a vm object."""
     vm = SpokeVMStorageXen(self.hv_uri)
     vm_name = 'test'
     data = vm.get(vm_name)['data']
     # UUID is different each time so we need to strip it out
     ruuid = re.compile(r'<uuid.*?uuid>\n  ')
     result = ruuid.sub('', data[0])
     result = [result]
     expected_result = ["<domain type='test'>\n  <name>test</name>\n  <memory unit='KiB'>8388608</memory>\n  <currentMemory unit='KiB'>2097152</currentMemory>\n  <vcpu>2</vcpu>\n  <os>\n    <type arch='i686'>hvm</type>\n    <boot dev='hd'/>\n  </os>\n  <clock offset='utc'/>\n  <on_poweroff>destroy</on_poweroff>\n  <on_reboot>restart</on_reboot>\n  <on_crash>destroy</on_crash>\n  <devices>\n  </devices>\n</domain>\n"]
     self.assertEquals(result, expected_result)
예제 #7
0
파일: vm.py 프로젝트: mattmb/spoke
def store_create(vm_family, vm_name, vm_uuid, vm_mem, vm_cpu,
                vm_storage_layout, vm_network_layout,
                vm_install=False):
    from spoke.lib.vm_storage import SpokeVMStorageXen
    vms = SpokeVMStorageXen(hv_uri)
    try:
        result = vms.create(vm_name, vm_uuid, vm_mem, vm_cpu, vm_family,
                vm_storage_layout, vm_network_layout,
                vm_install)
    except error.SpokeError as e:
        result = common.handle_error(e)
    return result
예제 #8
0
파일: test_vm.py 프로젝트: KrisSaxton/spoke
 def test_create_vm_twice(self):
     """Create virtual machine twice; raise AlreadExists."""
     vm = SpokeVMStorageXen(self.hv_uri)
     vm.create(self.vm_name, self.vm_uuid, self.vm_mem, self.vm_cpu,
               self.vm_family, self.vm_storage_layout,
               self.vm_network_layout, self.vm_install, self.vm_disks,
               self.vm_interfaces)
     self.assertRaises(error.AlreadyExists, vm.create, self.vm_name,
                       self.vm_uuid, self.vm_mem, self.vm_cpu,
                       self.vm_family, self.vm_storage_layout,
                       self.vm_network_layout, self.vm_install,
                       self.vm_disks, self.vm_interfaces)
     vm.conn.close()
예제 #9
0
파일: test_vm.py 프로젝트: KrisSaxton/spoke
 def test_get_vm(self):
     """Retrieve a virtual machine; return a vm object."""
     vm = SpokeVMStorageXen(self.hv_uri)
     vm_name = 'test'
     data = vm.get(vm_name)['data']
     # UUID is different each time so we need to strip it out
     ruuid = re.compile(r'<uuid.*?uuid>\n  ')
     result = ruuid.sub('', data[0])
     result = [result]
     expected_result = [
         "<domain type='test'>\n  <name>test</name>\n  <memory unit='KiB'>8388608</memory>\n  <currentMemory unit='KiB'>2097152</currentMemory>\n  <vcpu>2</vcpu>\n  <os>\n    <type arch='i686'>hvm</type>\n    <boot dev='hd'/>\n  </os>\n  <clock offset='utc'/>\n  <on_poweroff>destroy</on_poweroff>\n  <on_reboot>restart</on_reboot>\n  <on_crash>destroy</on_crash>\n  <devices>\n  </devices>\n</domain>\n"
     ]
     self.assertEquals(result, expected_result)
예제 #10
0
파일: test_vm.py 프로젝트: KrisSaxton/spoke
 def test_create_vm_twice(self):
     """Create virtual machine twice; raise AlreadExists."""
     vm = SpokeVMStorageXen(self.hv_uri)
     vm.create(self.vm_name, self.vm_uuid, self.vm_mem, 
                              self.vm_cpu, self.vm_family,
                              self.vm_storage_layout, self.vm_network_layout, 
                              self.vm_install, self.vm_disks,
                              self.vm_interfaces)
     self.assertRaises(error.AlreadyExists, vm.create, self.vm_name, 
                              self.vm_uuid, self.vm_mem, 
                              self.vm_cpu, self.vm_family,
                              self.vm_storage_layout, self.vm_network_layout, 
                              self.vm_install, self.vm_disks,
                              self.vm_interfaces)
     vm.conn.close()
예제 #11
0
파일: test_vm.py 프로젝트: KrisSaxton/spoke
 def test_get_all_vms(self):
     """Retrieve a virtual machine; return a vm object."""
     vm = SpokeVMStorageXen(self.hv_uri)
     vm_name = 'test2ndvm'
     vm.create(vm_name, self.vm_uuid, self.vm_mem, 
                              self.vm_cpu, self.vm_family,
                              self.vm_storage_layout, self.vm_network_layout, 
                              self.vm_install, self.vm_disks,
                              self.vm_interfaces)
     data = vm.get()['data']
     # UUID is different each time so we need to strip it out
     ruuid = re.compile(r'<uuid.*?uuid>\n  ')
     out = ruuid.sub('', data[0])
     result = [out, data[1]]
     expected_result = ["<domain type='test'>\n  <name>test</name>\n  <memory unit='KiB'>8388608</memory>\n  <currentMemory unit='KiB'>2097152</currentMemory>\n  <vcpu>2</vcpu>\n  <os>\n    <type arch='i686'>hvm</type>\n    <boot dev='hd'/>\n  </os>\n  <clock offset='utc'/>\n  <on_poweroff>destroy</on_poweroff>\n  <on_reboot>restart</on_reboot>\n  <on_crash>destroy</on_crash>\n  <devices>\n  </devices>\n</domain>\n", "<domain type='test'>\n  <name>test2ndvm</name>\n  <uuid>00000000-0000-0000-0000-000000000001</uuid>\n  <memory unit='KiB'>262144</memory>\n  <currentMemory unit='KiB'>262144</currentMemory>\n  <vcpu>1</vcpu>\n  <bootloader>/usr/sbin/pypxeboot</bootloader>\n  <bootloader_args>--udhcpc=/usr/local/pkg/udhcp/sbin/udhcpc --interface=eth3 mac=02:00:00:01:00:00 --label=install-aethernet</bootloader_args>\n  <os>\n    <type arch='i686'>hvm</type>\n  </os>\n  <clock offset='utc'/>\n  <on_poweroff>destroy</on_poweroff>\n  <on_reboot>restart</on_reboot>\n  <on_crash>restart</on_crash>\n  <devices>\n    <emulator>/usr/lib/xen/bin/qemu-dm</emulator>\n    <disk type='block' device='disk'>\n      <driver name='phy'/>\n      <source dev='/dev/vg01/test2ndvm'/>\n      <target dev='hda' bus='ide'/>\n      <address type='drive' controller='0' bus='0' target='0' unit='0'/>\n    </disk>\n    <disk type='block' device='disk'>\n      <driver name='phy'/>\n      <source dev='/dev/vg02/test2ndvm'/>\n      <target dev='hdb' bus='ide'/>\n      <address type='drive' controller='0' bus='0' target='0' unit='1'/>\n    </disk>\n    <controller type='ide' index='0'/>\n    <interface type='bridge'>\n      <mac address='02:00:00:01:00:00'/>\n      <source bridge='eth3'/>\n      <script path='vif-bridge'/>\n      <target dev='vif-1.0'/>\n    </interface>\n    <interface type='bridge'>\n      <mac address='02:00:00:01:01:00'/>\n      <source bridge='eth0'/>\n      <script path='vif-bridge'/>\n      <target dev='vif-1.1'/>\n    </interface>\n    <console type='pty'>\n      <target type='xen' port='0'/>\n    </console>\n    <input type='mouse' bus='ps2'/>\n    <graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'>\n      <listen type='address' address='0.0.0.0'/>\n    </graphics>\n    <video>\n      <model type='cirrus' vram='9216' heads='1'/>\n    </video>\n  </devices>\n</domain>\n"]
     self.assertEquals(result, expected_result)
예제 #12
0
파일: test_vm.py 프로젝트: KrisSaxton/spoke
 def test_get_all_vms(self):
     """Retrieve a virtual machine; return a vm object."""
     vm = SpokeVMStorageXen(self.hv_uri)
     vm_name = 'test2ndvm'
     vm.create(vm_name, self.vm_uuid, self.vm_mem, self.vm_cpu,
               self.vm_family, self.vm_storage_layout,
               self.vm_network_layout, self.vm_install, self.vm_disks,
               self.vm_interfaces)
     data = vm.get()['data']
     # UUID is different each time so we need to strip it out
     ruuid = re.compile(r'<uuid.*?uuid>\n  ')
     out = ruuid.sub('', data[0])
     result = [out, data[1]]
     expected_result = [
         "<domain type='test'>\n  <name>test</name>\n  <memory unit='KiB'>8388608</memory>\n  <currentMemory unit='KiB'>2097152</currentMemory>\n  <vcpu>2</vcpu>\n  <os>\n    <type arch='i686'>hvm</type>\n    <boot dev='hd'/>\n  </os>\n  <clock offset='utc'/>\n  <on_poweroff>destroy</on_poweroff>\n  <on_reboot>restart</on_reboot>\n  <on_crash>destroy</on_crash>\n  <devices>\n  </devices>\n</domain>\n",
         "<domain type='test'>\n  <name>test2ndvm</name>\n  <uuid>00000000-0000-0000-0000-000000000001</uuid>\n  <memory unit='KiB'>262144</memory>\n  <currentMemory unit='KiB'>262144</currentMemory>\n  <vcpu>1</vcpu>\n  <bootloader>/usr/sbin/pypxeboot</bootloader>\n  <bootloader_args>--udhcpc=/usr/local/pkg/udhcp/sbin/udhcpc --interface=eth3 mac=02:00:00:01:00:00 --label=install-aethernet</bootloader_args>\n  <os>\n    <type arch='i686'>hvm</type>\n  </os>\n  <clock offset='utc'/>\n  <on_poweroff>destroy</on_poweroff>\n  <on_reboot>restart</on_reboot>\n  <on_crash>restart</on_crash>\n  <devices>\n    <emulator>/usr/lib/xen/bin/qemu-dm</emulator>\n    <disk type='block' device='disk'>\n      <driver name='phy'/>\n      <source dev='/dev/vg01/test2ndvm'/>\n      <target dev='hda' bus='ide'/>\n      <address type='drive' controller='0' bus='0' target='0' unit='0'/>\n    </disk>\n    <disk type='block' device='disk'>\n      <driver name='phy'/>\n      <source dev='/dev/vg02/test2ndvm'/>\n      <target dev='hdb' bus='ide'/>\n      <address type='drive' controller='0' bus='0' target='0' unit='1'/>\n    </disk>\n    <controller type='ide' index='0'/>\n    <interface type='bridge'>\n      <mac address='02:00:00:01:00:00'/>\n      <source bridge='eth3'/>\n      <script path='vif-bridge'/>\n      <target dev='vif-1.0'/>\n    </interface>\n    <interface type='bridge'>\n      <mac address='02:00:00:01:01:00'/>\n      <source bridge='eth0'/>\n      <script path='vif-bridge'/>\n      <target dev='vif-1.1'/>\n    </interface>\n    <console type='pty'>\n      <target type='xen' port='0'/>\n    </console>\n    <input type='mouse' bus='ps2'/>\n    <graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'>\n      <listen type='address' address='0.0.0.0'/>\n    </graphics>\n    <video>\n      <model type='cirrus' vram='9216' heads='1'/>\n    </video>\n  </devices>\n</domain>\n"
     ]
     self.assertEquals(result, expected_result)
예제 #13
0
파일: test_vm.py 프로젝트: KrisSaxton/spoke
 def test_create_vm_with_invalid_vm_family(self):
     """Create a vm object with an invalid family; raise InputError."""
     vm_family = 'c*@t'
     vm = SpokeVMStorageXen(self.hv_uri)
     self.assertRaises(error.InputError, vm.create, self.vm_name,
                       self.vm_uuid, self.vm_mem, self.vm_cpu, vm_family,
                       self.vm_storage_layout, self.vm_network_layout,
                       self.vm_install, self.vm_disks, self.vm_interfaces)
     vm.conn.close()
예제 #14
0
파일: test_vm.py 프로젝트: KrisSaxton/spoke
 def test_create_vm_with_invalid_vm_name(self):
     """Create a virtual machine object; return True."""
     vm_name = 'c*@t'
     vm = SpokeVMStorageXen(self.hv_uri)
     self.assertRaises(error.InputError, vm.create, vm_name, self.vm_uuid,
                       self.vm_mem, self.vm_cpu, self.vm_family,
                       self.vm_storage_layout, self.vm_network_layout,
                       self.vm_install, self.vm_disks, self.vm_interfaces)
     vm.conn.close()
예제 #15
0
파일: test_vm.py 프로젝트: KrisSaxton/spoke
 def test_input_invalid_vm(self):
     """Retrieve an invalid vm; raise InputError."""
     vm_name = 'c*@t'
     vm = SpokeVMStorageXen(self.hv_uri)
     self.assertRaises(error.InputError, vm.get, vm_name)
예제 #16
0
파일: test_vm.py 프로젝트: KrisSaxton/spoke
 def test_delete_running_vm(self):
     """Fail to delete a virtual machine object; raise SearchError."""
     vm_name = 'test'
     vm = SpokeVMStorageXen(self.hv_uri)
     self.assertRaises(error.SearchError, vm.delete, vm_name)
예제 #17
0
파일: test_vm.py 프로젝트: KrisSaxton/spoke
 def test_delete_missing_vm(self):
     """Delete a running virtual machine object; raise NotFound."""
     vm_name = 'missingvmtest'
     vm = SpokeVMStorageXen(self.hv_uri)
     self.assertRaises(error.NotFound, vm.delete, vm_name)
예제 #18
0
파일: mc_vm.py 프로젝트: mattmb/spoke
# TODO This only works for Xen until we can hide VM Storage types in the vm_storage module
# TODO Implement access to vm power via vm host modify (e.g. vm.modify(vm_name, power=on).
from spoke.lib.vm_storage import SpokeVMStorageXen

config_file = '/usr/local/pkg/spoke/etc/spoke.conf'
config = config.setup(config_file)
    
if __name__ == '__main__':
    log = logger.setup('main', verbose=False, quiet=True)
    mc = mc.MCollectiveAction()
    request = mc.request()
    try:
        hv_uri = config.get('VM', 'hv_uri')
        mc.info('Connecting to hypervisor URI %s' % hv_uri)
        vm = SpokeVMStorageXen(hv_uri)
    except error.SpokeError, e:
        mc.fail(e.msg, e.exit_code)
            
    if request['action'] == 'create':
        vm_name             = request['data']['hostname']
        vm_uuid             = request['data']['uuid']
        vm_mem              = request['data']['mem']
        vm_cpu              = request['data']['cpu']
        vm_family           = request['data']['family']
        vm_storage_layout   = request['data']['storage_layout']
        vm_network_layout   = request['data']['network_layout']
        try:
            vm_install = request['data']['install']
        except KeyError:
            vm_install = None
예제 #19
0
 def test_delete_running_vm(self):
     """Delete a running virtual machine object; raise VMRunning."""
     vm_name = 'test'
     vm = SpokeVMStorageXen(self.hv_uri)
     self.assertRaises(error.VMRunning, vm.delete, vm_name)