CORD-3010 Download image if 'path' is a URL
Change-Id: I26f3f61af418438d3af01193a737482a390b8615
diff --git a/xos/synchronizer/steps/sync_controller_images.py b/xos/synchronizer/steps/sync_controller_images.py
index 4b6bded..78d205f 100644
--- a/xos/synchronizer/steps/sync_controller_images.py
+++ b/xos/synchronizer/steps/sync_controller_images.py
@@ -13,6 +13,7 @@
# limitations under the License.
import os
+import urlparse
import base64
from synchronizers.openstack.openstacksyncstep import OpenStackSyncStep
from synchronizers.new_base.syncstep import *
@@ -32,6 +33,14 @@
return super(SyncControllerImages, self).fetch_pending(deleted)
def map_sync_inputs(self, controller_image):
+ if controller_image.image.path.startswith("http"):
+ location = controller_image.image.path
+ a = urlparse.urlparse(location)
+ filepath = "/opt/xos/images" + a.path
+ else:
+ filepath = controller_image.image.path
+ location = None
+
image_fields = {'endpoint':controller_image.controller.auth_url,
'endpoint_v3': controller_image.controller.auth_url_v3,
'admin_user':controller_image.controller.admin_user,
@@ -39,7 +48,8 @@
'admin_project': 'admin',
'domain': controller_image.controller.domain,
'name':controller_image.image.name,
- 'filepath':controller_image.image.path,
+ 'filepath':filepath,
+ 'location':location,
'ansible_tag': '%s@%s'%(controller_image.image.name,controller_image.controller.name), # name of ansible playbook
}
diff --git a/xos/synchronizer/steps/sync_controller_images.yaml b/xos/synchronizer/steps/sync_controller_images.yaml
index 3c68294..0ce4d4b 100644
--- a/xos/synchronizer/steps/sync_controller_images.yaml
+++ b/xos/synchronizer/steps/sync_controller_images.yaml
@@ -19,6 +19,18 @@
connection: local
tasks:
+{% if location and filepath %}
+ - file:
+ path: "{{ '{{' }} '{{ filepath }}' | dirname {{ '}}' }}"
+ state: directory
+ mode: 0755
+
+ - get_url:
+ url: "{{ location }}"
+ dest: "{{ filepath }}"
+ mode: 0644
+{% endif %}
+
- os_image:
name: "{{ name }}"
filename: "{{ filepath }}"