Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove curl dependency #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ENV DEBIAN_FRONTEND noninteractive
# - remove defunct packages
# - start supervisor
#
RUN apt-get -y update && apt-get -y upgrade && apt-get -y install git curl python python-requests supervisor
RUN apt-get -y update && apt-get -y upgrade && apt-get -y install git python python-requests supervisor
RUN curl https://bootstrap.pypa.io/get-pip.py | python
ADD resources/supervisor/supervisord.conf /etc/supervisor/supervisord.conf
RUN pip install git+https://github.com/autodesk-cloud/ochopod.git
Expand Down
19 changes: 10 additions & 9 deletions ochopod/bindings/ec2/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from pykka import ThreadingFuture
from pykka.exceptions import Timeout, ActorDeadError
from flask import Flask, request
from requests import post
import requests
from requests.auth import HTTPBasicAuth

#: Our ochopod logger.
Expand Down Expand Up @@ -106,9 +106,9 @@ def boot(self, lifecycle, model=Reactive, local=0):
# - we'll retrieve the underlying metadata using curl
#
def _aws(token):
code, lines = shell('curl -f http://169.254.169.254/latest/meta-data/%s' % token)
assert code is 0, 'unable to lookup EC2 metadata for %s (are you running on EC2 ?)' % token
return lines[0]
result = requests.get('http://169.254.169.254/latest/meta-data/%s' % token)
assert result.status_code is requests.codes.ok, 'unable to lookup EC2 metadata for %s (are you running on EC2 ?)' % token
return result.text[0]

#
# - lame workaround to fetch the master IP and credentials as there does not seem to be a way to
Expand All @@ -117,9 +117,10 @@ def _aws(token):
# - don't forget to merge the resulting output
#
def _k8s(token):
code, lines = shell('curl -f -u %s:%s -k https://%s/api/v1beta3/namespaces/default/%s' % (env['KUBERNETES_USER'], env['KUBERNETES_PWD'], env['KUBERNETES_MASTER'], token))
assert code is 0, 'unable to look the RO service up (is the master running ?)'
return json.loads(''.join(lines))
result = requests.get('https://%s//api/v1beta3/namespaces/default/%s' % (env['KUBERNETES_MASTER'], token),
auth=(env['KUBERNETES_USER'], env['KUBERNETES_PWD']))
assert result.status_code is requests.codes.ok, 'unable to look the RO service up (is the master running ?)'
return result.json()

#
# - look our local k8s pod up
Expand Down Expand Up @@ -333,7 +334,7 @@ def run(self):
#
shutdown(executor)
shutdown(coordinator)
post('http://127.0.0.1:%s/terminate' % env['ochopod_port'])
requests.post('http://127.0.0.1:%s/terminate' % env['ochopod_port'])

except KeyboardInterrupt:

Expand All @@ -343,4 +344,4 @@ def run(self):

logger.fatal('unexpected condition -> %s' % diagnostic(failure))

exit(1)
exit(1)
12 changes: 6 additions & 6 deletions ochopod/bindings/ec2/marathon.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from pykka import ThreadingFuture
from pykka.exceptions import Timeout, ActorDeadError
from flask import Flask, request
from requests import post
import requests

#: Our ochopod logger.
logger = logging.getLogger('ochopod')
Expand Down Expand Up @@ -119,9 +119,9 @@ def boot(self, lifecycle, model=Reactive, local=0):
# - get our underlying metadata using curl
#
def _peek(token, strict=True):
code, lines = shell('curl -f http://169.254.169.254/latest/meta-data/%s' % token)
assert not strict or code is 0, 'unable to lookup EC2 metadata for %s (are you running on EC2 ?)' % token
return lines[0]
result = requests.get('http://169.254.169.254/latest/meta-data/%s' % token)
assert not strict or result.status_code is requests.codes.ok, 'unable to lookup EC2 metadata for %s (are you running on EC2 ?)' % token
return result.text[0]

#
# - get our local and public IPV4 addresses
Expand Down Expand Up @@ -335,12 +335,12 @@ def run(self):
#
shutdown(executor)
shutdown(coordinator)
post('http://127.0.0.1:%s/terminate' % env['ochopod_port'])
requests.post('http://127.0.0.1:%s/terminate' % env['ochopod_port'])

except KeyboardInterrupt:

logger.fatal('CTRL-C pressed')

except Exception as failure:

logger.fatal('unexpected condition -> %s' % diagnostic(failure))
logger.fatal('unexpected condition -> %s' % diagnostic(failure))