mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-24 15:36:27 +00:00
Merge pull request #316 from justinsb/fix/gce_upload
Fixes for uploading a GCE image
This commit is contained in:
commit
3c1999f809
2 changed files with 15 additions and 15 deletions
|
@ -3,11 +3,15 @@ Google Compute Engine
|
||||||
|
|
||||||
The `GCE <https://cloud.google.com/products/compute-engine/>`__ provider
|
The `GCE <https://cloud.google.com/products/compute-engine/>`__ provider
|
||||||
can creates image as expected by GCE - i.e. raw disk image in \*.tar.gz
|
can creates image as expected by GCE - i.e. raw disk image in \*.tar.gz
|
||||||
file. It can upload created images to Google Storage Engine (to URI
|
file. It can upload created images to Google Cloud Storage (to a URI
|
||||||
provided in manifest by ``gcs_destination``) and can register image to
|
provided in the manifest by ``gcs_destination``) and can register images to
|
||||||
be used by Google Compute Engine to project provided in manifest by
|
be used by Google Compute Engine to a project provided in the manifest by
|
||||||
``gce_project``. Both of those functionalities are not fully tested yet.
|
``gce_project``. Both of those functionalities are not fully tested yet.
|
||||||
|
|
||||||
|
Note that to register an image, it must first be uploaded to GCS, so you must
|
||||||
|
specify ``gcs_destination`` (upload to GCS) to use ``gce_project`` (register
|
||||||
|
with GCE)
|
||||||
|
|
||||||
Manifest settings
|
Manifest settings
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
@ -15,7 +19,7 @@ Provider
|
||||||
~~~~~~~~
|
~~~~~~~~
|
||||||
|
|
||||||
- ``description``: Description of the image.
|
- ``description``: Description of the image.
|
||||||
- ``gcs_destination``: Image destination in GSE.
|
- ``gcs_destination``: Image destination in GCS.
|
||||||
- ``gce_project``: GCE project in which to register the image.
|
- ``gce_project``: GCE project in which to register the image.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,16 +12,8 @@ class CreateTarball(Task):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def run(cls, info):
|
def run(cls, info):
|
||||||
import datetime
|
|
||||||
image_name = info.manifest.name.format(**info.manifest_vars)
|
image_name = info.manifest.name.format(**info.manifest_vars)
|
||||||
filename = image_name + '.' + info.volume.extension
|
filename = image_name + '.' + info.volume.extension
|
||||||
today = datetime.datetime.today()
|
|
||||||
name_suffix = today.strftime('%Y%m%d')
|
|
||||||
image_name_format = '{lsb_distribution}-{lsb_release}-{release}-v{name_suffix}'
|
|
||||||
image_name = image_name_format.format(lsb_distribution=info._gce['lsb_distribution'],
|
|
||||||
lsb_release=info._gce['lsb_release'],
|
|
||||||
release=info.manifest.system['release'],
|
|
||||||
name_suffix=name_suffix)
|
|
||||||
# ensure that we do not use disallowed characters in image name
|
# ensure that we do not use disallowed characters in image name
|
||||||
image_name = image_name.lower()
|
image_name = image_name.lower()
|
||||||
image_name = image_name.replace(".", "-")
|
image_name = image_name.replace(".", "-")
|
||||||
|
@ -30,8 +22,11 @@ class CreateTarball(Task):
|
||||||
tarball_path = os.path.join(info.manifest.bootstrapper['workspace'], tarball_name)
|
tarball_path = os.path.join(info.manifest.bootstrapper['workspace'], tarball_name)
|
||||||
info._gce['tarball_name'] = tarball_name
|
info._gce['tarball_name'] = tarball_name
|
||||||
info._gce['tarball_path'] = tarball_path
|
info._gce['tarball_path'] = tarball_path
|
||||||
|
# GCE requires that the file in the tar be named disk.raw, hence the transform
|
||||||
log_check_call(['tar', '--sparse', '-C', info.manifest.bootstrapper['workspace'],
|
log_check_call(['tar', '--sparse', '-C', info.manifest.bootstrapper['workspace'],
|
||||||
'-caf', tarball_path, filename])
|
'-caf', tarball_path,
|
||||||
|
'--transform=s|.*|disk.raw|',
|
||||||
|
filename])
|
||||||
|
|
||||||
|
|
||||||
class UploadImage(Task):
|
class UploadImage(Task):
|
||||||
|
@ -55,7 +50,8 @@ class RegisterImage(Task):
|
||||||
image_description = info._gce['lsb_description']
|
image_description = info._gce['lsb_description']
|
||||||
if 'description' in info.manifest.provider:
|
if 'description' in info.manifest.provider:
|
||||||
image_description = info.manifest.provider['description']
|
image_description = info.manifest.provider['description']
|
||||||
|
image_description = image_description.format(**info.manifest_vars)
|
||||||
log_check_call(['gcloud', 'compute', '--project=' + info.manifest.provider['gce_project'],
|
log_check_call(['gcloud', 'compute', '--project=' + info.manifest.provider['gce_project'],
|
||||||
'image', 'create', info._gce['image_name'], '--source-uri=',
|
'images', 'create', info._gce['image_name'],
|
||||||
info.manifest.provider['gcs_destination'] + info._gce['tarball_name'],
|
'--source-uri=' + info.manifest.provider['gcs_destination'] + info._gce['tarball_name'],
|
||||||
'--description=' + image_description])
|
'--description=' + image_description])
|
||||||
|
|
Loading…
Add table
Reference in a new issue