diff --git a/doc/topics/cloud/aws.rst b/doc/topics/cloud/aws.rst index fda04b2d24..da6c6fc16d 100644 --- a/doc/topics/cloud/aws.rst +++ b/doc/topics/cloud/aws.rst @@ -721,6 +721,28 @@ them have never been used, much less tested, by the Salt Stack team. .. __: https://aws.amazon.com/marketplace +NOTE: If ``image`` of a profile does not start with ``ami-``, latest +image with that name will be used. For example, to create a CentOS 7 +profile, instead of using the AMI like ``image: ami-1caef165``, we +can use its name like ``image: 'CentOS Linux 7 x86_64 HVM EBS ENA 1803_01'``. +We can also use a pattern like below to get the latest CentOS 7: + + +.. code-block:: yaml + + profile-id: + provider: provider-name + subnetid: subnet-XXXXXXXX + image: 'CentOS Linux 7 x86_64 HVM EBS *' + size: m1.medium + ssh_username: centos + securitygroupid: + - sg-XXXXXXXX + securitygroupname: + - AnotherSecurityGroup + - AndThirdSecurityGroup + + show_image ========== This is a function that describes an AMI on EC2. This will give insight as to diff --git a/salt/cloud/clouds/ec2.py b/salt/cloud/clouds/ec2.py index 0cb5e234ad..edc86dc540 100644 --- a/salt/cloud/clouds/ec2.py +++ b/salt/cloud/clouds/ec2.py @@ -1191,6 +1191,33 @@ def get_tenancy(vm_): ) +def get_imageid(vm_): + ''' + Returns the ImageId to use + ''' + image = config.get_cloud_config_value( + 'image', vm_, __opts__, search_global=False + ) + if image.startswith('ami-'): + return image + # a poor man's cache + if not hasattr(get_imageid, 'images'): + get_imageid.images = {} + elif image in get_imageid.images: + return get_imageid.images[image] + params = {'Action': 'DescribeImages', + 'Filter.0.Name': 'name', + 'Filter.0.Value.0': image} + # Query AWS, sort by 'creationDate' and get the last imageId + _t = lambda x: datetime.datetime.strptime(x['creationDate'], '%Y-%m-%dT%H:%M:%S.%fZ') + image_id = sorted(aws.query(params, location=get_location(), + provider=get_provider(), opts=__opts__, sigver='4'), + lambda i, j: cmp(_t(i), _t(j)) + )[-1]['imageId'] + get_imageid.images[image] = image_id + return image_id + + def _get_subnetname_id(subnetname): ''' Returns the SubnetId of a SubnetName to use @@ -1774,7 +1801,7 @@ def request_instance(vm_=None, call=None): # Normal instances should have no prefix. spot_prefix = '' - image_id = vm_['image'] + image_id = get_imageid(vm_) params[spot_prefix + 'ImageId'] = image_id userdata = None diff --git a/salt/engines/libvirt_events.py b/salt/engines/libvirt_events.py index ca773ef5b5..0977efc61f 100644 --- a/salt/engines/libvirt_events.py +++ b/salt/engines/libvirt_events.py @@ -214,7 +214,8 @@ def _salt_send_domain_event(opaque, conn, domain, event, event_data): data = { 'domain': { 'name': domain.name(), - 'id': domain.ID() + 'id': domain.ID(), + 'uuid': domain.UUIDString() }, 'event': event } @@ -228,7 +229,8 @@ def _domain_event_lifecycle_cb(conn, domain, event, detail, opaque): ''' event_str, detail_str = _get_domain_event_detail(event, detail) - _salt_send_domain_event(opaque, conn, domain, event_str, { + _salt_send_domain_event(opaque, conn, domain, opaque['event'], { + 'event': event_str, 'detail': detail_str }) @@ -468,7 +470,10 @@ def _network_event_lifecycle_cb(conn, net, event, detail, opaque): ''' _salt_send_event(opaque, conn, { - 'network': net.name(), + 'network': { + 'name': net.name(), + 'uuid': net.UUIDString() + }, 'event': _get_libvirt_enum_string('VIR_NETWORK_EVENT_', event), 'detail': 'unknown' # currently unused }) @@ -479,7 +484,10 @@ def _pool_event_lifecycle_cb(conn, pool, event, detail, opaque): Storage pool lifecycle events handler ''' _salt_send_event(opaque, conn, { - 'pool': pool.name(), + 'pool': { + 'name': pool.name(), + 'uuid': pool.UUIDString() + }, 'event': _get_libvirt_enum_string('VIR_STORAGE_POOL_EVENT_', event), 'detail': 'unknown' # currently unused }) @@ -490,7 +498,10 @@ def _pool_event_refresh_cb(conn, pool, opaque): Storage pool refresh events handler ''' _salt_send_event(opaque, conn, { - 'pool': pool.name(), + 'pool': { + 'name': pool.name(), + 'uuid': pool.UUIDString() + }, 'event': opaque['event'] }) @@ -500,7 +511,9 @@ def _nodedev_event_lifecycle_cb(conn, dev, event, detail, opaque): Node device lifecycle events handler ''' _salt_send_event(opaque, conn, { - 'nodedev': dev.name(), + 'nodedev': { + 'name': dev.name() + }, 'event': _get_libvirt_enum_string('VIR_NODE_DEVICE_EVENT_', event), 'detail': 'unknown' # currently unused }) @@ -511,7 +524,9 @@ def _nodedev_event_update_cb(conn, dev, opaque): Node device update events handler ''' _salt_send_event(opaque, conn, { - 'nodedev': dev.name(), + 'nodedev': { + 'name': dev.name() + }, 'event': opaque['event'] }) @@ -521,7 +536,9 @@ def _secret_event_lifecycle_cb(conn, secret, event, detail, opaque): Secret lifecycle events handler ''' _salt_send_event(opaque, conn, { - 'secret': secret.UUIDString(), + 'secret': { + 'uuid': secret.UUIDString() + }, 'event': _get_libvirt_enum_string('VIR_SECRET_EVENT_', event), 'detail': 'unknown' # currently unused }) @@ -532,7 +549,9 @@ def _secret_event_value_changed_cb(conn, secret, opaque): Secret value change events handler ''' _salt_send_event(opaque, conn, { - 'secret': secret.UUIDString(), + 'secret': { + 'uuid': secret.UUIDString() + }, 'event': opaque['event'] }) diff --git a/salt/modules/at.py b/salt/modules/at.py index efd1e034d7..bd2d45a4ff 100644 --- a/salt/modules/at.py +++ b/salt/modules/at.py @@ -104,7 +104,7 @@ def atq(tag=None): if __grains__['os_family'] == 'RedHat': job, spec = line.split('\t') specs = spec.split() - elif __grains__['os'] in BSD: + elif __grains__['os'] == 'OpenBSD': if line.startswith(' Rank'): continue else: @@ -115,6 +115,17 @@ def atq(tag=None): '%H:%M')[0:5])).isoformat().split('T') specs.append(tmp[7]) specs.append(tmp[5]) + elif __grains__['os'] == 'FreeBSD': + if line.startswith('Date'): + continue + else: + tmp = line.split() + timestr = ' '.join(tmp[1:6]) + job = tmp[8] + specs = datetime.datetime(*(time.strptime(timestr, + '%b %d %H:%M:%S %Z %Y')[0:5])).isoformat().split('T') + specs.append(tmp[7]) + specs.append(tmp[6]) else: job, spec = line.split('\t') diff --git a/salt/modules/vault.py b/salt/modules/vault.py index cb1277b2e9..50cc94a206 100644 --- a/salt/modules/vault.py +++ b/salt/modules/vault.py @@ -108,10 +108,6 @@ Functions to interact with Hashicorp Vault. from __future__ import absolute_import, print_function, unicode_literals import logging -# Import Salt libs -import salt.crypt -import salt.exceptions - log = logging.getLogger(__name__) @@ -146,7 +142,7 @@ def read_secret(path, key=None): return data except Exception as err: log.error('Failed to read secret! %s: %s', type(err).__name__, err) - raise salt.exceptions.CommandExecutionError(err) + return None def write_secret(path, **kwargs): @@ -169,7 +165,7 @@ def write_secret(path, **kwargs): return True except Exception as err: log.error('Failed to write secret! %s: %s', type(err).__name__, err) - raise salt.exceptions.CommandExecutionError(err) + return False def delete_secret(path): @@ -191,7 +187,7 @@ def delete_secret(path): return True except Exception as err: log.error('Failed to delete secret! %s: %s', type(err).__name__, err) - raise salt.exceptions.CommandExecutionError(err) + return False def list_secrets(path): @@ -214,4 +210,4 @@ def list_secrets(path): return response.json()['data'] except Exception as err: log.error('Failed to list secrets! %s: %s', type(err).__name__, err) - raise salt.exceptions.CommandExecutionError(err) + return None diff --git a/salt/templates/debian_ip/route_eth.jinja b/salt/templates/debian_ip/route_eth.jinja index a5379b1964..21d73f0d5d 100644 --- a/salt/templates/debian_ip/route_eth.jinja +++ b/salt/templates/debian_ip/route_eth.jinja @@ -2,5 +2,5 @@ # {{route_type}} test "${IFACE}" = "{{iface}}" || exit 0 {% for route in routes %}{% if route.name %}# {{route.name}} -{%endif%}ip route {{route_type}} {% if route.ipaddr %}{{route.ipaddr}}{%endif%}{% if route.netmask %}/{{route.netmask}}{%endif%} {% if route.gateway %}via {{route.gateway}}{%endif%} dev {{iface}} +{%endif%}ip route {{route_type}} {% if route.ipaddr %}{{route.ipaddr}}{%endif%}{% if route.netmask %}/{{route.netmask}}{%endif%} {% if route.gateway %}via {{route.gateway}}{%endif%} dev {{iface}}{% if route.metric %} metric {{route.metric}}{%endif%} {% endfor %} diff --git a/salt/templates/rh_ip/rh6_route_eth.jinja b/salt/templates/rh_ip/rh6_route_eth.jinja index 4b0bc7ede1..3bde01b6e0 100644 --- a/salt/templates/rh_ip/rh6_route_eth.jinja +++ b/salt/templates/rh_ip/rh6_route_eth.jinja @@ -7,4 +7,6 @@ {%- if route.gateway %} via {{route.gateway}} {%- else %} dev {{iface}} {%- endif %} +{%- if route.metric %} metric {{route.metric}} +{%- endif %} {% endfor -%}