Skip to content

Commit 3e3bdd4

Browse files
authored
Merge pull request #2 from QualiSystemsLab/feature/private_image
added support for private images
2 parents a3dfdc9 + 856c6bb commit 3e3bdd4

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

deployments/deploy-instance-deployment-path.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ node_types:
2828
description: 'The id of the image to be used for deploying the app.'
2929
default: ''
3030
tags: [user_input] # editable_only_in_app_template
31+
Image Source:
32+
type: string
33+
description: "The source of the image. Supported values: 'public' or 'private'. Use 'image' for private source not 'machine image'"
34+
default: 'public'
35+
tags: [ user_input ]
36+
constraints:
37+
- valid_values: [ public, private ]
3138
Machine Type:
3239
type: string
3340
description: 'The size of the instance. Can be one of the pre-defined ones or a custom one.'

shell-definition.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ tosca_definitions_version: tosca_simple_yaml_1_0
33
metadata:
44
template_name: Google Cloud Provider
55
template_author: yaniv.k
6-
template_version: 0.9.8
6+
template_version: 0.9.9
77
template_icon: shell-icon.png
88

99
description: >

src/ccp/gcp/gcp_service.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,10 @@ def deploy_instance(self, context, cloudshell_session, cloud_provider_resource,
214214
deployment_model_attributes[deployment_path + '.Machine Type'],
215215
deployment_model_attributes[deployment_path + '.Disk Type'],
216216
deployment_model_attributes[deployment_path + '.Disk Size'],
217-
network_data)
217+
network_data,
218+
image_source_type=deployment_model_attributes[deployment_path + '.Image Source'])
218219
except Exception as e:
220+
self.logger.exception("==>")
219221
return DeployAppResult(actionId=deploy_app_action.actionId, success=False, errorMessage=e.message)
220222

221223
connect_subnet_results = []
@@ -289,9 +291,9 @@ def deploy_instance_from_template(self, context, cloudshell_session, cloud_provi
289291
self.logger.error(ex.message)
290292
raise ex
291293

292-
293294
def _create_instance(self, actionId, cloud_provider_resource, vm_unique_name, image_project, image_id, machine_type,
294-
disk_type, disk_size, network_data, input_user='', decrypted_input_password=''):
295+
disk_type, disk_size, network_data, input_user='', decrypted_input_password='',
296+
image_source_type='public'):
295297

296298
client = self._get_client()
297299

@@ -302,6 +304,8 @@ def _create_instance(self, actionId, cloud_provider_resource, vm_unique_name, im
302304

303305
diskType = disk_type.lower()
304306

307+
source_image_uri = self._prepare_source_image(image_id, image_project, image_source_type)
308+
305309
instance_body = {
306310
"kind": "compute#instance",
307311
"name": vm_unique_name,
@@ -326,7 +330,7 @@ def _create_instance(self, actionId, cloud_provider_resource, vm_unique_name, im
326330
"autoDelete": True,
327331
"deviceName": "instance-1",
328332
"initializeParams": {
329-
"sourceImage": "projects/{}/global/images/{}".format(image_project, image_id),
333+
"sourceImage": source_image_uri,
330334
"diskType": "projects/{}/zones/{}/diskTypes/pd-{}".format(self.project, zone, diskType),
331335
"diskSizeGb": disk_size
332336
}
@@ -359,7 +363,7 @@ def _create_instance(self, actionId, cloud_provider_resource, vm_unique_name, im
359363
"deletionProtection": False
360364
}
361365

362-
self.logger.debug("instance_body: " + str(instance_body))
366+
self.logger.info("instance_body: " + str(instance_body))
363367

364368
request = client.instances().insert(project=self.project, zone=zone, body=instance_body)
365369
response = request.execute()
@@ -374,6 +378,17 @@ def _create_instance(self, actionId, cloud_provider_resource, vm_unique_name, im
374378
deployedAppAddress=vm_details_data.vmNetworkData[0].privateIpAddress,
375379
vmDetailsData=vm_details_data)
376380

381+
def _prepare_source_image(self, image_id, image_project, image_source_type):
382+
source_image_uri = ""
383+
if image_source_type == "public":
384+
source_image_uri = "projects/{}/global/images/{}".format(image_project, image_id)
385+
elif image_source_type == "private":
386+
source_image_uri = "global/images/{}".format(image_id)
387+
else:
388+
raise ValueError("Unsupported image source {}".format(image_source_type))
389+
390+
return source_image_uri
391+
377392
def _create_instance_from_template(self, actionId, cloud_provider_resource, vm_unique_name, template_name,
378393
network_data, input_user='', decrypted_input_password=''):
379394

0 commit comments

Comments
 (0)