ystia / yorc

Ystia Orchestrator
https://ystia.github.io
Apache License 2.0
67 stars 23 forks source link

Feature/gh 687 openstack compute metadata #694

Closed laurentganne closed 4 years ago

laurentganne commented 4 years ago

Pull Request description

Description of the change

The OpenStack API provides a Compute Instance property metadata allowing a user to define key/value pairs at instance creation, and these key/value pairs will then be available from within the instance. Added the corresponding property in Yorc TOSCA type for OpenStack compute instances.

What I did

data/tosca/yorc-openstack-types.yml Added the property metdata to the TOSCA type yorc.nodes.openstack.Compute

prov/terraform/openstack/osinstance.go Getting the compute instance metadata value from the topology

prov/terraform/openstack/osinstance_test.go Added a test on this new property

prov/terraform/openstack/resources.go Added a field Metadata to the golang type used for an OpenStack Compute instance

prov/terraform/openstack/testdata/simpleOSInstance.yaml Added the new property in a topoly used in tests

How to verify it

Bootstrap a setup on OpenStack using an inputs file specifying a download URL of a Yorc distribution with this pull request code, and using a yorc_plugin download URL of an alien4cloud-yorc-provder containing the code from pull request https://github.com/alien4cloud/alien4cloud-yorc-provider/pull/23

Then, from Alien4Cloud,edit the OpenStack on-demand compute instance property metadata to add this key/value pair:

Then upload in Alien4Cloud catalog this application template: that will define 2 key/value pairs in the metadata:

tosca_definitions_version: alien_dsl_2_0_0

metadata:
  template_name: TestMetadata
  template_version: 0.1.0-SNAPSHOT
  template_author: ystia

description: ""

imports:
  - tosca-normative-types:1.0.0-ALIEN20

topology_template:
  inputs:
    vm_metadata:
      type: map
      entry_schema:
        type: string
      default: {"firstKey": "firstValue", "secondKey": "secondValue"}
      required: false
  node_templates:
    Network:
      type: tosca.nodes.Network
      properties:
        ip_version: 4
    TestMetadata:
      type: tosca.nodes.Compute
      requirements:
        - networkNetworkConnection:
            type_requirement: network
            node: Network
            capability: tosca.capabilities.Connectivity
            relationship: tosca.relationships.Network
      capabilities:
        scalable:
          properties:
            min_instances: 1
            max_instances: 1
            default_instances: 1
        endpoint:
          properties:
            secure: true
            protocol: tcp
            network_name: PRIVATE
            initiator: source

Create an application from this template and deploy it on OpenStack. Once the application is deployed, you can either use the OpenStack console, select the created compute instance and check the metadata, or you can login on the compute instance, and run the follwing commands.

First run this command to get the list of openstack metata API supported versions:

$ curl http://169.254.169.254/openstack
2012-08-10
2013-04-04
2013-10-17
2015-10-15
2016-06-30
2016-10-06
2017-02-22

Then get the metadata using the latest API version, and format the output

$ curl http://169.254.169.254/openstack/2017-02-22/meta_data.json | python -m json.tool
...
    "launch_index": 0,
    "meta": {
        "firstKey": "firstValue",
        "secondKey": "secondValue"
    },
    "name": "yorc-TestMetadata-0",
...

Check the meta section provide the key/pair values that we had specified in the application template.

Description for the changelog

Add the ability to define OpenStack Compute Instance metadata (GH-687)

Applicable Issues

Closes #687

codeclimate[bot] commented 4 years ago

Code Climate has analyzed commit 6a5120a2 and detected 2 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 2

View more on Code Climate.

sonarcloud[bot] commented 4 years ago

SonarCloud Quality Gate failed.

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 1 Code Smell

62.5% 62.5% Coverage
0.0% 0.0% Duplication

warning The version of Java (1.8.0_151) you have used to run this analysis is deprecated and we will stop accepting it from October 2020. Please update to at least Java 11. Read more here