Skip to content

Commit

Permalink
A few changes are needed to support the latest version of etcd
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Feb 10, 2014
1 parent 6dbd008 commit a085316
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
1 change: 1 addition & 0 deletions bootstrap.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
apt-get update
apt-get -y install software-properties-common
echo "Acquire::http::Proxy \"http://192.168.1.21:3142\";" > /etc/apt/apt.conf.d/02proxy
mkdir -p /etc/salt/
touch /etc/salt/minion
cat <<EOF > /etc/salt/minion
Expand Down
26 changes: 20 additions & 6 deletions etcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, logger, server=None):
self.server = server
else:
self.server = socket.gethostname()
self.url = 'http://%(hostname)s:4001/v1/keys' % {
self.url = 'http://%(hostname)s:4001/v2/keys' % {
'hostname': self.server}
self.logger = logger

Expand All @@ -42,12 +42,15 @@ def set_key(self, key, value):
curl.setopt(pycurl.FOLLOWLOCATION, 1)
curl.setopt(pycurl.MAXREDIRS, 5)
curl.setopt(curl.WRITEFUNCTION, storage.write)
curl.setopt(pycurl.CUSTOMREQUEST, "PUT")
curl.perform()
response = curl.getinfo(pycurl.HTTP_CODE)
curl.close()

if response == requests.codes.ok:
return True
elif response == requests.codes.created:
return True
else:
self.logger.error("ETCD returned %(status)s %(text)s" % {
'status': response,
Expand All @@ -72,7 +75,11 @@ def get_key(self, key):
if 'errorCode' in res:
raise EtcdError(res['errorCode'], res['message'])

return str(res['value'])
try:
return str(res['node']['value'])
except KeyError:
#Fallback on v1 functionality
return str(res['value'])

def delete_key(self, key):
url = '%(base)s/%(key)s' % {
Expand All @@ -96,9 +103,14 @@ def list_directory(self, path):
if response.status_code == requests.codes.ok:
directory_list = []
json_txt = json.loads(response.text)
for entry in json_txt:
directory_list.append(str(entry['key']))
return directory_list
try:
for entry in json_txt['node']['nodes']:
directory_list.append(str(entry['key']))
return directory_list
except KeyError:
self.logger.error("Key ['node']['nodes'] not found in %(data)s" %{
'data': json_txt
})
else:
response.raise_for_status()
return None
Expand Down Expand Up @@ -142,7 +154,9 @@ def test_c_deletekey(self):
self.etcd.set_key('message', 'Hello World')

text = self.etcd.delete_key('message')
regex = re.compile(r'{"action":"DELETE","key":"/message",.*"index":\d+}')
regex = re.compile(r'{"action":"delete","node":{"key":"/message",'
'"modifiedIndex":\d+,"createdIndex":\d+},"prevNode":{"key":"/message"'
',"value":"Hello World","modifiedIndex":\d+,"createdIndex":\d+}}')
self.assertRegexpMatches(text, regex)

def test_d_directorylist(self):
Expand Down
11 changes: 10 additions & 1 deletion manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ def load_formation_from_etcd(self, username, formation_name):
if "WARNING" in app['container_id']:
app['container_id'] = app['container_id'].replace("WARNING: Your "\
"kernel does not support memory swap capabilities. Limitation discarded.\n","")
#Message changed in docker 0.8.0
app['container_id'] = app['container_id'].replace("WARNING: WARNING:"\
"Your kernel does not support swap limit capabilities. Limitation "\
"discarded.\n","")

# Set volumes if needed
volumes = None
Expand Down Expand Up @@ -184,7 +188,12 @@ def start_application(self, app):
salt_process = self.salt_client.cmd(app.host_server,'cmd.run', [d], expr_form='list')
container_id = salt_process[app.host_server]
if container_id:
app.change_container_id(container_id)
if "WARNING" in container_id:
container_id = container_id.replace("WARNING: WARNING: "\
"Your kernel does not support swap limit capabilities. Limitation "\
"discarded.\n","")
#Docker only uses the first 12 chars to identify a container
app.change_container_id(container_id[0:12])

def bootstrap_application(self, app):
# Log into the host with paramiko and run the salt bootstrap script
Expand Down

0 comments on commit a085316

Please sign in to comment.