Skip to content

Commit

Permalink
Automatically upload composed images to the cloud
Browse files Browse the repository at this point in the history
Currently, Azure, vSphere, and OpenStack are supported. See
weldr#826 for more details about this new
feature.

I've called the upload library "lifted" as a reference to Seuss'
The Lorax -- in the book, the Lorax lifts himself up by the seat of his
pants through a hole in the smog clouds, and they start calling him the
"Lifted Lorax."

This adds new features to the /compose route under API v1
  • Loading branch information
evan-goode authored and bcl committed Sep 24, 2019
1 parent 71efbaf commit 3eaf40f
Show file tree
Hide file tree
Showing 20 changed files with 1,443 additions and 16 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
url="http://www.github.com/weldr/lorax/",
download_url="http://www.github.com/weldr/lorax/releases/",
license="GPLv2+",
packages=["pylorax", "pylorax.api", "composer", "composer.cli"],
packages=["pylorax", "pylorax.api", "composer", "composer.cli", "lifted"],
package_dir={"" : "src"},
data_files=data_files
)
47 changes: 47 additions & 0 deletions share/lifted/providers/azure/playbook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
- hosts: localhost
connection: local
tasks:
- name: Make sure provided credentials work and the storage account exists
azure_rm_storageaccount_facts:
subscription_id: "{{ subscription_id }}"
client_id: "{{ client_id }}"
secret: "{{ secret }}"
tenant: "{{ tenant }}"
resource_group: "{{ resource_group }}"
name: "{{ storage_account_name }}"
register: storageaccount_facts
- name: Fail if we couldn't log in or the storage account was not found
fail:
msg: "Invalid credentials or storage account not found!"
when: storageaccount_facts.ansible_facts.azure_storageaccounts | length < 1
- stat:
path: "{{ image_path }}"
register: image_stat
- set_fact:
image_id: "{{ image_name }}-{{ image_stat['stat']['checksum'] }}.vhd"
- name: Upload image to Azure
azure_rm_storageblob:
subscription_id: "{{ subscription_id }}"
client_id: "{{ client_id }}"
secret: "{{ secret }}"
tenant: "{{ tenant }}"
resource_group: "{{ resource_group }}"
storage_account_name: "{{ storage_account_name }}"
container: "{{ storage_container }}"
src: "{{ image_path }}"
blob: "{{ image_id }}"
blob_type: page
force: no
- set_fact:
host: "{{ storage_account_name }}.blob.core.windows.net"
- name: Import image
azure_rm_image:
subscription_id: "{{ subscription_id }}"
client_id: "{{ client_id }}"
secret: "{{ secret }}"
tenant: "{{ tenant }}"
resource_group: "{{ resource_group }}"
name: "{{ image_name }}"
os_type: Linux
location: "{{ location }}"
source: "https://{{ host }}/{{ storage_container }}/{{ image_id }}"
53 changes: 53 additions & 0 deletions share/lifted/providers/azure/provider.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
display = "Azure"

supported_types = [
"vhd",
]

[settings-info.resource_group]
display = "Resource group"
type = "string"
placeholder = ""
regex = ''

[settings-info.storage_account_name]
display = "Storage account name"
type = "string"
placeholder = ""
regex = ''

[settings-info.storage_container]
display = "Storage container"
type = "string"
placeholder = ""
regex = ''

[settings-info.subscription_id]
display = "Subscription ID"
type = "string"
placeholder = ""
regex = ''

[settings-info.client_id]
display = "Client ID"
type = "string"
placeholder = ""
regex = ''

[settings-info.secret]
display = "Secret"
type = "string"
placeholder = ""
regex = ''

[settings-info.tenant]
display = "Tenant"
type = "string"
placeholder = ""
regex = ''

[settings-info.location]
display = "Location"
type = "string"
placeholder = ""
regex = ''
4 changes: 4 additions & 0 deletions share/lifted/providers/dummy/playbook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- hosts: localhost
connection: local
tasks:
- pause: seconds=30
4 changes: 4 additions & 0 deletions share/lifted/providers/dummy/provider.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
display = "Dummy"

[settings-info]
# This provider has no settings.
20 changes: 20 additions & 0 deletions share/lifted/providers/openstack/playbook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
- hosts: localhost
connection: local
tasks:
- stat:
path: "{{ image_path }}"
register: image_stat
- set_fact:
image_id: "{{ image_name }}-{{ image_stat['stat']['checksum'] }}.qcow2"
- name: Upload image to OpenStack
os_image:
auth:
auth_url: "{{ auth_url }}"
username: "{{ username }}"
password: "{{ password }}"
project_name: "{{ project_name }}"
os_user_domain_name: "{{ user_domain_name }}"
os_project_domain_name: "{{ project_domain_name }}"
name: "{{ image_id }}"
filename: "{{ image_path }}"
is_public: "{{ is_public }}"
45 changes: 45 additions & 0 deletions share/lifted/providers/openstack/provider.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
display = "OpenStack"

supported_types = [
"qcow2",
]

[settings-info.auth_url]
display = "Authentication URL"
type = "string"
placeholder = ""
regex = ''

[settings-info.username]
display = "Username"
type = "string"
placeholder = ""
regex = ''

[settings-info.password]
display = "Password"
type = "string"
placeholder = ""
regex = ''

[settings-info.project_name]
display = "Project name"
type = "string"
placeholder = ""
regex = ''

[settings-info.user_domain_name]
display = "User domain name"
type = "string"
placeholder = ""
regex = ''

[settings-info.project_domain_name]
display = "Project domain name"
type = "string"
placeholder = ""
regex = ''

[settings-info.is_public]
display = "Allow public access"
type = "boolean"
17 changes: 17 additions & 0 deletions share/lifted/providers/vsphere/playbook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
- hosts: localhost
connection: local
tasks:
- stat:
path: "{{ image_path }}"
register: image_stat
- set_fact:
image_id: "{{ image_name }}-{{ image_stat['stat']['checksum'] }}.vmdk"
- name: Upload image to vSphere
vsphere_copy:
login: "{{ username }}"
password: "{{ password }}"
host: "{{ host }}"
datacenter: "{{ datacenter }}"
datastore: "{{ datastore }}"
src: "{{ image_path }}"
path: "{{ folder }}/{{ image_id }}"
42 changes: 42 additions & 0 deletions share/lifted/providers/vsphere/provider.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
display = "vSphere"

supported_types = [
"vmdk",
]

[settings-info.datacenter]
display = "Datacenter"
type = "string"
placeholder = ""
regex = ''

[settings-info.datastore]
display = "Datastore"
type = "string"
placeholder = ""
regex = ''

[settings-info.host]
display = "Host"
type = "string"
placeholder = ""
regex = ''

[settings-info.folder]
display = "Folder"
type = "string"
placeholder = ""
regex = ''

[settings-info.username]
display = "Username"
type = "string"
placeholder = ""
regex = ''

[settings-info.password]
display = "Password"
type = "string"
placeholder = ""
regex = ''

16 changes: 16 additions & 0 deletions src/lifted/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Copyright (C) 2019 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
Loading

0 comments on commit 3eaf40f

Please sign in to comment.