mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Merge pull request #44844 from gtmanfred/shade
Rewrite openstack driver to use shade
This commit is contained in:
commit
37eb35a84b
@ -1,10 +0,0 @@
|
||||
#my-openstack-hp-config:
|
||||
# driver: openstack
|
||||
# identity_url: 'https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/'
|
||||
# compute_name: Compute
|
||||
# compute_region: 'az-1.region-a.geo-1'
|
||||
# tenant: myuser-tenant1
|
||||
# user: myuser
|
||||
# ssh_key_name: mykey
|
||||
# ssh_key_file: '/etc/salt/hpcloud/mykey.pem'
|
||||
# password: mypass
|
@ -1,10 +0,0 @@
|
||||
#my-openstack-rackspace-config:
|
||||
# driver: openstack
|
||||
# identity_url: 'https://identity.api.rackspacecloud.com/v2.0/tokens'
|
||||
# compute_name: cloudServersOpenStack
|
||||
# protocol: ipv4
|
||||
# compute_region: DFW
|
||||
# protocol: ipv4
|
||||
# user: myuser
|
||||
# tenant: 5555555
|
||||
# apikey: 901d3f579h23c8v73q9
|
@ -3,4 +3,4 @@ salt.cloud.clouds.openstack
|
||||
===========================
|
||||
|
||||
.. automodule:: salt.cloud.clouds.openstack
|
||||
:members:
|
||||
:members:
|
||||
|
@ -184,37 +184,18 @@ minion. In your pillar file, you would use something like this:
|
||||
ssh_key_file: /root/.ssh/id_rsa
|
||||
update_cachedir: True
|
||||
diff_cache_events: True
|
||||
change_password: True
|
||||
|
||||
providers:
|
||||
my-nova:
|
||||
identity_url: https://identity.api.rackspacecloud.com/v2.0/
|
||||
compute_region: IAD
|
||||
user: myuser
|
||||
api_key: apikey
|
||||
tenant: 123456
|
||||
driver: nova
|
||||
|
||||
my-openstack:
|
||||
identity_url: https://identity.api.rackspacecloud.com/v2.0/tokens
|
||||
user: user2
|
||||
apikey: apikey2
|
||||
tenant: 654321
|
||||
compute_region: DFW
|
||||
driver: openstack
|
||||
compute_name: cloudServersOpenStack
|
||||
region_name: ORD
|
||||
cloud: mycloud
|
||||
|
||||
profiles:
|
||||
ubuntu-nova:
|
||||
provider: my-nova
|
||||
size: performance1-8
|
||||
image: bb02b1a3-bc77-4d17-ab5b-421d89850fca
|
||||
script_args: git develop
|
||||
|
||||
ubuntu-openstack:
|
||||
provider: my-openstack
|
||||
size: performance1-8
|
||||
image: bb02b1a3-bc77-4d17-ab5b-421d89850fca
|
||||
size: ds512M
|
||||
image: CentOS 7
|
||||
script_args: git develop
|
||||
|
||||
|
||||
@ -363,76 +344,7 @@ be set in the configuration file to enable interfacing with GoGrid:
|
||||
OpenStack
|
||||
---------
|
||||
|
||||
OpenStack configuration differs between providers, and at the moment several
|
||||
options need to be specified. This module has been officially tested against
|
||||
the HP and the Rackspace implementations, and some examples are provided for
|
||||
both.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
# For HP
|
||||
my-openstack-hp-config:
|
||||
identity_url:
|
||||
'https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/'
|
||||
compute_name: Compute
|
||||
compute_region: 'az-1.region-a.geo-1'
|
||||
tenant: myuser-tenant1
|
||||
user: myuser
|
||||
ssh_key_name: mykey
|
||||
ssh_key_file: '/etc/salt/hpcloud/mykey.pem'
|
||||
password: mypass
|
||||
driver: openstack
|
||||
|
||||
# For Rackspace
|
||||
my-openstack-rackspace-config:
|
||||
identity_url: 'https://identity.api.rackspacecloud.com/v2.0/tokens'
|
||||
compute_name: cloudServersOpenStack
|
||||
protocol: ipv4
|
||||
compute_region: DFW
|
||||
user: myuser
|
||||
tenant: 5555555
|
||||
password: mypass
|
||||
driver: openstack
|
||||
|
||||
|
||||
If you have an API key for your provider, it may be specified instead of a
|
||||
password:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
my-openstack-hp-config:
|
||||
apikey: 901d3f579h23c8v73q9
|
||||
|
||||
my-openstack-rackspace-config:
|
||||
apikey: 901d3f579h23c8v73q9
|
||||
|
||||
.. note::
|
||||
|
||||
In the cloud profile that uses this provider configuration, the syntax for the
|
||||
``provider`` required field would be either ``provider: my-openstack-hp-config``
|
||||
or ``provider: my-openstack-rackspace-config``.
|
||||
|
||||
You will certainly need to configure the ``user``, ``tenant``, and either
|
||||
``password`` or ``apikey``.
|
||||
|
||||
If your OpenStack instances only have private IP addresses and a CIDR range of
|
||||
private addresses are not reachable from the salt-master, you may set your
|
||||
preference to have Salt ignore it:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
my-openstack-config:
|
||||
ignore_cidr: 192.168.0.0/16
|
||||
|
||||
For in-house OpenStack Essex installation, libcloud needs the service_type :
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
my-openstack-config:
|
||||
identity_url: 'http://control.openstack.example.org:5000/v2.0/'
|
||||
compute_name : Compute Service
|
||||
service_type : compute
|
||||
|
||||
.. automodule:: salt.cloud.clouds.openstack
|
||||
|
||||
DigitalOcean
|
||||
------------
|
||||
|
@ -1,185 +0,0 @@
|
||||
==============================
|
||||
Getting Started With OpenStack
|
||||
==============================
|
||||
|
||||
OpenStack is one the most popular cloud projects. It's an open source project
|
||||
to build public and/or private clouds. You can use Salt Cloud to launch
|
||||
OpenStack instances.
|
||||
|
||||
|
||||
Dependencies
|
||||
============
|
||||
* Libcloud >= 0.13.2
|
||||
|
||||
|
||||
Configuration
|
||||
=============
|
||||
* Using the new format, set up the cloud configuration at
|
||||
``/etc/salt/cloud.providers`` or
|
||||
``/etc/salt/cloud.providers.d/openstack.conf``:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
my-openstack-config:
|
||||
# Set the location of the salt-master
|
||||
#
|
||||
minion:
|
||||
master: saltmaster.example.com
|
||||
|
||||
# Configure the OpenStack driver
|
||||
#
|
||||
identity_url: http://identity.youopenstack.com/v2.0/tokens
|
||||
compute_name: nova
|
||||
protocol: ipv4
|
||||
|
||||
compute_region: RegionOne
|
||||
|
||||
# Configure Openstack authentication credentials
|
||||
#
|
||||
user: myname
|
||||
password: 123456
|
||||
# tenant is the project name
|
||||
tenant: myproject
|
||||
|
||||
driver: openstack
|
||||
|
||||
# skip SSL certificate validation (default false)
|
||||
insecure: false
|
||||
|
||||
.. note::
|
||||
.. versionchanged:: 2015.8.0
|
||||
|
||||
The ``provider`` parameter in cloud provider definitions was renamed to ``driver``. This
|
||||
change was made to avoid confusion with the ``provider`` parameter that is used in cloud profile
|
||||
definitions. Cloud provider definitions now use ``driver`` to refer to the Salt cloud module that
|
||||
provides the underlying functionality to connect to a cloud host, while cloud profiles continue
|
||||
to use ``provider`` to refer to provider configurations that you define.
|
||||
|
||||
Using nova client to get information from OpenStack
|
||||
===================================================
|
||||
|
||||
One of the best ways to get information about OpenStack is using the novaclient
|
||||
python package (available in pypi as python-novaclient). The client
|
||||
configuration is a set of environment variables that you can get from the
|
||||
Dashboard. Log in and then go to Project -> Access & security -> API Access and
|
||||
download the "OpenStack RC file". Then:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
source /path/to/your/rcfile
|
||||
nova credentials
|
||||
nova endpoints
|
||||
|
||||
In the ``nova endpoints`` output you can see the information about
|
||||
``compute_region`` and ``compute_name``.
|
||||
|
||||
|
||||
Compute Region
|
||||
==============
|
||||
|
||||
It depends on the OpenStack cluster that you are using. Please, have a look at
|
||||
the previous sections.
|
||||
|
||||
|
||||
Authentication
|
||||
==============
|
||||
|
||||
The ``user`` and ``password`` is the same user as is used to log into the
|
||||
OpenStack Dashboard.
|
||||
|
||||
|
||||
Profiles
|
||||
========
|
||||
|
||||
Here is an example of a profile:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
openstack_512:
|
||||
provider: my-openstack-config
|
||||
size: m1.tiny
|
||||
image: cirros-0.3.1-x86_64-uec
|
||||
ssh_key_file: /tmp/test.pem
|
||||
ssh_key_name: test
|
||||
ssh_interface: private_ips
|
||||
|
||||
The following list explains some of the important properties.
|
||||
|
||||
|
||||
size
|
||||
can be one of the options listed in the output of ``nova flavor-list``.
|
||||
|
||||
image
|
||||
can be one of the options listed in the output of ``nova image-list``.
|
||||
|
||||
ssh_key_file
|
||||
The SSH private key that the salt-cloud uses to SSH into the VM after its
|
||||
first booted in order to execute a command or script. This private key's
|
||||
*public key* must be the openstack public key inserted into the
|
||||
authorized_key's file of the VM's root user account.
|
||||
|
||||
ssh_key_name
|
||||
The name of the openstack SSH public key that is inserted into the
|
||||
authorized_keys file of the VM's root user account. Prior to using this
|
||||
public key, you must use openstack commands or the horizon web UI to load
|
||||
that key into the tenant's account. Note that this openstack tenant must be
|
||||
the one you defined in the cloud provider.
|
||||
|
||||
ssh_interface
|
||||
This option allows you to create a VM without a public IP. If this option
|
||||
is omitted and the VM does not have a public IP, then the salt-cloud waits
|
||||
for a certain period of time and then destroys the VM. With the nova drive,
|
||||
private cloud networks can be defined here.
|
||||
|
||||
For more information concerning cloud profiles, see :ref:`here
|
||||
<salt-cloud-profiles>`.
|
||||
|
||||
|
||||
change_password
|
||||
~~~~~~~~~~~~~~~
|
||||
If no ssh_key_file is provided, and the server already exists, change_password
|
||||
will use the api to change the root password of the server so that it can be
|
||||
bootstrapped.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
change_password: True
|
||||
|
||||
|
||||
userdata_file
|
||||
~~~~~~~~~~~~~
|
||||
Use `userdata_file` to specify the userdata file to upload for use with
|
||||
cloud-init if available.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
my-openstack-config:
|
||||
# Pass userdata to the instance to be created
|
||||
userdata_file: /etc/salt/cloud-init/packages.yml
|
||||
|
||||
.. note::
|
||||
As of the 2016.11.4 release, this file can be templated. To use templating,
|
||||
simply specify a ``userdata_template`` option in the cloud profile:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
my-openstack-config:
|
||||
# Pass userdata to the instance to be created
|
||||
userdata_file: /etc/salt/cloud-init/packages.yml
|
||||
userdata_template: jinja
|
||||
|
||||
If no ``userdata_template`` is set in the cloud profile, then the master
|
||||
configuration will be checked for a :conf_master:`userdata_template` value.
|
||||
If this is not set, then no templating will be performed on the
|
||||
userdata_file.
|
||||
|
||||
To disable templating in a cloud profile when a
|
||||
:conf_master:`userdata_template` has been set in the master configuration
|
||||
file, simply set ``userdata_template`` to ``False`` in the cloud profile:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
my-openstack-config:
|
||||
# Pass userdata to the instance to be created
|
||||
userdata_file: /etc/salt/cloud-init/packages.yml
|
||||
userdata_template: False
|
@ -666,7 +666,7 @@ class Cloud(object):
|
||||
# If driver has function list_nodes_min, just replace it
|
||||
# with query param to check existing vms on this driver
|
||||
# for minimum information, Otherwise still use query param.
|
||||
if 'selected_query_option' not in opts and '{0}.list_nodes_min'.format(driver) in self.clouds:
|
||||
if opts.get('selected_query_option') is None and '{0}.list_nodes_min'.format(driver) in self.clouds:
|
||||
this_query = 'list_nodes_min'
|
||||
|
||||
fun = '{0}.{1}'.format(driver, this_query)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -3265,7 +3265,7 @@ def get_cloud_config_value(name, vm_, opts, default=None, search_global=True):
|
||||
return value
|
||||
|
||||
|
||||
def is_provider_configured(opts, provider, required_keys=()):
|
||||
def is_provider_configured(opts, provider, required_keys=(), log_message=True):
|
||||
'''
|
||||
Check and return the first matching and fully configured cloud provider
|
||||
configuration.
|
||||
@ -3278,13 +3278,14 @@ def is_provider_configured(opts, provider, required_keys=()):
|
||||
return False
|
||||
for key in required_keys:
|
||||
if opts['providers'][alias][driver].get(key, None) is None:
|
||||
# There's at least one require configuration key which is not
|
||||
# set.
|
||||
log.warning(
|
||||
"The required '{0}' configuration setting is missing "
|
||||
"from the '{1}' driver, which is configured under the "
|
||||
"'{2}' alias.".format(key, provider, alias)
|
||||
)
|
||||
if log_message is True:
|
||||
# There's at least one require configuration key which is not
|
||||
# set.
|
||||
log.warning(
|
||||
"The required '{0}' configuration setting is missing "
|
||||
"from the '{1}' driver, which is configured under the "
|
||||
"'{2}' alias.".format(key, provider, alias)
|
||||
)
|
||||
return False
|
||||
# If we reached this far, there's a properly configured provider.
|
||||
# Return it!
|
||||
@ -3300,15 +3301,16 @@ def is_provider_configured(opts, provider, required_keys=()):
|
||||
skip_provider = False
|
||||
for key in required_keys:
|
||||
if provider_details.get(key, None) is None:
|
||||
# This provider does not include all necessary keys,
|
||||
# continue to next one.
|
||||
log.warning(
|
||||
"The required '{0}' configuration setting is "
|
||||
"missing from the '{1}' driver, which is configured "
|
||||
"under the '{2}' alias.".format(
|
||||
key, provider, alias
|
||||
if log_message is True:
|
||||
# This provider does not include all necessary keys,
|
||||
# continue to next one.
|
||||
log.warning(
|
||||
"The required '{0}' configuration setting is "
|
||||
"missing from the '{1}' driver, which is configured "
|
||||
"under the '{2}' alias.".format(
|
||||
key, provider, alias
|
||||
)
|
||||
)
|
||||
)
|
||||
skip_provider = True
|
||||
break
|
||||
|
||||
|
@ -84,12 +84,9 @@ else:
|
||||
# We list un-supported functions here. These will be removed from the loaded.
|
||||
# TODO: remove the need for this cross-module code. Maybe use NotImplemented
|
||||
LIBCLOUD_FUNCS_NOT_SUPPORTED = (
|
||||
'parallels.avail_sizes',
|
||||
'parallels.avail_locations',
|
||||
'proxmox.avail_sizes',
|
||||
'rackspace.reboot',
|
||||
'openstack.list_locations',
|
||||
'rackspace.list_locations'
|
||||
u'parallels.avail_sizes',
|
||||
u'parallels.avail_locations',
|
||||
u'proxmox.avail_sizes',
|
||||
)
|
||||
|
||||
# Will be set to pyximport module at runtime if cython is enabled in config.
|
||||
|
@ -1,44 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
:codeauthor: :email:`Bo Maryniuk <bo@suse.de>`
|
||||
'''
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from tests.support.unit import TestCase
|
||||
from tests.support.mock import MagicMock, patch
|
||||
from tests.unit.cloud.clouds import _preferred_ip
|
||||
|
||||
# Import Salt libs
|
||||
from salt.cloud.clouds import openstack
|
||||
|
||||
|
||||
class OpenstackTestCase(TestCase):
|
||||
'''
|
||||
Test case for openstack
|
||||
'''
|
||||
PRIVATE_IPS = ['0.0.0.0', '1.1.1.1', '2.2.2.2']
|
||||
|
||||
@patch('salt.cloud.clouds.openstack.show_instance',
|
||||
MagicMock(return_value={'state': True,
|
||||
'public_ips': [],
|
||||
'private_ips': PRIVATE_IPS}))
|
||||
@patch('salt.cloud.clouds.openstack.rackconnect', MagicMock(return_value=False))
|
||||
@patch('salt.cloud.clouds.openstack.managedcloud', MagicMock(return_value=False))
|
||||
@patch('salt.cloud.clouds.openstack.preferred_ip', _preferred_ip(PRIVATE_IPS, ['0.0.0.0']))
|
||||
@patch('salt.cloud.clouds.openstack.ssh_interface', MagicMock(return_value=False))
|
||||
def test_query_node_data_filter_preferred_ip_addresses(self):
|
||||
'''
|
||||
Test if query node data is filtering out unpreferred IP addresses.
|
||||
'''
|
||||
openstack.NodeState = MagicMock() # pylint: disable=blacklisted-unmocked-patching
|
||||
openstack.NodeState.RUNNING = True
|
||||
|
||||
vm = {'name': None}
|
||||
data = MagicMock()
|
||||
data.public_ips = []
|
||||
|
||||
with patch('salt.utils.cloud.is_public_ip', MagicMock(return_value=True)):
|
||||
assert openstack._query_node_data(vm, data, False, MagicMock()).public_ips == ['0.0.0.0']
|
Loading…
Reference in New Issue
Block a user