def perform_volume_list(self, tenant_id, instance_id):
     self.client, self.env = get_client_env()
     self.vg_clientMock = self.client['Virtual_Guest']
     self.vdi_clientMock = self.client['Virtual_Disk_Image']
     self.req = api.Request(self.env, sl_client=self.client)
     self.resp = falcon.Response()
     instance = volumes.OSVolumeAttachmentsV2()
     instance.on_get(self.req, self.resp, tenant_id, instance_id)
Example #2
0
 def perform_attach_action(self, body_str, tenant_id, instance_id):
     self.client, self.env = get_client_env(body=body_str)
     self.vg_clientMock = self.client['Virtual_Guest']
     self.vdi_clientMock = self.client['Virtual_Disk_Image']
     self.req = falcon.Request(self.env)
     self.resp = falcon.Response()
     instance = volumes.OSVolumeAttachmentsV2()
     instance.on_post(self.req, self.resp, tenant_id, instance_id)
 def test_on_get_fail_block_devices_exception(self):
     client, env = get_client_env()
     vg_clientMock = client['Virtual_Guest']
     gbdMock = vg_clientMock.getBlockDevices
     gbdMock.side_effect = SoftLayer.SoftLayerAPIError(
         404, 'No Block Devices', None)
     req = api.Request(env, sl_client=client)
     resp = falcon.Response()
     instance = volumes.OSVolumeAttachmentsV2()
     instance.on_get(req, resp, TENANT_ID, INSTANCE_ID)
     self.assertEqual(
         resp.body,
         {'volumeFault': {
             'message': 'No Block Devices',
             'code': '500'
         }})
Example #4
0
 def test_on_post_fail_vdi_client_exception(self):
     body_str = ('{"volumeAttachment": '
                 '{"device": null, "volumeId": "3887490"}}')
     client, env = get_client_env(body=body_str)
     vg_clientMock = client['Virtual_Guest']
     vdi_clientMock = client['Virtual_Disk_Image']
     vdi_clientMock.getObject.side_effect = Exception('No Object!')
     req = falcon.Request(env)
     resp = falcon.Response()
     instance = volumes.OSVolumeAttachmentsV2()
     instance.on_post(req, resp, TENANT_ID, INSTANCE_ID)
     self.assertEquals(
         resp.body,
         {'volumeFault': {
             'message': 'No Object!',
             'code': '400'
         }})
Example #5
0
 def test_on_post_fail_vdi_client_exception(self):
     body_str = ('{"volumeAttachment": '
                 '{"device": null, "volumeId": "3887490"}}')
     client, env = get_client_env(body=body_str)
     vg_clientMock = client['Virtual_Guest']
     vdi_clientMock = client['Virtual_Disk_Image']
     vg_clientMock.checkHostDiskAvailability.return_value = False
     req = falcon.Request(env)
     resp = falcon.Response()
     instance = volumes.OSVolumeAttachmentsV2()
     instance.on_post(req, resp, TENANT_ID, INSTANCE_ID)
     self.assertEquals(
         resp.body, {
             'volumeFault': {
                 'message': 'Action causes migration to a new '
                 'host. Migration is not allowed.',
                 'code': '400'
             }
         })
 def test_on_get(self):
     self.client, self.env = get_client_env()
     self.vg_clientMock = self.client['Virtual_Guest']
     self.vg_clientMock.getBlockDevices.return_value = [{
         'diskImage': {
             'type': {
                 'keyName': 'not SWAP'
             },
             'id': '0123456'
         }
     }]
     self.vdi_clientMock = self.client['Virtual_Disk_Image']
     self.req = api.Request(self.env, sl_client=self.client)
     self.resp = falcon.Response()
     instance = volumes.OSVolumeAttachmentsV2()
     instance.on_get(self.req, self.resp, TENANT_ID, INSTANCE_ID)
     self.assertEqual(list(self.resp.body.keys()), ['volumeAttachments'])
     self.assertIn('device', self.resp.body['volumeAttachments'][0])
     self.assertIn('id', self.resp.body['volumeAttachments'][0])
     self.assertIn('serverId', self.resp.body['volumeAttachments'][0])
     self.assertIn('volumeId', self.resp.body['volumeAttachments'][0])
Example #7
0
 def test_on_post_fail_disk_already_attach_this_guest(self):
     body_str = ('{"volumeAttachment": '
                 '{"device": null, "volumeId": "3887490"}}')
     client, env = get_client_env(body=body_str)
     vg_clientMock = client['Virtual_Guest']
     vdi_clientMock = client['Virtual_Disk_Image']
     vdi_clientMock.getObject.return_value = {
         'blockDevices': [{
             'guestId': INSTANCE_ID
         }]
     }
     req = falcon.Request(env)
     resp = falcon.Response()
     instance = volumes.OSVolumeAttachmentsV2()
     instance.on_post(req, resp, TENANT_ID, INSTANCE_ID)
     self.assertEquals(
         resp.body, {
             'volumeFault': {
                 'message': 'The requested disk image is already'
                 ' attached to this guest.',
                 'code': '400'
             }
         })
Example #8
0
def setup_routes(app, disp):
    # V3 Routes
    # None currently supported

    # V2 Routes
    disp.set_handler('index', index.IndexV2(app))
    disp.set_handler('v2_index', index.IndexV2(app))

    flavors_from_config = flavor_list_loader.Flavors.get_flavors(app)
    flavor = flavors.FlavorV2(app, flavors_from_config)
    flavor_list = flavors.FlavorsV2(app, flavors_from_config)
    flavors_detail = flavors.FlavorsDetailV2(app, flavors_from_config)

    disp.set_handler('v2_availability_zone',
                     availability_zones.AvailabilityZonesV2())
    disp.set_handler('v2_availability_zone_detail',
                     availability_zones.AvailabilityZonesV2())

    disp.set_handler('v2_extensions', extensions.ExtensionsV2())
    disp.set_handler('v2_extension', extensions.ExtensionV2())

    disp.set_handler('v2_os_extra_specs_flavor',
                     extra_specs.ExtraSpecsFlavorV2(app, flavors_from_config))
    disp.set_handler('v2_os_extra_specs_flavor_key',
                     extra_specs.ExtraSpecsFlavorKeyV2(app,
                                                       flavors_from_config))

    disp.set_handler('v2_flavor', flavor)
    disp.set_handler('v2_flavors', flavor_list)
    disp.set_handler('v2_flavors_detail', flavors_detail)

    disp.set_handler('v2_os_floating_ip_dns', dns.DNSDomainsV2())
    disp.set_handler('v2_os_floating_ip_dns_domain_entry',
                     dns.DNSDomainEntryV2())

    disp.set_handler('v2_limits', limits.LimitsV2())

    disp.set_handler('v2_os_floating_ips', floating_ips.OSFloatingIpsV2())

    disp.set_handler('v2_os_tenant_networks', networks.OSNetworksV2())
    disp.set_handler('v2_os_tenant_network', networks.OSNetworkV2())
    disp.set_handler('v2_os_networks', networks.OSNetworksV2())
    disp.set_handler('v2_os_network', networks.OSNetworkV2())

    disp.set_handler('v2_os_keypair', keypairs.KeypairV2())
    disp.set_handler('v2_os_keypairs', keypairs.KeypairsV2())

    disp.set_handler('v2_os_quota_sets', quota_sets.OSQuotaSetsV2())
    disp.set_handler('v2_os_tenant_quota_sets', quota_sets.OSQuotaSetsV2())

    disp.set_handler('v2_os_server_security_groups',
                     security_groups.OSSecurityGroupsV2())
    disp.set_handler('v2_os_security_groups',
                     security_groups.OSSecurityGroupsV2())

    disp.set_handler('v2_os_volume_attachments',
                     volumes.OSVolumeAttachmentsV2())
    disp.set_handler('v2_os_volume_attachments_detail',
                     volumes.OSVolumeAttachmentV2())

    disp.set_handler('v2_server', servers.ServerV2(app))
    disp.set_handler('v2_servers',
                     servers.ServersV2(app, flavors_from_config))
    disp.set_handler('v2_servers_detail', servers.ServersDetailV2(app))
    disp.set_handler('v2_server_action',
                     servers.ServerActionV2(app, flavors_from_config))
    disp.set_handler('v2_os_instance_actions',
                     instance_actions.InstanceActionsV2())
    disp.set_handler('v2_os_instance_action',
                     instance_actions.InstanceActionV2())

    disp.set_handler('v2_server_ips', server_ips.ServerIpsV2())
    disp.set_handler('v2_server_ips_network', server_ips.ServerIpsNetworkV2())

    disp.set_handler('v2_tenant_flavor', flavor)
    disp.set_handler('v2_tenant_flavors', flavor_list)
    disp.set_handler('v2_tenant_flavors_detail', flavors_detail)

    disp.set_handler('v2_tenant_usage', usage.UsageV2())

    disp.set_handler('v2_image', images.ImageV1(app))
    disp.set_handler('v2_images', images.ImagesV2(app))
    disp.set_handler('v2_images_detail', images.ImagesV2(app))

    sl_common.add_hooks(app)
Example #9
0
def setup_routes(app, disp):
    # V2 Routes
    disp.set_handler('index', index.IndexV2(app))
    # need separate handler cause the second version takes a tenant ID
    # and using the same handler does not work where there is a difference
    # in parameters; so the tenant ID optional
    disp.set_handler('v2_detail', versionv2.VersionV2(app))
    disp.set_handler('v2_detail_tenant', versionv2.VersionV2(app))

    flavors_from_config = flavor_list_loader.Flavors.get_flavors(app)
    flavor = flavors.FlavorV2(app, flavors_from_config)
    flavor_list = flavors.FlavorsV2(app, flavors_from_config)
    flavors_detail = flavors.FlavorsDetailV2(app, flavors_from_config)

    disp.set_handler('v2_availability_zone',
                     availability_zones.AvailabilityZonesV2())
    disp.set_handler('v2_availability_zone_detail',
                     availability_zones.AvailabilityZonesV2())

    disp.set_handler('v2_extensions', extensions.ExtensionsV2())
    disp.set_handler('v2_extension', extensions.ExtensionV2())

    disp.set_handler('v2_os_extra_specs_flavor',
                     extra_specs.ExtraSpecsFlavorV2(app, flavors_from_config))
    disp.set_handler('v2_os_extra_specs_flavor_key',
                     extra_specs.ExtraSpecsFlavorKeyV2(app,
                                                       flavors_from_config))

    disp.set_handler('v2_flavor', flavor)
    disp.set_handler('v2_flavors', flavor_list)
    disp.set_handler('v2_flavors_detail', flavors_detail)

    disp.set_handler('v2_limits', limits.LimitsV2())

    disp.set_handler('v2_os_floating_ips', floating_ips.OSFloatingIpsV2())

    disp.set_handler('v2_os_tenant_networks', networks.OSNetworksV2())
    disp.set_handler('v2_os_tenant_network', networks.OSNetworkV2())
    disp.set_handler('v2_os_networks', networks.OSNetworksV2())
    disp.set_handler('v2_os_network', networks.OSNetworkV2())

    disp.set_handler('v2_os_keypair', keypairs.KeypairV2())
    disp.set_handler('v2_os_keypairs', keypairs.KeypairsV2())

    disp.set_handler('v2_os_quota_sets', quota_sets.OSQuotaSetsV2())
    disp.set_handler('v2_os_tenant_quota_sets', quota_sets.OSQuotaSetsV2())

    disp.set_handler('v2_os_server_security_groups',
                     security_groups.OSSecurityGroupsV2())
    disp.set_handler('v2_os_security_groups',
                     security_groups.OSSecurityGroupsV2())

    disp.set_handler('v2_os_volume_attachments',
                     volumes.OSVolumeAttachmentsV2())
    disp.set_handler('v2_os_volume_attachments_detail',
                     volumes.OSVolumeAttachmentV2())

    disp.set_handler('v2_server', servers.ServerV2(app))
    disp.set_handler('v2_servers',
                     servers.ServersV2(app, flavors_from_config))
    disp.set_handler('v2_servers_detail', servers.ServersDetailV2(app))
    disp.set_handler('v2_server_action',
                     servers.ServerActionV2(app, flavors_from_config))
    disp.set_handler('v2_os_instance_actions',
                     instance_actions.InstanceActionsV2())
    disp.set_handler('v2_os_instance_action',
                     instance_actions.InstanceActionV2())

    disp.set_handler('v2_server_ips', server_ips.ServerIpsV2())
    disp.set_handler('v2_server_ips_network', server_ips.ServerIpsNetworkV2())

    disp.set_handler('v2_tenant_flavor', flavor)
    disp.set_handler('v2_tenant_flavors', flavor_list)
    disp.set_handler('v2_tenant_flavors_detail', flavors_detail)

    disp.set_handler('v2_tenant_usage', usage.UsageV2())

    disp.set_handler('compute_image_show',
                     compute_images.ComputeImageShow(app))
    disp.set_handler('v2_images', glance_images.ImagesV2(app))
    disp.set_handler('v2_images_detail', glance_images.ImagesV2(
        app, detail=True))

    sl_common.add_hooks(app)
Example #10
0
 def perform_attach_action(self, body_str, tenant_id, instance_id):
     self.client, self.env = get_client_env(body=body_str)
     self.req = api.Request(self.env, sl_client=self.client)
     self.resp = falcon.Response()
     instance = volumes.OSVolumeAttachmentsV2()
     instance.on_post(self.req, self.resp, tenant_id, instance_id)