salt icon indicating copy to clipboard operation
salt copied to clipboard

salt-cloud operating against wrong AWS endpoint

Open jdito opened this issue 9 years ago • 6 comments

Description of Issue/Question

Hi, I've just started using salt-cloud, and I seem to be running into an issue with AWS endpoints. I've got a profile to launch a VM in us-east-2, and it gets most of the way through provisioning, but when it tries to mark the minion as created, it sends the request to ec2.us-east-1.amazonaws.com.

Setup

[root@sum-foreman-02 ~]# cat /etc/salt/cloud.providers.d/ec2.conf 
dy-ec2:
  driver: ec2
  # Set the EC2 access credentials (see below)
  #
  id: 'xxx'
  key: 'xxx'

  # Make sure this key is owned by root with permissions 0400.
  #
  private_key: /root/.ssh/ec2_salt_rsa
  keyname: ec2_salt_rsa
  securitygroup: default
[root@sum-foreman-02 ~]# cat /etc/salt/cloud.profiles.d/ec2.conf 
base:
  provider: dy-ec2
  size: t2.micro
  del_root_vol_on_destroy: True
  del_all_vol_on_destroy: True
  ssh_username: ec2-user

#micro_ec2_us-east-1:
#  extends: base
#  location: us-east-1
#  image: ami-b63769a1

micro_ec2_us-east-2:
  extends: base
  location: us-east-2
  image: ami-c55673a0

Steps to Reproduce Issue

Attempt to create AWS VM in an endpoint other than us-east-1. I've only tried with us-east-2 so far. I'm also cutting out most of the output; I can pastebin the whole thing if it could be relevant.

[root@sum-foreman-02 ~]# salt-cloud -p micro_ec2_us-east-2 minion1-east2-2 -l debug
------
[DEBUG   ] Sending event: tag = salt/cloud/minion1-east2-2/created; data = {'profile': 'micro_ec2_us-east-2', '_stamp': '2017-02-28T20:27:10.453630', 'name': 'minion1-east2-2', 'instance_id': 'i-0a282bb188dda081f', 'provider': 'dy-ec2:ec2', 'event': 'created instance'}
[DEBUG   ] Using AWS endpoint: ec2.us-east-1.amazonaws.com
[DEBUG   ] AWS Request: https://ec2.us-east-1.amazonaws.com/?Action=DescribeInstances&InstanceId.1=i-0a282bb188dda081f&Version=2014-10-01
[DEBUG   ] AWS Response Status Code: 400
[ERROR   ] AWS Response Status Code and Error: [400 400 Client Error: Bad Request for url: https://ec2.us-east-1.amazonaws.com/?Action=DescribeInstances&InstanceId.1=i-0a282bb188dda081f&Version=2014-10-01] {'Errors': {'Error': {'Message': "The instance ID 'i-0a282bb188dda081f' does not exist", 'Code': 'InvalidInstanceID.NotFound'}}, 'RequestID': 'b8bc34b8-2617-4645-8d4a-9409d06d57c2'}
[ERROR   ] There was a profile error: string indices must be integers, not str
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/salt/cloud/cli.py", line 284, in run
    self.config.get('names')
  File "/usr/lib/python2.7/site-packages/salt/cloud/__init__.py", line 1458, in run_profile
    ret[name] = self.create(vm_)
  File "/usr/lib/python2.7/site-packages/salt/cloud/__init__.py", line 1288, in create
    output = self.clouds[func](vm_)
  File "/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.py", line 2695, in create
    node = _get_node(instance_id=vm_['instance_id'])
  File "/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.py", line 3304, in _get_node
    return _extract_instance_info(instances).values()[0]
  File "/usr/lib/python2.7/site-packages/salt/cloud/clouds/ec2.py", line 3382, in _extract_instance_info
    if isinstance(instance['instancesSet']['item'], list):
TypeError: string indices must be integers, not str

Versions Report

All freshly installed from the 'latest' repo.

[root@sum-foreman-02 ~]# salt-cloud --versions-report                                                                                                                                                                                                                                                               [0/9257]
Salt Version:
            Salt: 2016.11.3
 
Dependency Versions:
 Apache Libcloud: 0.20.1
            cffi: 0.8.6
        cherrypy: 3.2.2
        dateutil: 1.5
           gitdb: 0.5.4
       gitpython: 0.3.2 RC1
           ioflo: Not Installed
          Jinja2: 2.7.2
         libgit2: 0.21.0
         libnacl: Not Installed
        M2Crypto: 0.21.1
            Mako: Not Installed
    msgpack-pure: Not Installed
  msgpack-python: 0.4.7
    mysql-python: Not Installed
       pycparser: 2.14
        pycrypto: 2.6.1
          pygit2: 0.21.4
          Python: 2.7.5 (default, Nov 20 2015, 02:00:19)
    python-gnupg: Not Installed
          PyYAML: 3.10
           PyZMQ: 14.3.1
            RAET: Not Installed
           smmap: 0.9.0
         timelib: Not Installed
         Tornado: 4.2.1
             ZMQ: 3.2.5
 
System Versions:
            dist: centos 7.2.1511 Core
         machine: x86_64
         release: 3.10.0-327.18.2.el7.x86_64
          system: Linux
         version: CentOS Linux 7.2.1511 Core

jdito avatar Feb 28 '17 20:02 jdito

Thanks for reporting this, If you wanted to take a shot at fixing this, we would greatly appreciate it, otherwise we will get it fixed.

Thanks Daniel

gtmanfred avatar Mar 01 '17 17:03 gtmanfred

I'll take a look, but I'm kind of an awful programmer, so no promises. It does work if I pass '-L us-east-2' on the command line.

jdito avatar Mar 01 '17 22:03 jdito

In /cloud/ec2.py, in the create function, update the following line: node = _get_node(instance_id=vm_['instance_id']) to node = _get_node(instance_id=vm_['instance_id'], location=location) and it works properly. Otherwise you can specify the location in the provider configuration.

The problem also affects Salt version 2016.3.6 and the destroy function.

hemebond avatar Jun 28 '17 01:06 hemebond

@hemebond Thanks for the suggestion. I tried that patch in your comment and it works while provisioning - so the end point is properly configured to do the final step where it queries the correct AWS endpoint of that zone.

However the issue still remains when I do a salt-cloud --query (it only shows the us-east-1 VM even though I created other VMs in other zones of AWS using salt-cloud right before). Similarly when deleting it is blind to VMs created in other zones. (This is using the latest development branch earlier today).

bigbitbus avatar May 06 '18 23:05 bigbitbus

Otherwise you can specify the location in the provider configuration.

Doing this resolved it for me. Thanks!

shaneneuerburg avatar Oct 02 '18 17:10 shaneneuerburg

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

stale[bot] avatar Jan 09 '20 18:01 stale[bot]