diff --git a/share/oneprovision/ansible/onprem.yml b/share/oneprovision/ansible/onprem.yml new file mode 100644 index 0000000000..71b665ae86 --- /dev/null +++ b/share/oneprovision/ansible/onprem.yml @@ -0,0 +1,22 @@ +--- + +- hosts: all + gather_facts: false + roles: + - python + +- hosts: nodes + roles: + - ddc + - opennebula-repository + - { role: opennebula-node-kvm, when: oneprovision_hypervisor == 'kvm' } + - { role: opennebula-node-firecracker, when: oneprovision_hypervisor == 'firecracker' } + - { role: opennebula-node-lxc, when: oneprovision_hypervisor == 'lxc' } + - opennebula-ssh + - update-replica + - role: frr + #bond0_0 is attached to the project private network + frr_iface: '{{ oneprovision_private_phydev }}' + # Use /25 for the internal management network address + frr_prefix_length: 25 + diff --git a/share/oneprovision/edge-clusters/onprem/description.md b/share/oneprovision/edge-clusters/onprem/description.md new file mode 100644 index 0000000000..327be1625d --- /dev/null +++ b/share/oneprovision/edge-clusters/onprem/description.md @@ -0,0 +1 @@ +The onprem provision uses on premises infrastructure to build an **edge cluster**. This provision is useful for automate the datacenter configuration and operation. diff --git a/share/oneprovision/edge-clusters/onprem/providers/onprem/onprem.yml b/share/oneprovision/edge-clusters/onprem/providers/onprem/onprem.yml new file mode 100644 index 0000000000..4a11346d99 --- /dev/null +++ b/share/oneprovision/edge-clusters/onprem/providers/onprem/onprem.yml @@ -0,0 +1,8 @@ +name: 'onprem' + +description: 'On Premises datacenter infrastructure' +provider: 'dummy' + +plain: + image: 'ON-PREMISE' + provision_type: 'onprem' diff --git a/share/oneprovision/edge-clusters/onprem/provisions/onprem.d/datastores.yml b/share/oneprovision/edge-clusters/onprem/provisions/onprem.d/datastores.yml new file mode 100644 index 0000000000..78bb9bf37f --- /dev/null +++ b/share/oneprovision/edge-clusters/onprem/provisions/onprem.d/datastores.yml @@ -0,0 +1,39 @@ +--- +# ---------------------------------------------------------------------------- # +# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +# ---------------------------------------------------------------------------- # + +#------------------------------------------------------------------------------- +# datastores: Defines the storage area for the cluster using the SSH replication +# drivers. It creates the following datastores, using Replica driver: +# 1. Image datastore, ${cluster_name}-image +# 2. System datastore, ${cluster_name}-system +# +# Configuration/Input attributes: +# - replica_host: The host that will hold the cluster replicas and snapshots. +#------------------------------------------------------------------------------- +datastores: + + - name: "${provision}-image" + type: 'image_ds' + ds_mad: 'fs' + tm_mad: 'ssh' + safe_dirs: "/var/tmp /tmp" + + - name: "${provision}-system" + type: 'system_ds' + tm_mad: 'ssh' + safe_dirs: "/var/tmp /tmp" + replica_host: "use-first-host" diff --git a/share/oneprovision/edge-clusters/onprem/provisions/onprem.d/defaults.yml b/share/oneprovision/edge-clusters/onprem/provisions/onprem.d/defaults.yml new file mode 100644 index 0000000000..09dcb80fcb --- /dev/null +++ b/share/oneprovision/edge-clusters/onprem/provisions/onprem.d/defaults.yml @@ -0,0 +1,31 @@ +--- +# ---------------------------------------------------------------------------- # +# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +# ---------------------------------------------------------------------------- # + +#------------------------------------------------------------------------------- +# defaults: Common configuration attributes for provision objects +#-------------------------------------------------------------------------------- + +defaults: + configuration: + # Select the hypervisor package to install + oneprovision_hypervisor: "${input.one_hypervisor}" + + # required for copying recovery VM snapshots to the replica host + opennebula_ssh_deploy_private_key: true + + # Select the physical device for private network (VXLAN) + oneprovision_private_phydev: "${input.private_phydev}" diff --git a/share/oneprovision/edge-clusters/onprem/provisions/onprem.d/fireedge.yml b/share/oneprovision/edge-clusters/onprem/provisions/onprem.d/fireedge.yml new file mode 100644 index 0000000000..09f8de6e6e --- /dev/null +++ b/share/oneprovision/edge-clusters/onprem/provisions/onprem.d/fireedge.yml @@ -0,0 +1,20 @@ +--- +# ---------------------------------------------------------------------------- # +# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +# ---------------------------------------------------------------------------- # + +image: 'OPENNEBULA-ON-PREM' +provider: 'dummy' +provision_type: 'onprem' diff --git a/share/oneprovision/edge-clusters/onprem/provisions/onprem.d/hosts.yml b/share/oneprovision/edge-clusters/onprem/provisions/onprem.d/hosts.yml new file mode 100644 index 0000000000..a1e4946b94 --- /dev/null +++ b/share/oneprovision/edge-clusters/onprem/provisions/onprem.d/hosts.yml @@ -0,0 +1,34 @@ +--- +# ---------------------------------------------------------------------------- # +# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +# ---------------------------------------------------------------------------- # + +#------------------------------------------------------------------------------- +# hosts: Packet or AWS metal servers +# provision: +# - count: Number of servers to create +# - hostname: kvm-host1, kvm-host2 .... of the server +# +# You can define specific OpenNebula configuration attributes for all the hosts: +# - reserved_cpu: In percentage. It will be subtracted from the TOTAL CPU +# - reserved_memory: In percentage. It will be subtracted from the TOTAL MEM +#------------------------------------------------------------------------------- +hosts: + + - im_mad: "${input.one_hypervisor}" + vm_mad: "${input.one_hypervisor}" + provision: + hostname: "${input.hosts_names}" +... diff --git a/share/oneprovision/edge-clusters/onprem/provisions/onprem.d/inputs.yml b/share/oneprovision/edge-clusters/onprem/provisions/onprem.d/inputs.yml new file mode 100644 index 0000000000..343382a21a --- /dev/null +++ b/share/oneprovision/edge-clusters/onprem/provisions/onprem.d/inputs.yml @@ -0,0 +1,57 @@ +--- +# ---------------------------------------------------------------------------- # +# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +# ---------------------------------------------------------------------------- # + +inputs: + - name: 'hosts_names' + type: array + description: 'Comma separated list of FQDNs or IP addresses of the hosts to be added to the cluster' + + - name: 'one_hypervisor' + type: list + description: "Virtualization technology for the cluster hosts" + options: + - 'kvm' + - 'lxc' + - 'firecracker' + + - name: 'dns' + type: text + description: 'Comma separated list of DNS servers for public network' + default: '1.1.1.1' + + - name: 'public_network_bridge' + type: text + description: 'Name of the bridge to be created by OpenNebula for public networking.' + + - name: 'first_public_ip' + type: text + description: 'First public IP for the public IPs address range.' + + - name: 'number_public_ips' + type: text + description: 'Number of public IPs to get' + default: '1' + + - name: 'public_phydev' + type: text + description: 'Physical device to be used for public networking.' + + - name: 'private_phydev' + type: text + description: 'Physical device to be used for private networking.' + +... \ No newline at end of file diff --git a/share/oneprovision/edge-clusters/onprem/provisions/onprem.d/networks.yml b/share/oneprovision/edge-clusters/onprem/provisions/onprem.d/networks.yml new file mode 100644 index 0000000000..7fd4935e1c --- /dev/null +++ b/share/oneprovision/edge-clusters/onprem/provisions/onprem.d/networks.yml @@ -0,0 +1,39 @@ +--- +# ---------------------------------------------------------------------------- # +# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +# ---------------------------------------------------------------------------- # + +networks: + - name: "${provision}-public" + vn_mad: 'bridge' + phydev: "${input.public_phydev}" + bridge: '${input.public_network_bridge}' + netrole: 'public' + dns: "${input.dns}" + ar: + - type: IP4 + ip: "${input.first_public_ip}" + size: "${input.number_public_ips}" + +vntemplates: + - name: "${provision}-private" + vn_mad: 'vxlan' + phydev: "${input.private_phydev}" + automatic_vlan_id: 'yes' + netrole: 'private' + vxlan_mode: 'evpn' + vxlan_tep: 'dev' + ip_link_conf: 'nolearning=' + cluster_ids: "${cluster.0.id}" \ No newline at end of file diff --git a/share/oneprovision/edge-clusters/onprem/provisions/onprem.d/resources.yml b/share/oneprovision/edge-clusters/onprem/provisions/onprem.d/resources.yml new file mode 100644 index 0000000000..f79444a509 --- /dev/null +++ b/share/oneprovision/edge-clusters/onprem/provisions/onprem.d/resources.yml @@ -0,0 +1,31 @@ +--- +# ---------------------------------------------------------------------------- # +# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +# ---------------------------------------------------------------------------- # + +#------------------------------------------------------------------------------- +# Use this file to define custom resources associated to the cluster, example: +# - images +# - marketplaceapps +# - templates +# - vntemplates +# - flowtemplates +# +# Cross-references to other objects can be made: +# - by name, eg. ${datastore.images.id} to get the OpenNebula ID of the +# datastore with name "images" +# - by index, eg. ${datastore.0.id} to get the OpenNebula ID of the **first** +# datastore defined in the provision +#------------------------------------------------------------------------------- diff --git a/share/oneprovision/edge-clusters/onprem/provisions/onprem.yml b/share/oneprovision/edge-clusters/onprem/provisions/onprem.yml new file mode 100644 index 0000000000..a866baaa02 --- /dev/null +++ b/share/oneprovision/edge-clusters/onprem/provisions/onprem.yml @@ -0,0 +1,66 @@ +--- +# ---------------------------------------------------------------------------- # +# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +# ---------------------------------------------------------------------------- # + +#------------------------------------------------------------------------------- +# This is the canonical description file for a cluster build On-Premise +# ------------------------------------------------------------------------------ + +name: 'onprem-cluster' + +extends: + - onprem.d/defaults.yml + - onprem.d/resources.yml + - onprem.d/hosts.yml + - onprem.d/datastores.yml + - onprem.d/fireedge.yml + - onprem.d/inputs.yml + - onprem.d/networks.yml + +#------------------------------------------------------------------------------- +# playbook: Ansible playbook used for hosts configuration. Check ansible/aws.yml +# for the specific roles applied. +#------------------------------------------------------------------------------- +playbook: + - onprem + +#------------------------------------------------------------------------------- +# defaults: Common configuration attributes for provision objects +#-------------------------------------------------------------------------------- +defaults: + provision: + provider_name: 'onprem' + connection: + remote_user: 'root' + +#------------------------------------------------------------------------------- +# cluster: Parameters for the OpenNebula cluster. Applies to all the Hosts +#-------------------------------------------------------------------------------- +# name: of the cluster +# description: Additional information +# reserved_cpu: In percentage. It will be subtracted from the TOTAL CPU +# reserved_memory: In percentage. It will be subtracted from the TOTAL MEM +#-------------------------------------------------------------------------------- +cluster: + name: "${provision}" + description: 'On-Premise edge cluster' + reserved_cpu: '0' + reserved_mem: '0' + datastores: + - 1 + - 2 + +... diff --git a/src/cli/one_helper/oneprovider_helper.rb b/src/cli/one_helper/oneprovider_helper.rb index 0ba442297b..255b9f548d 100644 --- a/src/cli/one_helper/oneprovider_helper.rb +++ b/src/cli/one_helper/oneprovider_helper.rb @@ -102,6 +102,8 @@ class OneProviderHelper < OpenNebulaHelper::OneHelper puts format('ID : %s', :s => id) puts format('NAME : %s', :s => provider['NAME']) + return if body['provider'] == 'dummy' + # Get max size to adjust all the values size = body['connection'].keys.map {|k| k.size }.max data = {} @@ -176,7 +178,6 @@ class OneProviderHelper < OpenNebulaHelper::OneHelper template = YAML.load_file(template) raise 'Name not found' unless template['name'] - raise 'Connection info not found' unless template['connection'] unless OneProvision::Terraform::PROVIDERS.include?( template['provider'] @@ -185,6 +186,10 @@ class OneProviderHelper < OpenNebulaHelper::OneHelper "#{OneProvision::Terraform::PROVIDERS.join(', ')}" end + return template if template['provider'] == 'dummy' + + raise 'Connection info not found' unless template['connection'] + template rescue StandardError => e OpenNebula::Error.new("ERROR: #{e}") diff --git a/src/cli/oneprovision b/src/cli/oneprovision index 417805cc8c..ea8e5526da 100755 --- a/src/cli/oneprovision +++ b/src/cli/oneprovision @@ -129,8 +129,6 @@ CommandParser::CmdParser.new(ARGV) do STDERR.puts rc.message exit(-1) elsif rc.to_i < 0 - puts CLIHelper.green('Provision successfully created') - puts "ID: #{rc}" rc else puts CLIHelper.green('Provision successfully created') diff --git a/src/oneprovision/lib/provider/provider.rb b/src/oneprovision/lib/provider/provider.rb index 6820c1f880..16093fbf3f 100644 --- a/src/oneprovision/lib/provider/provider.rb +++ b/src/oneprovision/lib/provider/provider.rb @@ -148,8 +148,6 @@ module OneProvision # # @return [Provider] def self.by_name(client, provider) - return Provider.new_with_id(-1) if provider == 'dummy' - if provider.to_s.match(/^[0123456789]+$/) provider = Provider.new_with_id(Integer(provider), client) rc = provider.info(true) diff --git a/src/oneprovision/lib/terraform/providers/dummy.rb b/src/oneprovision/lib/terraform/providers/dummy.rb index 4066a08f24..cfad78e013 100644 --- a/src/oneprovision/lib/terraform/providers/dummy.rb +++ b/src/oneprovision/lib/terraform/providers/dummy.rb @@ -30,6 +30,8 @@ module OneProvision end def deploy(_) + OneProvisionLogger.info('(Deploy skipped)') + [@hosts.map do |h| h.to_hash['HOST']['TEMPLATE']['PROVISION']['HOSTNAME'] end, @@ -51,12 +53,34 @@ module OneProvision # @return [Array] # - Terraform state in base64 # - Terraform config in base64 - def destroy(_ = nil) end + def destroy(_ = nil) + OneProvisionLogger.info('(Destroy skipped)') + end # Destroys a host # # @param host [String] Host ID - def destroy_host(_) end + def destroy_host(_) + OneProvisionLogger.info('(Destroy host skipped)') + end + + def destroy_cluster(_) + OneProvisionLogger.info('(Destroy cluster skipped)') + end + + # Destroys a datastore + # + # @param id [String] Datastore ID + def destroy_datastore(_) + OneProvisionLogger.info('(Destroy datastore skipped)') + end + + # Destriys a network + # + # @param id [String] Network ID + def destroy_network(_) + OneProvisionLogger.info('(Destroy network skipped)') + end end diff --git a/src/oneprovision/lib/terraform/terraform.rb b/src/oneprovision/lib/terraform/terraform.rb index 649413d4ee..2bb75e3f67 100644 --- a/src/oneprovision/lib/terraform/terraform.rb +++ b/src/oneprovision/lib/terraform/terraform.rb @@ -46,7 +46,7 @@ module OneProvision class Terraform # Providers that are currently available - PROVIDERS = %w[aws packet] + PROVIDERS = %w[aws packet dummy] # Class constructor # @@ -66,13 +66,13 @@ module OneProvision # # @return [Terraform] Terraform provider def self.singleton(provider, tf) - return Dummy.new if Integer(provider['ID']) == -1 - case provider.body['provider'] when 'packet' tf_class = Packet when 'aws' tf_class = AWS + when 'dummy' + tf_class = Dummy else raise OneProvisionLoopException, "Unknown provider: #{provider.body['provider']}" @@ -91,6 +91,8 @@ module OneProvision keys = Packet::KEYS when 'aws' keys = AWS::KEYS + when 'dummy' + return true else raise OneProvisionLoopException, "Unknown provider: #{provider['provider']}"