Juan Hernandez has uploaded a new change for review.
Change subject: restapi: OpenStack image provider
......................................................................
restapi: OpenStack image provider
This patch adds the resources for the OpenStack image providers. The
representation of the resource will look like this:
GET /openstackimageproviders
<openstack_image_providers>
<openstack_image_provider id="{provider:id}">...</openstack_image_provider>
...
</openstack_image_providers>
GET /openstackimageproviders/{provider:id}
<openstack_image_provider id="{provider:id}">
<name>myprovider</name>
<description>My provider</description>
<url>http://glance.example.com</url>
<requires_authentication>true</requires_authentication>
<username>myuser</username>
<password>mypass</password>
<tenant_name>mytenant</tenant_name>
<properties>
<property>
<name>prop1</name>
<value>value1</myvalue>
</property>
<property>
<name>prop2</name>
<value>value2</myvalue>
</property>
</properties>
</openstack_image_provider>
The providers collection will support listing, getting, adding, and
removing providers, with the usual methods.
The provider resource will support getting, deleting and updating the
provider, with the usual methods. In addition it will support the
"testconnectivity" and "importcertificates" operations. The first is
used to check the connectivity with the external provider:
POST /openstackimageproviders/{provider:id}/testconnectivity
<action/>
The second is used to import the chain of certificates of the external
provider:
POST /openstackimageproviders/{provider:id}/importcertificates
<action/>
The third is used to import the image:
POST /openstackimageproviders/{provider:id}/importcertificates
<action/>
The provider resource includes subcollections for certificates and
images. For certificates it will look like this:
GET /openstackimageproviders/{provider:id}/certificates
<certificates>
<certificate id="{host:id}">...</certificate>
...
</fcertificates>
GET /openstackimageproviders/{provider:id}/certificates/{certificate:id}
<certificate id="{certificate:id}">
<subject>CN=glance.example.com</subject>
<content>...</content>
</certificate>
For images:
GET /openstackimageproviders/{provider:id}/images
<openstack_images>
<openstack_image id="{image:id}">...</openstack_image>
...
</openstack_images>
GET /openstackimageproviders/{provider:id}/images/{image:id}
<openstack_image id="{image:id}">
<name>myimage</name>
</openstack_image>
The image resource supports the "import" operation:
POST /openstackimageproviders/{provider:id}/images/{image:id}/import
<action>
<storagedomain>
<name>mysd</name>
</storagedomain>
<cluster>
<name>mycluster</name>
</cluster>
<import_as_template>false</import_as_template>
</action>
Change-Id: I77fca2208b18d54f9177ec8b0178768a6b815f20
Related-To: https://bugzilla.redhat.com/1132259
Signed-off-by: Juan Hernandez <[email protected]>
---
A
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackImageProviderResource.java
A
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackImageProvidersResource.java
A
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackImageResource.java
A
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackImagesResource.java
M
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/ApiRootLinksCreator.java
M
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java
M
backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
M
backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
M
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/BackendApplication.java
M
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendResource.java
A
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImageProviderHelper.java
A
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImageProviderResource.java
A
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImageProvidersResource.java
A
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImageResource.java
A
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImagesResource.java
M
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/utils/FeaturesHelper.java
M
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java
A
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImageProviderResourceTest.java
A
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImageProvidersResourceTest.java
A
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImageResourceTest.java
A
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImagesResourceTest.java
A
backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/openstack/OpenStackImageMapper.java
A
backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/openstack/OpenStackImageProviderMapper.java
A
backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/openstack/OpenStackImageMapperTest.java
A
backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/openstack/OpenStackImageProviderMapperTest.java
25 files changed, 1,508 insertions(+), 2 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/75/33975/1
diff --git
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackImageProviderResource.java
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackImageProviderResource.java
new file mode 100644
index 0000000..87c3232
--- /dev/null
+++
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackImageProviderResource.java
@@ -0,0 +1,30 @@
+/*
+* Copyright (c) 2014 Red Hat, Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.ovirt.engine.api.resource.openstack;
+
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+import org.ovirt.engine.api.model.OpenStackImageProvider;
+import org.ovirt.engine.api.resource.ApiMediaType;
+import org.ovirt.engine.api.resource.ExternalProviderResource;
+
+@Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON,
ApiMediaType.APPLICATION_X_YAML})
+public interface OpenStackImageProviderResource extends
ExternalProviderResource<OpenStackImageProvider> {
+ @Path("images")
+ public OpenStackImagesResource getOpenStackImages();
+}
diff --git
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackImageProvidersResource.java
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackImageProvidersResource.java
new file mode 100644
index 0000000..e81cb4e
--- /dev/null
+++
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackImageProvidersResource.java
@@ -0,0 +1,48 @@
+/*
+* Copyright (c) 2014 Red Hat, Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.ovirt.engine.api.resource.openstack;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+
+import org.ovirt.engine.api.model.OpenStackImageProvider;
+import org.ovirt.engine.api.model.OpenStackImageProviders;
+import org.ovirt.engine.api.resource.ApiMediaType;
+
+@Path("/openstackimageproviders")
+@Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON,
ApiMediaType.APPLICATION_X_YAML})
+public interface OpenStackImageProvidersResource {
+ @GET
+ public OpenStackImageProviders list();
+
+ @POST
+ @Consumes({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON,
ApiMediaType.APPLICATION_X_YAML})
+ public Response add(OpenStackImageProvider provider);
+
+ @DELETE
+ @Path("{id}")
+ public Response remove(@PathParam("id") String id);
+
+ @Path("{id}")
+ public OpenStackImageProviderResource
getOpenStackImageProvider(@PathParam("id") String id);
+}
diff --git
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackImageResource.java
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackImageResource.java
new file mode 100644
index 0000000..d2c6401
--- /dev/null
+++
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackImageResource.java
@@ -0,0 +1,39 @@
+/*
+* Copyright (c) 2014 Red Hat, Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.ovirt.engine.api.resource.openstack;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+
+import org.ovirt.engine.api.model.Action;
+import org.ovirt.engine.api.model.Actionable;
+import org.ovirt.engine.api.model.OpenStackImage;
+import org.ovirt.engine.api.resource.ApiMediaType;
+
+@Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON,
ApiMediaType.APPLICATION_X_YAML})
+public interface OpenStackImageResource {
+ @GET
+ public OpenStackImage get();
+
+ @POST
+ @Actionable
+ @Path("import")
+ public Response doImport(Action action);
+}
diff --git
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackImagesResource.java
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackImagesResource.java
new file mode 100644
index 0000000..1e93a32
--- /dev/null
+++
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackImagesResource.java
@@ -0,0 +1,35 @@
+/*
+* Copyright (c) 2014 Red Hat, Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.ovirt.engine.api.resource.openstack;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+
+import org.ovirt.engine.api.model.OpenStackImages;
+import org.ovirt.engine.api.resource.ApiMediaType;
+
+@Path("images")
+@Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON,
ApiMediaType.APPLICATION_X_YAML})
+public interface OpenStackImagesResource {
+ @GET
+ public OpenStackImages list();
+
+ @Path("{id}")
+ OpenStackImageResource getOpenStackImage(@PathParam("id") String id);
+}
diff --git
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/ApiRootLinksCreator.java
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/ApiRootLinksCreator.java
index 7561ff7..094cc36 100644
---
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/ApiRootLinksCreator.java
+++
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/ApiRootLinksCreator.java
@@ -59,6 +59,7 @@
links.add(createLink("permissions", baseUri));
links.add(createLink("macpools", baseUri));
links.add(createLink("foremanhostproviders", baseUri));
+ links.add(createLink("openstackimageproviders", baseUri));
return links;
}
diff --git
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java
index 9dc50b0..d8b0835 100644
---
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java
+++
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java
@@ -70,6 +70,8 @@
import org.ovirt.engine.api.model.NIC;
import org.ovirt.engine.api.model.Network;
import org.ovirt.engine.api.model.NumaNode;
+import org.ovirt.engine.api.model.OpenStackImage;
+import org.ovirt.engine.api.model.OpenStackImageProvider;
import org.ovirt.engine.api.model.Parameter;
import org.ovirt.engine.api.model.ParametersSet;
import org.ovirt.engine.api.model.Permission;
@@ -238,6 +240,10 @@
import org.ovirt.engine.api.resource.gluster.GlusterHooksResource;
import org.ovirt.engine.api.resource.gluster.GlusterVolumeResource;
import org.ovirt.engine.api.resource.gluster.GlusterVolumesResource;
+import org.ovirt.engine.api.resource.openstack.OpenStackImageProviderResource;
+import org.ovirt.engine.api.resource.openstack.OpenStackImageProvidersResource;
+import org.ovirt.engine.api.resource.openstack.OpenStackImageResource;
+import org.ovirt.engine.api.resource.openstack.OpenStackImagesResource;
/**
* Contains a static addLinks() method which constructs any href attributes
@@ -506,6 +512,14 @@
map = new ParentToCollectionMap(ForemanComputeResourceResource.class,
ForemanComputeResourcesResource.class);
map.add(ForemanComputeResourceResource.class,
ForemanComputeResourcesResource.class, ForemanHostProvider.class);
TYPES.put(ForemanComputeResource.class, map);
+
+ // OpenStack image providers:
+ map = new ParentToCollectionMap(OpenStackImageProviderResource.class,
OpenStackImageProvidersResource.class);
+ TYPES.put(OpenStackImageProvider.class, map);
+
+ map = new ParentToCollectionMap(OpenStackImageResource.class,
OpenStackImagesResource.class);
+ map.add(OpenStackImageResource.class, OpenStackImagesResource.class,
OpenStackImageProvider.class);
+ TYPES.put(OpenStackImage.class, map);
}
/**
diff --git
a/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
b/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
index bb57f1c..0138d8e 100644
---
a/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
+++
b/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
@@ -5074,4 +5074,61 @@
</xs:complexContent>
</xs:complexType>
+ <!-- OpenStack image providers: -->
+ <xs:element name="openstack_image_provider" type="OpenStackImageProvider"/>
+
+ <xs:complexType name="OpenStackImageProvider">
+ <xs:complexContent>
+ <xs:extension base="OpenStackProvider"/>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:element name="openstack_image_providers" type="OpenStackImageProviders"/>
+
+ <xs:complexType name="OpenStackImageProviders">
+ <xs:complexContent>
+ <xs:extension base="BaseResources">
+ <xs:sequence>
+ <xs:element ref="openstack_image_provider" minOccurs="0"
maxOccurs="unbounded">
+ <xs:annotation>
+ <xs:appinfo>
+ <jaxb:property name="OpenStackImageProviders"/>
+ </xs:appinfo>
+ </xs:annotation>
+ </xs:element>
+ </xs:sequence>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:element name="openstack_image" type="OpenStackImage"/>
+
+ <xs:element name="openstack_images" type="OpenStackImages"/>
+
+ <xs:complexType name="OpenStackImage">
+ <xs:complexContent>
+ <xs:extension base="BaseResource">
+ <xs:sequence>
+ <xs:element ref="openstack_image_provider" minOccurs="0"
maxOccurs="1"/>
+ </xs:sequence>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name="OpenStackImages">
+ <xs:complexContent>
+ <xs:extension base="BaseResources">
+ <xs:sequence>
+ <xs:element ref="openstack_image" minOccurs="0"
maxOccurs="unbounded">
+ <xs:annotation>
+ <xs:appinfo>
+ <jaxb:property name="OpenStackImages"/>
+ </xs:appinfo>
+ </xs:annotation>
+ </xs:element>
+ </xs:sequence>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
</xs:schema>
diff --git
a/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
b/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
index 6fe4829..303b934 100644
---
a/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
+++
b/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
@@ -6297,3 +6297,149 @@
urlparams: {}
headers: {}
+- name: /openstackimageproviders|rel=get
+ description: get the list of all OpenStack image providers in the system
+ request:
+ body:
+ parameterType: null
+ signatures: []
+ urlparams:
+ max: {context: matrix, type: 'xs:int', value: 'max results', required:
false}
+ headers: {}
+- name: /openstackimageproviders/{openstackimageprovider:id}|rel=get
+ description: get the details of the specified OpenStack image provider in
the system
+ request:
+ body:
+ parameterType: null
+ signatures: []
+ urlparams: {}
+ headers: {}
+- name: /openstackimageproviders/{openstackimageprovider:id}|rel=delete
+ description: delete the specified OpenStack image provider in the system
+ request:
+ body:
+ parameterType: null
+ signatures: []
+ urlparams:
+ async: {context: matrix, type: 'xs:boolean', value: true|false,
required: false}
+ headers:
+ Correlation-Id: {value: 'any string', required: false}
+- name: /openstackimageproviders/{openstackimageprovider:id}|rel=update
+ description: update the specified OpenStack image provider in the system
+ request:
+ body:
+ parameterType: OpenStackImageProvider
+ signatures:
+ - mandatoryArguments: {}
+ optionalArguments:
+ openstack_image_provider.name: xs:string
+ openstack_image_provider.description: xs:string
+ openstack_image_provider.requires_authentication: xs:boolean
+ openstack_image_provider.username: xs:string
+ openstack_image_provider.password: xs:string
+ openstack_image_provider.properties.property--COLLECTION:
+ property.name: xs:string
+ property.value: xs:string
+ description: update the specified OpenStack image provider in the
system
+ urlparams: {}
+ headers:
+ Content-Type: {value: application/xml|json, required: true}
+ Correlation-Id: {value: 'any string', required: false}
+- name: /openstackimageproviders|rel=add
+ description: add a new OpenStack image provider to the system
+ request:
+ body:
+ parameterType: OpenStackImageProvider
+ signatures:
+ - mandatoryArguments:
+ openstack_image_provider.name: xs:string
+ optionalArguments:
+ openstack_image_provider.description: xs:string
+ openstack_image_provider.url: xs:string
+ openstack_image_provider.requires_authentication: xs:boolean
+ openstack_image_provider.username: xs:string
+ openstack_image_provider.password: xs:string
+ openstack_image_provider.properties.property--COLLECTION:
+ property.name: xs:string
+ property.value: xs:string
+ description: add a new OpenStack image provider to the system
+ urlparams: {}
+ headers:
+ Content-Type: {value: application/xml|json, required: true}
+ Expect: {value: 201-created, required: false}
+ Correlation-Id: {value: 'any string', required: false}
+- name: /openstackimageproviders/{openstackimageprovider:id}/images|rel=get
+ description: get the list of images from the OpenStack image provider
+ request:
+ body:
+ parameterType: null
+ signatures: []
+ urlparams:
+ max: {context: matrix, type: 'xs:int', value: 'max results', required:
false}
+ headers: {}
+- name:
/openstackimageproviders/{openstackimageprovider:id}/images/{image:id}|rel=get
+ description: get the details of the specified image from the OpenStack image
provider
+ request:
+ body:
+ parameterType: null
+ signatures: []
+ urlparams: {}
+ headers: {}
+- name:
/openstackimageproviders/{openstackimageprovider:id}/certificates|rel=get
+ description: get the list of certificates of the OpenStack image provider
+ request:
+ body:
+ parameterType: null
+ signatures: []
+ urlparams:
+ max: {context: matrix, type: 'xs:int', value: 'max results', required:
false}
+ headers: {}
+- name:
/openstackimageproviders/{openstackimageprovider:id}/certificates/{certificate:id}|rel=get
+ description: get the details of the specified certificate of the OpenStack
image provider
+ request:
+ body:
+ parameterType: null
+ signatures: []
+ urlparams: {}
+ headers: {}
+- name:
/openstackimageproviders/{openstackimageprovider:id}/testconnectivity|rel=testconnectivity
+ description: test the connectivity to the external OpenStack imageprovider
+ request:
+ body:
+ parameterType: Action
+ signatures:
+ - mandatoryArguments: {}
+ optionalArguments: {}
+ urlparams: {}
+ headers:
+ Content-Type: {value: application/xml|json, required: true}
+ Correlation-Id: {value: 'any string', required: false}
+- name:
/openstackimageproviders/{openstackimageprovider:id}/importcertificates|rel=importcertificates
+ description: import the SSL certificates of the OpenStack image provider
+ request:
+ body:
+ parameterType: Action
+ signatures:
+ - mandatoryArguments: {}
+ optionalArguments: {}
+ urlparams: {}
+ headers:
+ Content-Type: {value: application/xml|json, required: true}
+ Correlation-Id: {value: 'any string', required: false}
+- name:
/openstackimageproviders/{openstackimageprovider:id}/images/{images:id}/import|rel=import
+ description: imports the OpenStack image
+ request:
+ body:
+ parameterType: Action
+ signatures:
+ - mandatoryArguments:
+ action.storagedomain.id|name: xs:string
+ optionalArguments:
+ action.async: xs:boolean
+ action.grace_period.expiry: xs:long
+ action.import_as_template: xs:boolean
+ action.cluster.id|name: xs:string
+ urlparams: {}
+ headers:
+ Content-Type: {value: application/xml|json, required: true}
+ Correlation-Id: {value: 'any string', required: false}
diff --git
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/BackendApplication.java
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/BackendApplication.java
index 905a2d1..f172742 100644
---
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/BackendApplication.java
+++
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/BackendApplication.java
@@ -58,6 +58,7 @@
import org.ovirt.engine.api.restapi.resource.aaa.BackendGroupsResource;
import org.ovirt.engine.api.restapi.resource.aaa.BackendUsersResource;
import
org.ovirt.engine.api.restapi.resource.foreman.BackendForemanHostProvidersResource;
+import
org.ovirt.engine.api.restapi.resource.openstack.BackendOpenStackImageProvidersResource;
import org.ovirt.engine.api.restapi.resource.validation.IOExceptionMapper;
import org.ovirt.engine.api.restapi.resource.validation.JsonExceptionMapper;
import
org.ovirt.engine.api.restapi.resource.validation.MalformedIdExceptionMapper;
@@ -147,6 +148,7 @@
addResource(new BackendDiskProfilesResource());
addResource(new BackendCpuProfilesResource());
addResource(new BackendForemanHostProvidersResource());
+ addResource(new BackendOpenStackImageProvidersResource());
final SessionProcessor processor = new SessionProcessor();
processor.setBackend(backend);
diff --git
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendResource.java
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendResource.java
index a2c1c88..6f69433 100644
---
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendResource.java
+++
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendResource.java
@@ -85,8 +85,7 @@
}
}
-
- protected VdcQueryReturnValue runQuery(VdcQueryType queryType,
VdcQueryParametersBase queryParams) {
+ public VdcQueryReturnValue runQuery(VdcQueryType queryType,
VdcQueryParametersBase queryParams) {
queryParams.setFiltered(isFiltered());
return backend.runQuery(queryType, sessionize(queryParams));
}
diff --git
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImageProviderHelper.java
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImageProviderHelper.java
new file mode 100644
index 0000000..ee7c5a1
--- /dev/null
+++
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImageProviderHelper.java
@@ -0,0 +1,54 @@
+/*
+* Copyright (c) 2014 Red Hat, Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.ovirt.engine.api.restapi.resource.openstack;
+
+import java.util.List;
+
+import org.ovirt.engine.api.restapi.resource.BackendResource;
+import org.ovirt.engine.core.common.businessentities.StorageDomain;
+import org.ovirt.engine.core.common.queries.VdcQueryParametersBase;
+import org.ovirt.engine.core.common.queries.VdcQueryType;
+import org.ovirt.engine.core.compat.Guid;
+
+/**
+ * A set of utility functions for dealing with OpenStack image providers.
+ */
+public class BackendOpenStackImageProviderHelper {
+ /**
+ * Finds the identifier of the storage domain corresponding to the given
provider.
+ *
+ * @param resource the resource that will be used to perform the operation
+ * @param providerId identifier of the provider
+ * @return the identifier of the corresponding storage domain or {@code
null} if no such storage domain exists
+ */
+ public static Guid getStorageDomainId(BackendResource resource, String
providerId) {
+ // The backend doesn't have any mechanism to obtain the images other
than listing the images provided by the
+ // storage domain that is created for the provider, and the only way
to find that provider is to iterate the
+ // complete list. This is potentially very slow, so it should be
improved in the future.
+ Guid storageDomainId = null;
+ List<StorageDomain> storageDomains =
+ resource.runQuery(VdcQueryType.GetAllStorageDomains, new
VdcQueryParametersBase()).getReturnValue();
+ for (StorageDomain storageDomain : storageDomains) {
+ String storageId = storageDomain.getStorage();
+ if (providerId.equals(storageId)) {
+ storageDomainId = storageDomain.getId();
+ break;
+ }
+ }
+ return storageDomainId;
+ }
+}
diff --git
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImageProviderResource.java
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImageProviderResource.java
new file mode 100644
index 0000000..da19572
--- /dev/null
+++
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImageProviderResource.java
@@ -0,0 +1,97 @@
+/*
+* Copyright (c) 2014 Red Hat, Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.ovirt.engine.api.restapi.resource.openstack;
+
+import static
org.ovirt.engine.api.restapi.resource.openstack.BackendOpenStackImageProvidersResource.SUB_COLLECTIONS;
+
+import javax.ws.rs.core.Response;
+
+import org.ovirt.engine.api.model.Action;
+import org.ovirt.engine.api.model.OpenStackImageProvider;
+import org.ovirt.engine.api.resource.ExternalProviderCertificatesResource;
+import org.ovirt.engine.api.resource.openstack.OpenStackImageProviderResource;
+import org.ovirt.engine.api.resource.openstack.OpenStackImagesResource;
+import org.ovirt.engine.api.restapi.resource.AbstractBackendActionableResource;
+import
org.ovirt.engine.api.restapi.resource.BackendExternalProviderCertificatesResource;
+import org.ovirt.engine.api.restapi.resource.BackendExternalProviderHelper;
+import org.ovirt.engine.core.common.action.ProviderParameters;
+import org.ovirt.engine.core.common.action.VdcActionParametersBase;
+import org.ovirt.engine.core.common.action.VdcActionType;
+import org.ovirt.engine.core.common.businessentities.Provider;
+import org.ovirt.engine.core.common.queries.IdQueryParameters;
+import org.ovirt.engine.core.common.queries.VdcQueryType;
+import org.ovirt.engine.core.compat.Guid;
+
+public class BackendOpenStackImageProviderResource
+ extends AbstractBackendActionableResource<OpenStackImageProvider,
Provider>
+ implements OpenStackImageProviderResource {
+
+ public BackendOpenStackImageProviderResource(String id) {
+ super(id, OpenStackImageProvider.class, Provider.class,
SUB_COLLECTIONS);
+ }
+
+ @Override
+ public OpenStackImageProvider get() {
+ return performGet(VdcQueryType.GetProviderById, new
IdQueryParameters(guid));
+ }
+
+ @Override
+ public OpenStackImageProvider update(OpenStackImageProvider incoming) {
+ return performUpdate(
+ incoming,
+ new QueryIdResolver<Guid>(VdcQueryType.GetProviderById,
IdQueryParameters.class),
+ VdcActionType.UpdateProvider,
+ new UpdateParametersProvider()
+ );
+ }
+
+ protected class UpdateParametersProvider implements
ParametersProvider<OpenStackImageProvider, Provider> {
+ @Override
+ public VdcActionParametersBase getParameters(OpenStackImageProvider
incoming, Provider entity) {
+ return new ProviderParameters(map(incoming, entity));
+ }
+ }
+
+ @Override
+ protected OpenStackImageProvider doPopulate(OpenStackImageProvider model,
Provider entity) {
+ return model;
+ }
+
+ @Override
+ public Response testConnectivity(Action action) {
+ Provider provider = BackendExternalProviderHelper.getProvider(this,
id);
+ ProviderParameters parameters = new ProviderParameters(provider);
+ return performAction(VdcActionType.TestProviderConnectivity,
parameters);
+ }
+
+ @Override
+ public Response importCertificates(Action action) {
+ Provider provider = BackendExternalProviderHelper.getProvider(this,
id);
+ ProviderParameters parameters = new ProviderParameters(provider);
+ return performAction(VdcActionType.ImportProviderCertificateChain,
parameters);
+ }
+
+ @Override
+ public OpenStackImagesResource getOpenStackImages() {
+ return inject(new BackendOpenStackImagesResource(id));
+ }
+
+ @Override
+ public ExternalProviderCertificatesResource getCertificates() {
+ return inject(new BackendExternalProviderCertificatesResource(id));
+ }
+}
diff --git
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImageProvidersResource.java
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImageProvidersResource.java
new file mode 100644
index 0000000..3e75a5f
--- /dev/null
+++
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImageProvidersResource.java
@@ -0,0 +1,122 @@
+/*
+* Copyright (c) 2014 Red Hat, Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.ovirt.engine.api.restapi.resource.openstack;
+
+import javax.ws.rs.PathParam;
+import javax.ws.rs.core.Response;
+import java.util.List;
+
+import org.apache.commons.lang.StringUtils;
+import org.ovirt.engine.api.common.util.QueryHelper;
+import org.ovirt.engine.api.model.OpenStackImageProvider;
+import org.ovirt.engine.api.model.OpenStackImageProviders;
+import org.ovirt.engine.api.resource.openstack.OpenStackImageProviderResource;
+import org.ovirt.engine.api.resource.openstack.OpenStackImageProvidersResource;
+import org.ovirt.engine.api.restapi.resource.AbstractBackendCollectionResource;
+import org.ovirt.engine.api.restapi.resource.SingleEntityResource;
+import org.ovirt.engine.api.restapi.resource.BackendExternalProviderHelper;
+import org.ovirt.engine.core.common.action.ProviderParameters;
+import org.ovirt.engine.core.common.action.VdcActionType;
+import org.ovirt.engine.core.common.businessentities.Provider;
+import org.ovirt.engine.core.common.businessentities.ProviderType;
+import org.ovirt.engine.core.common.interfaces.SearchType;
+import org.ovirt.engine.core.common.queries.GetAllProvidersParameters;
+import org.ovirt.engine.core.common.queries.IdQueryParameters;
+import org.ovirt.engine.core.common.queries.VdcQueryType;
+import org.ovirt.engine.core.compat.Guid;
+
+public class BackendOpenStackImageProvidersResource
+ extends AbstractBackendCollectionResource<OpenStackImageProvider,
Provider>
+ implements OpenStackImageProvidersResource {
+ /**
+ * The names of the sub-collections supported by this resource.
+ */
+ public static String[] SUB_COLLECTIONS = {
+ "images",
+ "certificates"
+ };
+
+ public BackendOpenStackImageProvidersResource() {
+ super(OpenStackImageProvider.class, Provider.class, SUB_COLLECTIONS);
+ }
+
+ @Override
+ public OpenStackImageProviders list() {
+ return mapCollection(getBackendCollection());
+ }
+
+ private OpenStackImageProviders mapCollection(List<Provider> entities) {
+ OpenStackImageProviders collection = new OpenStackImageProviders();
+ for (Provider entity : entities) {
+ collection.getOpenStackImageProviders().add(addLinks(map(entity)));
+ }
+ return collection;
+ }
+
+ private List<Provider> getBackendCollection() {
+ if (isFiltered()) {
+ return getBackendCollection(
+ VdcQueryType.GetAllProviders,
+ new GetAllProvidersParameters(ProviderType.OPENSTACK_IMAGE)
+ );
+ }
+ else {
+ return getBackendCollection(SearchType.Provider, getConstraint());
+ }
+ }
+
+ private String getConstraint() {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("Providers: type=");
+ buffer.append(ProviderType.OPENSTACK_IMAGE.name());
+ String query = QueryHelper.getConstraint(getUriInfo(), null,
modelType, false);
+ if (StringUtils.isNotBlank(query)) {
+ buffer.append(" AND (");
+ buffer.append(query);
+ buffer.append(")");
+ }
+ return buffer.toString();
+ }
+
+ @Override
+ public Response add(OpenStackImageProvider provider) {
+ validateParameters(provider, "name");
+ return performCreate(
+ VdcActionType.AddProvider,
+ new ProviderParameters(map(provider)),
+ new QueryIdResolver<Guid>(VdcQueryType.GetProviderById,
IdQueryParameters.class)
+ );
+ }
+
+ @Override
+ protected Response performRemove(String id) {
+ Provider provider = BackendExternalProviderHelper.getProvider(this,
id);
+ ProviderParameters parameters = new ProviderParameters(provider);
+ return performAction(VdcActionType.RemoveProvider, parameters);
+ }
+
+ @Override
+ protected OpenStackImageProvider doPopulate(OpenStackImageProvider model,
Provider entity) {
+ return model;
+ }
+
+ @Override
+ @SingleEntityResource
+ public OpenStackImageProviderResource
getOpenStackImageProvider(@PathParam("id") String id) {
+ return inject(new BackendOpenStackImageProviderResource(id));
+ }
+}
diff --git
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImageResource.java
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImageResource.java
new file mode 100644
index 0000000..0f20b33
--- /dev/null
+++
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImageResource.java
@@ -0,0 +1,80 @@
+/*
+* Copyright (c) 2014 Red Hat, Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.ovirt.engine.api.restapi.resource.openstack;
+
+import javax.ws.rs.core.Response;
+
+import org.ovirt.engine.api.model.Action;
+import org.ovirt.engine.api.model.OpenStackImage;
+import org.ovirt.engine.api.model.OpenStackImageProvider;
+import org.ovirt.engine.api.resource.openstack.OpenStackImageResource;
+import org.ovirt.engine.api.restapi.resource.AbstractBackendActionableResource;
+import org.ovirt.engine.core.common.action.ImportRepoImageParameters;
+import org.ovirt.engine.core.common.action.VdcActionType;
+import org.ovirt.engine.core.common.businessentities.RepoImage;
+import org.ovirt.engine.core.common.queries.GetImageByIdParameters;
+import org.ovirt.engine.core.common.queries.VdcQueryType;
+import org.ovirt.engine.core.compat.Guid;
+
+public class BackendOpenStackImageResource
+ extends AbstractBackendActionableResource<OpenStackImage, RepoImage>
+ implements OpenStackImageResource {
+ private String providerId;
+
+ protected BackendOpenStackImageResource(String providerId, String id) {
+ super(id, OpenStackImage.class, RepoImage.class);
+ this.providerId = providerId;
+ }
+
+ @Override
+ public OpenStackImage get() {
+ Guid storageDomainId =
BackendOpenStackImageProviderHelper.getStorageDomainId(this, providerId);
+ return performGet(VdcQueryType.GetImageById, new
GetImageByIdParameters(storageDomainId, id));
+ }
+
+ @Override
+ protected OpenStackImage doPopulate(OpenStackImage model, RepoImage
entity) {
+ return model;
+ }
+
+ @Override
+ protected OpenStackImage addParents(OpenStackImage image) {
+ OpenStackImageProvider provider = new OpenStackImageProvider();
+ provider.setId(providerId);
+ image.setOpenstackImageProvider(provider);
+ return super.addParents(image);
+ }
+
+ @Override
+ public Response doImport(Action action) {
+ validateParameters(action, "storageDomain.id|name");
+ Guid storageDomainId =
BackendOpenStackImageProviderHelper.getStorageDomainId(this, providerId);
+ ImportRepoImageParameters parameters = new ImportRepoImageParameters();
+ parameters.setSourceRepoImageId(id);
+ parameters.setSourceStorageDomainId(storageDomainId);
+
parameters.setStoragePoolId(getDataCenterId(getStorageDomainId(action)));
+ parameters.setStorageDomainId(getStorageDomainId(action));
+ if (action.isSetImportAsTemplate()) {
+ if (action.isImportAsTemplate()) {
+ validateParameters(action, "cluster.id|name");
+ parameters.setClusterId(getClusterId(action));
+ }
+ parameters.setImportAsTemplate(action.isImportAsTemplate());
+ }
+ return doAction(VdcActionType.ImportRepoImage, parameters, action);
+ }
+}
diff --git
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImagesResource.java
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImagesResource.java
new file mode 100644
index 0000000..0c5c335
--- /dev/null
+++
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImagesResource.java
@@ -0,0 +1,83 @@
+/*
+* Copyright (c) 2014 Red Hat, Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.ovirt.engine.api.restapi.resource.openstack;
+
+import javax.ws.rs.core.Response;
+import java.util.List;
+
+import org.ovirt.engine.api.model.OpenStackImage;
+import org.ovirt.engine.api.model.OpenStackImageProvider;
+import org.ovirt.engine.api.model.OpenStackImages;
+import org.ovirt.engine.api.resource.openstack.OpenStackImageResource;
+import org.ovirt.engine.api.resource.openstack.OpenStackImagesResource;
+import org.ovirt.engine.api.restapi.resource.AbstractBackendCollectionResource;
+import org.ovirt.engine.api.restapi.resource.SingleEntityResource;
+import org.ovirt.engine.core.common.businessentities.ImageFileType;
+import org.ovirt.engine.core.common.businessentities.RepoImage;
+import org.ovirt.engine.core.common.queries.GetImagesListParameters;
+import org.ovirt.engine.core.common.queries.VdcQueryType;
+import org.ovirt.engine.core.compat.Guid;
+
+public class BackendOpenStackImagesResource
+ extends AbstractBackendCollectionResource<OpenStackImage, RepoImage>
+ implements OpenStackImagesResource {
+ private String providerId;
+
+ public BackendOpenStackImagesResource(String providerId) {
+ super(OpenStackImage.class, RepoImage.class);
+ this.providerId = providerId;
+ }
+
+ @Override
+ public OpenStackImages list() {
+ Guid storageDomainId =
BackendOpenStackImageProviderHelper.getStorageDomainId(this, providerId);
+ GetImagesListParameters parameters = new
GetImagesListParameters(storageDomainId, ImageFileType.All);
+ return mapCollection(getBackendCollection(VdcQueryType.GetImagesList,
parameters));
+ }
+
+ @Override
+ protected OpenStackImage doPopulate(OpenStackImage model, RepoImage
entity) {
+ return model;
+ }
+
+ protected OpenStackImages mapCollection(List<RepoImage> entities) {
+ OpenStackImages collection = new OpenStackImages();
+ for (RepoImage image : entities) {
+ collection.getOpenStackImages().add(addLinks(populate(map(image),
image)));
+ }
+ return collection;
+ }
+
+ @Override
+ protected OpenStackImage addParents(OpenStackImage image) {
+ OpenStackImageProvider provider = new OpenStackImageProvider();
+ provider.setId(providerId);
+ image.setOpenstackImageProvider(provider);
+ return super.addParents(image);
+ }
+
+ @Override
+ protected Response performRemove(String id) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ @SingleEntityResource
+ public OpenStackImageResource getOpenStackImage(String id) {
+ return inject(new BackendOpenStackImageResource(providerId, id));
+ }
+}
diff --git
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/utils/FeaturesHelper.java
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/utils/FeaturesHelper.java
index aca137e..d6dd258 100644
---
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/utils/FeaturesHelper.java
+++
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/utils/FeaturesHelper.java
@@ -94,6 +94,7 @@
}
if (VersionUtils.greaterOrEqual(version,
BackendCapabilitiesResource.VERSION_3_6)) {
addForemanHostProvidersFeature(features);
+ addOpenStackImageProvidersFeature(features);
}
return features;
}
@@ -528,4 +529,11 @@
feature.setDescription("Add/modify/remove Foreman host providers.");
features.getFeature().add(feature);
}
+
+ private void addOpenStackImageProvidersFeature(Features features) {
+ Feature feature = new Feature();
+ feature.setName("OpenStack Image Providers");
+ feature.setDescription("Add/modify/remove OpenStack image providers.");
+ features.getFeature().add(feature);
+ }
}
diff --git
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java
index caf6780..cc0de9c 100644
---
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java
+++
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java
@@ -128,6 +128,7 @@
"permissions",
"macpools",
"foremanhostproviders",
+ "openstackimageproviders",
};
private static final String[] relationshipsGlusterOnly = {
@@ -191,6 +192,7 @@
BASE_PATH + "/permissions",
BASE_PATH + "/macpools",
BASE_PATH + "/foremanhostproviders",
+ BASE_PATH + "/openstackimageproviders",
};
private static final String[] hrefsGlusterOnly = {
diff --git
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImageProviderResourceTest.java
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImageProviderResourceTest.java
new file mode 100644
index 0000000..bbe7480
--- /dev/null
+++
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImageProviderResourceTest.java
@@ -0,0 +1,179 @@
+/*
+* Copyright (c) 2014 Red Hat, Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.ovirt.engine.api.restapi.resource.openstack;
+
+import static org.easymock.EasyMock.expect;
+
+import javax.ws.rs.WebApplicationException;
+
+import org.junit.Test;
+import org.ovirt.engine.api.model.OpenStackImageProvider;
+import org.ovirt.engine.api.restapi.resource.AbstractBackendSubResourceTest;
+import org.ovirt.engine.core.common.action.ProviderParameters;
+import org.ovirt.engine.core.common.action.VdcActionType;
+import org.ovirt.engine.core.common.businessentities.Provider;
+import org.ovirt.engine.core.common.queries.IdQueryParameters;
+import org.ovirt.engine.core.common.queries.VdcQueryType;
+
+public class BackendOpenStackImageProviderResourceTest
+ extends AbstractBackendSubResourceTest<OpenStackImageProvider,
Provider, BackendOpenStackImageProviderResource> {
+ public BackendOpenStackImageProviderResourceTest() {
+ super(new BackendOpenStackImageProviderResource(GUIDS[0].toString()));
+ }
+
+ @Test
+ public void testBadGuid() throws Exception {
+ control.replay();
+ try {
+ new BackendOpenStackImageProviderResource("foo");
+ fail("expected WebApplicationException");
+ }
+ catch (WebApplicationException wae) {
+ verifyNotFoundException(wae);
+ }
+ }
+
+ @Test
+ public void testGetNotFound() throws Exception {
+ setUriInfo(setUpBasicUriExpectations());
+ setUpGetEntityExpectations(1, true);
+ control.replay();
+ try {
+ resource.get();
+ fail("expected WebApplicationException");
+ } catch (WebApplicationException wae) {
+ verifyNotFoundException(wae);
+ }
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ setUriInfo(setUpBasicUriExpectations());
+ setUpGetEntityExpectations(1);
+ control.replay();
+ verifyModel(resource.get(), 0);
+ }
+
+ @Test
+ public void testUpdateNotFound() throws Exception {
+ setUriInfo(setUpBasicUriExpectations());
+ setUpGetEntityExpectations(1, true);
+ control.replay();
+ try {
+ resource.update(getModel(0));
+ fail("expected WebApplicationException");
+ } catch (WebApplicationException wae) {
+ verifyNotFoundException(wae);
+ }
+ }
+
+ @Test
+ public void testUpdate() throws Exception {
+ setUpGetEntityExpectations(2);
+ setUriInfo(
+ setUpActionExpectations(
+ VdcActionType.UpdateProvider,
+ ProviderParameters.class,
+ new String[] { "Provider.Id" },
+ new Object[] { GUIDS[0] },
+ true,
+ true
+ )
+ );
+ verifyModel(resource.update(getModel(0)), 0);
+ }
+
+ @Test
+ public void testUpdateCantDo() throws Exception {
+ doTestBadUpdate(false, true, CANT_DO);
+ }
+
+ @Test
+ public void testUpdateFailed() throws Exception {
+ doTestBadUpdate(true, false, FAILURE);
+ }
+
+ private void doTestBadUpdate(boolean canDo, boolean success, String
detail) throws Exception {
+ setUpGetEntityExpectations(1);
+ setUriInfo(
+ setUpActionExpectations(
+ VdcActionType.UpdateProvider,
+ ProviderParameters.class,
+ new String[] { "Provider.Id" },
+ new Object[] { GUIDS[0] },
+ canDo,
+ success
+ )
+ );
+ try {
+ resource.update(getModel(0));
+ fail("expected WebApplicationException");
+ }
+ catch (WebApplicationException wae) {
+ verifyFault(wae, detail);
+ }
+ }
+
+ @Test
+ public void testConflictedUpdate() throws Exception {
+ setUriInfo(setUpBasicUriExpectations());
+ setUpGetEntityExpectations(1);
+ control.replay();
+
+ OpenStackImageProvider model = getModel(1);
+ model.setId(GUIDS[1].toString());
+ try {
+ resource.update(model);
+ fail("expected WebApplicationException");
+ }
+ catch (WebApplicationException wae) {
+ verifyImmutabilityConstraint(wae);
+ }
+ }
+
+ private OpenStackImageProvider getModel(int index) {
+ OpenStackImageProvider model = new OpenStackImageProvider();
+ model.setName(NAMES[index]);
+ model.setDescription(DESCRIPTIONS[index]);
+ return model;
+ }
+
+ @Override
+ protected Provider getEntity(int index) {
+ Provider provider = control.createMock(Provider.class);
+ expect(provider.getId()).andReturn(GUIDS[index]).anyTimes();
+ expect(provider.getName()).andReturn(NAMES[index]).anyTimes();
+
expect(provider.getDescription()).andReturn(DESCRIPTIONS[index]).anyTimes();
+ return provider;
+ }
+
+ protected void setUpGetEntityExpectations(int times) throws Exception {
+ setUpGetEntityExpectations(times, false);
+ }
+
+ protected void setUpGetEntityExpectations(int times, boolean notFound)
throws Exception {
+ while (times-- > 0) {
+ setUpGetEntityExpectations(
+ VdcQueryType.GetProviderById,
+ IdQueryParameters.class,
+ new String[] { "Id" },
+ new Object[] { GUIDS[0] },
+ notFound? null: getEntity(0)
+ );
+ }
+ }
+}
diff --git
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImageProvidersResourceTest.java
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImageProvidersResourceTest.java
new file mode 100644
index 0000000..db8b20a
--- /dev/null
+++
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImageProvidersResourceTest.java
@@ -0,0 +1,62 @@
+/*
+* Copyright (c) 2014 Red Hat, Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.ovirt.engine.api.restapi.resource.openstack;
+
+import static org.easymock.EasyMock.expect;
+
+import java.util.List;
+
+import org.apache.commons.lang.StringUtils;
+import org.ovirt.engine.api.model.OpenStackImageProvider;
+import
org.ovirt.engine.api.restapi.resource.AbstractBackendCollectionResourceTest;
+import org.ovirt.engine.core.common.businessentities.Provider;
+import org.ovirt.engine.core.common.businessentities.ProviderType;
+import org.ovirt.engine.core.common.interfaces.SearchType;
+
+public class BackendOpenStackImageProvidersResourceTest extends
+ AbstractBackendCollectionResourceTest<OpenStackImageProvider,
Provider, BackendOpenStackImageProvidersResource> {
+
+ public BackendOpenStackImageProvidersResourceTest() {
+ super(
+ new BackendOpenStackImageProvidersResource(),
+ SearchType.Provider,
+ "Providers: type=" + ProviderType.OPENSTACK_IMAGE.name()
+ );
+ }
+
+ @Override
+ protected List<OpenStackImageProvider> getCollection() {
+ return collection.list().getOpenStackImageProviders();
+ }
+
+ @Override
+ protected void setUpQueryExpectations(String query) throws Exception {
+ if (StringUtils.isNotBlank(query)) {
+ query = " AND (" + query + ")";
+ }
+ super.setUpQueryExpectations(query);
+ }
+
+ @Override
+ protected Provider getEntity(int index) {
+ Provider provider = control.createMock(Provider.class);
+ expect(provider.getId()).andReturn(GUIDS[index]).anyTimes();
+ expect(provider.getName()).andReturn(NAMES[index]).anyTimes();
+
expect(provider.getDescription()).andReturn(DESCRIPTIONS[index]).anyTimes();
+ return provider;
+ }
+}
diff --git
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImageResourceTest.java
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImageResourceTest.java
new file mode 100644
index 0000000..b7cf441
--- /dev/null
+++
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImageResourceTest.java
@@ -0,0 +1,111 @@
+/*
+* Copyright (c) 2014 Red Hat, Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.ovirt.engine.api.restapi.resource.openstack;
+
+import static org.easymock.EasyMock.expect;
+
+import javax.ws.rs.WebApplicationException;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.Test;
+import org.ovirt.engine.api.model.OpenStackImage;
+import org.ovirt.engine.api.restapi.resource.AbstractBackendSubResourceTest;
+import org.ovirt.engine.core.common.businessentities.RepoImage;
+import org.ovirt.engine.core.common.businessentities.StorageDomain;
+import org.ovirt.engine.core.common.queries.GetImageByIdParameters;
+import org.ovirt.engine.core.common.queries.VdcQueryParametersBase;
+import org.ovirt.engine.core.common.queries.VdcQueryType;
+
+public class BackendOpenStackImageResourceTest
+ extends AbstractBackendSubResourceTest<OpenStackImage, RepoImage,
BackendOpenStackImageResource> {
+ public BackendOpenStackImageResourceTest() {
+ super(new BackendOpenStackImageResource(GUIDS[0].toString(),
GUIDS[1].toString()));
+ }
+
+ @Test
+ public void testBadId() throws Exception {
+ control.replay();
+ try {
+ new BackendOpenStackImageProviderResource("foo");
+ fail("expected WebApplicationException");
+ }
+ catch (WebApplicationException wae) {
+ verifyNotFoundException(wae);
+ }
+ }
+
+ @Test
+ public void testGetNotFound() throws Exception {
+ setUriInfo(setUpBasicUriExpectations());
+ setUpGetEntityExpectations(true);
+ control.replay();
+ try {
+ resource.get();
+ fail("expected WebApplicationException");
+ }
+ catch (WebApplicationException wae) {
+ verifyNotFoundException(wae);
+ }
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ setUriInfo(setUpBasicUriExpectations());
+ setUpGetEntityExpectations(false);
+ control.replay();
+ verifyModel(resource.get(), 1);
+ }
+
+ private List<StorageDomain> getStorageDomains() {
+ StorageDomain storageDomain = control.createMock(StorageDomain.class);
+ expect(storageDomain.getId()).andReturn(GUIDS[0]).anyTimes();
+
expect(storageDomain.getStorage()).andReturn(GUIDS[0].toString()).anyTimes();
+ return Collections.singletonList(storageDomain);
+ }
+
+ @Override
+ protected RepoImage getEntity(int index) {
+ RepoImage image = control.createMock(RepoImage.class);
+
expect(image.getRepoImageId()).andReturn(GUIDS[index].toString()).anyTimes();
+ expect(image.getRepoImageName()).andReturn(NAMES[index]).anyTimes();
+ return image;
+ }
+
+ private void setUpGetEntityExpectations(boolean notFound) throws Exception
{
+ setUpEntityQueryExpectations(
+ VdcQueryType.GetAllStorageDomains,
+ VdcQueryParametersBase.class,
+ new String[] {},
+ new Object[] {},
+ getStorageDomains()
+ );
+ setUpGetEntityExpectations(
+ VdcQueryType.GetImageById,
+ GetImageByIdParameters.class,
+ new String[] { "RepoImageId" },
+ new Object[] { GUIDS[1].toString() },
+ notFound? null: getEntity(1)
+ );
+ }
+
+ @Override
+ protected void verifyModel(OpenStackImage model, int index) {
+ assertEquals(NAMES[index], model.getName());
+ verifyLinks(model);
+ }
+}
diff --git
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImagesResourceTest.java
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImagesResourceTest.java
new file mode 100644
index 0000000..670d7be
--- /dev/null
+++
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackImagesResourceTest.java
@@ -0,0 +1,96 @@
+/*
+* Copyright (c) 2014 Red Hat, Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.ovirt.engine.api.restapi.resource.openstack;
+
+import static org.easymock.EasyMock.expect;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.ovirt.engine.api.model.OpenStackImage;
+import
org.ovirt.engine.api.restapi.resource.AbstractBackendCollectionResourceTest;
+import org.ovirt.engine.core.common.businessentities.RepoImage;
+import org.ovirt.engine.core.common.businessentities.StorageDomain;
+import org.ovirt.engine.core.common.queries.GetImagesListParameters;
+import org.ovirt.engine.core.common.queries.VdcQueryParametersBase;
+import org.ovirt.engine.core.common.queries.VdcQueryType;
+
+public class BackendOpenStackImagesResourceTest extends
+ AbstractBackendCollectionResourceTest<OpenStackImage, RepoImage,
BackendOpenStackImagesResource> {
+ public BackendOpenStackImagesResourceTest() {
+ super(
+ new BackendOpenStackImagesResource(GUIDS[0].toString()),
+ null,
+ ""
+ );
+ }
+
+ @Override
+ protected List<OpenStackImage> getCollection() {
+ return collection.list().getOpenStackImages();
+ }
+
+ @Override
+ protected void setUpQueryExpectations(String query, Object failure) throws
Exception {
+ setUpEntityQueryExpectations(
+ VdcQueryType.GetAllStorageDomains,
+ VdcQueryParametersBase.class,
+ new String[] {},
+ new Object[] {},
+ getStorageDomains()
+ );
+ setUpEntityQueryExpectations(
+ VdcQueryType.GetImagesList,
+ GetImagesListParameters.class,
+ new String[] { "StorageDomainId" },
+ new Object[] { GUIDS[0] },
+ getImages(),
+ failure
+ );
+ control.replay();
+ }
+
+ private List<StorageDomain> getStorageDomains() {
+ StorageDomain storageDomain = control.createMock(StorageDomain.class);
+ expect(storageDomain.getId()).andReturn(GUIDS[0]).anyTimes();
+
expect(storageDomain.getStorage()).andReturn(GUIDS[0].toString()).anyTimes();
+ return Collections.singletonList(storageDomain);
+ }
+
+ private List<RepoImage> getImages() {
+ List<RepoImage> images = new ArrayList<>();
+ for (int i = 0; i < NAMES.length; i++) {
+ images.add(getEntity(i));
+ }
+ return images;
+ }
+
+ @Override
+ protected RepoImage getEntity(int index) {
+ RepoImage image = control.createMock(RepoImage.class);
+
expect(image.getRepoImageId()).andReturn(GUIDS[index].toString()).anyTimes();
+ expect(image.getRepoImageName()).andReturn(NAMES[index]).anyTimes();
+ return image;
+ }
+
+ @Override
+ protected void verifyModel(OpenStackImage model, int index) {
+ assertEquals(NAMES[index], model.getName());
+ verifyLinks(model);
+ }
+}
diff --git
a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/openstack/OpenStackImageMapper.java
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/openstack/OpenStackImageMapper.java
new file mode 100644
index 0000000..f136c50
--- /dev/null
+++
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/openstack/OpenStackImageMapper.java
@@ -0,0 +1,47 @@
+/*
+* Copyright (c) 2014 Red Hat, Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.ovirt.engine.api.restapi.types.openstack;
+
+import org.ovirt.engine.api.model.OpenStackImage;
+import org.ovirt.engine.api.restapi.types.Mapping;
+import org.ovirt.engine.core.common.businessentities.RepoImage;
+
+public class OpenStackImageMapper {
+ @Mapping(from = RepoImage.class, to = OpenStackImage.class)
+ public static OpenStackImage map(RepoImage entity, OpenStackImage
template) {
+ OpenStackImage model = template != null? template: new
OpenStackImage();
+ if (entity.getRepoImageId() != null) {
+ model.setId(entity.getRepoImageId());
+ }
+ if (entity.getRepoImageName() != null) {
+ model.setName(entity.getRepoImageName());
+ }
+ return model;
+ }
+
+ @Mapping(from = OpenStackImage.class, to = RepoImage.class)
+ public static RepoImage map(OpenStackImage model, RepoImage template) {
+ RepoImage entity = template != null? template: new RepoImage();
+ if (model.isSetId()) {
+ entity.setRepoImageId(model.getId());
+ }
+ if (model.isSetName()) {
+ entity.setRepoImageName(model.getName());
+ }
+ return entity;
+ }
+}
diff --git
a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/openstack/OpenStackImageProviderMapper.java
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/openstack/OpenStackImageProviderMapper.java
new file mode 100644
index 0000000..f454824
--- /dev/null
+++
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/openstack/OpenStackImageProviderMapper.java
@@ -0,0 +1,117 @@
+/*
+* Copyright (c) 2014 Red Hat, Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.ovirt.engine.api.restapi.types.openstack;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.ovirt.engine.api.model.OpenStackImageProvider;
+import org.ovirt.engine.api.model.Properties;
+import org.ovirt.engine.api.model.Property;
+import org.ovirt.engine.api.restapi.types.Mapping;
+import org.ovirt.engine.api.restapi.utils.GuidUtils;
+import
org.ovirt.engine.core.common.businessentities.OpenStackImageProviderProperties;
+import org.ovirt.engine.core.common.businessentities.Provider;
+import org.ovirt.engine.core.common.businessentities.ProviderType;
+
+public class OpenStackImageProviderMapper {
+ @Mapping(from = OpenStackImageProvider.class, to = Provider.class)
+ public static Provider<OpenStackImageProviderProperties>
map(OpenStackImageProvider model,
+ Provider<OpenStackImageProviderProperties> template) {
+ Provider<OpenStackImageProviderProperties> entity =
+ template != null? template: new
Provider<OpenStackImageProviderProperties>();
+ entity.setType(ProviderType.OPENSTACK_IMAGE);
+ if (model.isSetId()) {
+ entity.setId(GuidUtils.asGuid(model.getId()));
+ }
+ if (model.isSetName()) {
+ entity.setName(model.getName());
+ }
+ if (model.isSetDescription()) {
+ entity.setDescription(model.getDescription());
+ }
+ if (model.isSetUrl()) {
+ entity.setUrl(model.getUrl());
+ }
+ if (model.isSetRequiresAuthentication()) {
+
entity.setRequiringAuthentication(model.isRequiresAuthentication());
+ }
+ if (model.isSetUsername()) {
+ entity.setUsername(model.getUsername());
+ }
+ if (model.isSetPassword()) {
+ entity.setPassword(model.getPassword());
+ }
+ if (model.isSetProperties()) {
+ Map<String, String> map = new HashMap<>();
+ for (Property property : model.getProperties().getProperties()) {
+ map.put(property.getName(), property.getValue());
+ }
+ entity.setCustomProperties(map);
+ }
+ OpenStackImageProviderProperties additionalProperties = new
OpenStackImageProviderProperties();
+ if (model.isSetTenantName()) {
+ additionalProperties.setTenantName(model.getTenantName());
+ }
+ entity.setAdditionalProperties(additionalProperties);
+ return entity;
+ }
+
+ @Mapping(from = Provider.class, to = OpenStackImageProvider.class)
+ public static OpenStackImageProvider
map(Provider<OpenStackImageProviderProperties> entity,
+ OpenStackImageProvider template) {
+ OpenStackImageProvider model = template != null? template: new
OpenStackImageProvider();
+ if (entity.getId() != null) {
+ model.setId(entity.getId().toString());
+ }
+ if (entity.getName() != null) {
+ model.setName(entity.getName());
+ }
+ if (entity.getDescription() != null) {
+ model.setDescription(entity.getDescription());
+ }
+ if (entity.getUrl() != null) {
+ model.setUrl(entity.getUrl());
+ }
+ model.setRequiresAuthentication(entity.isRequiringAuthentication());
+ if (entity.getUsername() != null) {
+ model.setUsername(entity.getUsername());
+ }
+ // The password isn't mapped for security reasons.
+ // if (entity.getPassword() != null) {
+ // model.setPassword(entity.getPassword());
+ // }
+ Map<String, String> customProperties = entity.getCustomProperties();
+ if (customProperties != null) {
+ Properties properties = new Properties();
+ for (Map.Entry<String, String> entry :
customProperties.entrySet()) {
+ Property property = new Property();
+ property.setName(entry.getKey());
+ property.setValue(entry.getValue());
+ properties.getProperties().add(property);
+ }
+ model.setProperties(properties);
+ }
+ OpenStackImageProviderProperties additionalProperties =
entity.getAdditionalProperties();
+ if (additionalProperties != null) {
+ if (additionalProperties.getTenantName() != null) {
+ model.setTenantName(additionalProperties.getTenantName());
+ }
+ }
+ return model;
+ }
+}
diff --git
a/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/openstack/OpenStackImageMapperTest.java
b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/openstack/OpenStackImageMapperTest.java
new file mode 100644
index 0000000..30db418
--- /dev/null
+++
b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/openstack/OpenStackImageMapperTest.java
@@ -0,0 +1,35 @@
+/*
+* Copyright (c) 2014 Red Hat, Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.ovirt.engine.api.restapi.types.openstack;
+
+import org.ovirt.engine.api.model.OpenStackImage;
+import org.ovirt.engine.api.restapi.types.AbstractInvertibleMappingTest;
+import org.ovirt.engine.core.common.businessentities.RepoImage;
+
+public class OpenStackImageMapperTest
+ extends AbstractInvertibleMappingTest<OpenStackImage, RepoImage,
RepoImage> {
+ public OpenStackImageMapperTest() {
+ super(OpenStackImage.class, RepoImage.class, RepoImage.class);
+ }
+
+ @Override
+ protected void verify(OpenStackImage model, OpenStackImage transform) {
+ assertNotNull(transform);
+ assertEquals(model.getId(), transform.getId());
+ assertEquals(model.getName(), transform.getName());
+ }
+}
diff --git
a/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/openstack/OpenStackImageProviderMapperTest.java
b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/openstack/OpenStackImageProviderMapperTest.java
new file mode 100644
index 0000000..7545fbb
--- /dev/null
+++
b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/openstack/OpenStackImageProviderMapperTest.java
@@ -0,0 +1,42 @@
+/*
+* Copyright (c) 2014 Red Hat, Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.ovirt.engine.api.restapi.types.openstack;
+
+import org.ovirt.engine.api.model.OpenStackImageProvider;
+import org.ovirt.engine.api.restapi.types.AbstractInvertibleMappingTest;
+import org.ovirt.engine.core.common.businessentities.Provider;
+
+public class OpenStackImageProviderMapperTest
+ extends AbstractInvertibleMappingTest<OpenStackImageProvider,
Provider, Provider> {
+ public OpenStackImageProviderMapperTest() {
+ super(OpenStackImageProvider.class, Provider.class, Provider.class);
+ }
+
+ @Override
+ protected void verify(OpenStackImageProvider model, OpenStackImageProvider
transform) {
+ assertNotNull(transform);
+ assertEquals(model.getId(), transform.getId());
+ assertEquals(model.getName(), transform.getName());
+ assertEquals(model.getDescription(), transform.getDescription());
+ assertEquals(model.isRequiresAuthentication(),
transform.isRequiresAuthentication());
+ assertEquals(model.getUrl(), transform.getUrl());
+ assertEquals(model.getUsername(), transform.getUsername());
+ // The password isn't mapped for security reasons.
+ assertNull(transform.getPassword());
+ assertEquals(model.getTenantName(), transform.getTenantName());
+ }
+}
--
To view, visit http://gerrit.ovirt.org/33975
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I77fca2208b18d54f9177ec8b0178768a6b815f20
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches