|
@@ -44,25 +44,25 @@ class Cluster_Action(Docker_Action):
|
|
@staticmethod
|
|
@staticmethod
|
|
def leave():
|
|
def leave():
|
|
result = Swarm.leave()
|
|
result = Swarm.leave()
|
|
- print result
|
|
|
|
|
|
+ print(result)
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
def drop():
|
|
def drop():
|
|
Swarm.drop()
|
|
Swarm.drop()
|
|
- print 'drop cluster:yes'
|
|
|
|
|
|
+ print('drop cluster:yes')
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
def name():
|
|
def name():
|
|
arg = Args.name
|
|
arg = Args.name
|
|
name = Swarm.name(arg)
|
|
name = Swarm.name(arg)
|
|
name = name.split("\n")
|
|
name = name.split("\n")
|
|
- print name[0]
|
|
|
|
|
|
+ print(name[0])
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
def names():
|
|
def names():
|
|
arg = Args.name
|
|
arg = Args.name
|
|
name = Swarm.name(arg)
|
|
name = Swarm.name(arg)
|
|
- print name
|
|
|
|
|
|
+ print(name)
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
def node():
|
|
def node():
|
|
@@ -72,12 +72,12 @@ class Cluster_Action(Docker_Action):
|
|
def num():
|
|
def num():
|
|
name = Args.name
|
|
name = Args.name
|
|
num = Args.param
|
|
num = Args.param
|
|
- print 'setting ' + name + ', please wait...'
|
|
|
|
|
|
+ print('setting ' + name + ', please wait...')
|
|
Swarm.scale(name, num)
|
|
Swarm.scale(name, num)
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
def restart(**param):
|
|
def restart(**param):
|
|
- print 'reloading ' + param['name'] + ', please wait...'
|
|
|
|
|
|
+ print('reloading ' + param['name'] + ', please wait...')
|
|
name = Swarm.name(param['name'])
|
|
name = Swarm.name(param['name'])
|
|
name = name.split("\n")
|
|
name = name.split("\n")
|
|
for i in name:
|
|
for i in name:
|
|
@@ -105,7 +105,7 @@ class Cluster_Action(Docker_Action):
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
def stop(**param):
|
|
def stop(**param):
|
|
- print 'stop command is not exists'
|
|
|
|
|
|
+ print('stop command is not exists')
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
def save(**param):
|
|
def save(**param):
|
|
@@ -134,7 +134,7 @@ class Cluster_Action(Docker_Action):
|
|
Alias.delete(param['config'], param['name'])
|
|
Alias.delete(param['config'], param['name'])
|
|
else:
|
|
else:
|
|
Container.delete()
|
|
Container.delete()
|
|
- print 'rm cluster:yes'
|
|
|
|
|
|
+ print('rm cluster:yes')
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
def rmb(**param):
|
|
def rmb(**param):
|
|
@@ -143,7 +143,7 @@ class Cluster_Action(Docker_Action):
|
|
Alias.delete(param['config'], param['name'])
|
|
Alias.delete(param['config'], param['name'])
|
|
else:
|
|
else:
|
|
Swarm.delete()
|
|
Swarm.delete()
|
|
- print 'rm cluster:yes'
|
|
|
|
|
|
+ print('rm cluster:yes')
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
def reset(self, **param):
|
|
def reset(self, **param):
|
|
@@ -153,7 +153,7 @@ class Cluster_Action(Docker_Action):
|
|
@classmethod
|
|
@classmethod
|
|
def test(self, **param):
|
|
def test(self, **param):
|
|
param['test'] = True
|
|
param['test'] = True
|
|
- print self.run(**param)
|
|
|
|
|
|
+ print(self.run(**param))
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
def create(self, **param):
|
|
def create(self, **param):
|
|
@@ -195,13 +195,13 @@ class Cluster_Action(Docker_Action):
|
|
command = ' '.join(run)
|
|
command = ' '.join(run)
|
|
if 'test' in param:
|
|
if 'test' in param:
|
|
return 'docker service create ' + command
|
|
return 'docker service create ' + command
|
|
- print 'setuping ' + param['name'] + ', please wait...'
|
|
|
|
|
|
+ print('setuping ' + param['name'] + ', please wait...')
|
|
method = Core.getMethod(Swarm, param['action'])
|
|
method = Core.getMethod(Swarm, param['action'])
|
|
method(command)
|
|
method(command)
|
|
Alias.add(param['config'], param['name'], 'docker run ' + command, param['action'], True)
|
|
Alias.add(param['config'], param['name'], 'docker run ' + command, param['action'], True)
|
|
Cluster.hook('end', param['config'], param['name'])
|
|
Cluster.hook('end', param['config'], param['name'])
|
|
else:
|
|
else:
|
|
- print param['name'] + ' cluster is setuped'
|
|
|
|
|
|
+ print(param['name'] + ' cluster is setuped')
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
def setting():
|
|
def setting():
|
|
@@ -229,7 +229,7 @@ class Cluster_Action(Docker_Action):
|
|
url = 'http://' + ip + ':8500/v1/kv/' + key
|
|
url = 'http://' + ip + ':8500/v1/kv/' + key
|
|
Core.popen('curl -X PUT -d "'+value+'" ' + url, bg=True)
|
|
Core.popen('curl -X PUT -d "'+value+'" ' + url, bg=True)
|
|
if p == True:
|
|
if p == True:
|
|
- print True
|
|
|
|
|
|
+ print(True)
|
|
return True
|
|
return True
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
@@ -243,19 +243,19 @@ class Cluster_Action(Docker_Action):
|
|
url = 'http://' + ip + ':8500/v1/kv/' + key
|
|
url = 'http://' + ip + ':8500/v1/kv/' + key
|
|
value = Core.curl(url)
|
|
value = Core.curl(url)
|
|
if not value:
|
|
if not value:
|
|
- print False
|
|
|
|
|
|
+ print(False)
|
|
return False
|
|
return False
|
|
value = json.loads(value)
|
|
value = json.loads(value)
|
|
value = base64.b64decode(value[0]['Value'])
|
|
value = base64.b64decode(value[0]['Value'])
|
|
if p == True:
|
|
if p == True:
|
|
- print value
|
|
|
|
|
|
+ print(value)
|
|
return value
|
|
return value
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
def init(self, **param):
|
|
def init(self, **param):
|
|
(ip, ckey) = self.setting()
|
|
(ip, ckey) = self.setting()
|
|
token = Swarm.init(ip)
|
|
token = Swarm.init(ip)
|
|
- print 'init cluster ...'
|
|
|
|
|
|
+ print('init cluster ...')
|
|
if token and '--token' in token:
|
|
if token and '--token' in token:
|
|
Core.popen('dm pull consul')
|
|
Core.popen('dm pull consul')
|
|
Core.popen('ds run daemon-master')
|
|
Core.popen('ds run daemon-master')
|
|
@@ -268,14 +268,14 @@ class Cluster_Action(Docker_Action):
|
|
|
|
|
|
self.put(ckey, token, p = False)
|
|
self.put(ckey, token, p = False)
|
|
#Core.popen('consul kv put ' + ckey + ' ' + token)
|
|
#Core.popen('consul kv put ' + ckey + ' ' + token)
|
|
- print 'init cluster success! please remember the ip address:'+ip+''
|
|
|
|
|
|
+ print('init cluster success! please remember the ip address:'+ip+'')
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
def join(self, **param):
|
|
def join(self, **param):
|
|
(ip, ckey) = self.setting()
|
|
(ip, ckey) = self.setting()
|
|
value = self.get(ckey, ip, False)
|
|
value = self.get(ckey, ip, False)
|
|
#config = value.split(':')
|
|
#config = value.split(':')
|
|
- print value
|
|
|
|
|
|
+ print(value)
|
|
|
|
|
|
'''
|
|
'''
|
|
Core.popen('dm pull consul')
|
|
Core.popen('dm pull consul')
|
|
@@ -305,7 +305,7 @@ class Swarm(object):
|
|
return command
|
|
return command
|
|
@staticmethod
|
|
@staticmethod
|
|
def show(name=''):
|
|
def show(name=''):
|
|
- print Core.shell('swarm.show ' + name)
|
|
|
|
|
|
+ print(Core.shell('swarm.show ' + name))
|
|
@staticmethod
|
|
@staticmethod
|
|
def args():
|
|
def args():
|
|
return {
|
|
return {
|
|
@@ -325,7 +325,7 @@ class Swarm(object):
|
|
Core.shell('swarm.drop', bg=True)
|
|
Core.shell('swarm.drop', bg=True)
|
|
@staticmethod
|
|
@staticmethod
|
|
def node():
|
|
def node():
|
|
- print Core.shell('swarm.node')
|
|
|
|
|
|
+ print(Core.shell('swarm.node'))
|
|
@staticmethod
|
|
@staticmethod
|
|
def stop(name):
|
|
def stop(name):
|
|
Core.shell('swarm.stop ' + name)
|
|
Core.shell('swarm.stop ' + name)
|
|
@@ -341,7 +341,7 @@ class Swarm(object):
|
|
@classmethod
|
|
@classmethod
|
|
def delete(self, name='', bg=False):
|
|
def delete(self, name='', bg=False):
|
|
if name != '':
|
|
if name != '':
|
|
- print 'rm ' + name + ', please wait...'
|
|
|
|
|
|
+ print('rm ' + name + ', please wait...')
|
|
if self.check(name) == 1:
|
|
if self.check(name) == 1:
|
|
Core.shell('swarm.rm ' + name, False, bg=bg)
|
|
Core.shell('swarm.rm ' + name, False, bg=bg)
|
|
else:
|
|
else:
|