本文整理汇总了Python中marathon.MarathonClient类的典型用法代码示例。如果您正苦于以下问题:Python MarathonClient类的具体用法?Python MarathonClient怎么用?Python MarathonClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MarathonClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
def update(service, instances = 1):
#
# set up marathon client and launch container
#
print 'updating ' + service
image_string = 'docker:///' + data['services'][service]['image']
print image_string
marathon_client = MarathonClient('http://' + str(data['marathon']['host']) + ':' + str(data['marathon']['port']))
app = marathon_client.get_app(service)
#
# set up options for cassandra
#
options = []
if service == "cassandra":
options = ["-p", "7000:7000", "-p", "9042:9042", "-p", "9160:9160", "-p", "22000:22", "-p", "5000:5000"]
# ports = []
# constraints = [["hostname", "UNIQUE"]]
marathon_client.update_app(
service,
app,
instances = instances,
container = {
"image" : image_string,
"options" : options
}
)
示例2: test_list_tasks_without_app_id
def test_list_tasks_without_app_id(m):
fake_response = '{ "tasks": [ { "appId": "/anapp", "healthCheckResults": ' \
'[ { "alive": true, "consecutiveFailures": 0, "firstSuccess": "2014-10-03T22:57:02.246Z", "lastFailure": null, ' \
'"lastSuccess": "2014-10-03T22:57:41.643Z", "taskId": "bridged-webapp.eb76c51f-4b4a-11e4-ae49-56847afe9799" } ],' \
' "host": "10.141.141.10", "id": "bridged-webapp.eb76c51f-4b4a-11e4-ae49-56847afe9799", "ports": [ 31000 ], ' \
'"servicePorts": [ 9000 ], "stagedAt": "2014-10-03T22:16:27.811Z", "startedAt": "2014-10-03T22:57:41.587Z", ' \
'"version": "2014-10-03T22:16:23.634Z" }, { "appId": "/anotherapp", ' \
'"healthCheckResults": [ { "alive": true, "consecutiveFailures": 0, "firstSuccess": "2014-10-03T22:57:02.246Z", ' \
'"lastFailure": null, "lastSuccess": "2014-10-03T22:57:41.649Z", "taskId": "bridged-webapp.ef0b5d91-4b4a-11e4-ae49-56847afe9799" } ], ' \
'"host": "10.141.141.10", "id": "bridged-webapp.ef0b5d91-4b4a-11e4-ae49-56847afe9799", "ports": [ 31001 ], "servicePorts": [ 9000 ], ' \
'"stagedAt": "2014-10-03T22:16:33.814Z", "startedAt": "2014-10-03T22:57:41.593Z", "version": "2014-10-03T22:16:23.634Z" } ] }'
m.get('http://fake_server/v2/tasks', text=fake_response)
mock_client = MarathonClient(servers='http://fake_server')
actual_deployments = mock_client.list_tasks()
expected_deployments = [
models.task.MarathonTask(
app_id="/anapp",
health_check_results=[
models.task.MarathonHealthCheckResult(
alive=True,
consecutive_failures=0,
first_success="2014-10-03T22:57:02.246Z",
last_failure=None,
last_success="2014-10-03T22:57:41.643Z",
task_id="bridged-webapp.eb76c51f-4b4a-11e4-ae49-56847afe9799"
)
],
host="10.141.141.10",
id="bridged-webapp.eb76c51f-4b4a-11e4-ae49-56847afe9799",
ports=[
31000
],
service_ports=[
9000
],
staged_at="2014-10-03T22:16:27.811Z",
started_at="2014-10-03T22:57:41.587Z",
version="2014-10-03T22:16:23.634Z"
),
models.task.MarathonTask(
app_id="/anotherapp",
health_check_results=[
models.task.MarathonHealthCheckResult(
alive=True,
consecutive_failures=0,
first_success="2014-10-03T22:57:02.246Z",
last_failure=None,
last_success="2014-10-03T22:57:41.649Z",
task_id="bridged-webapp.ef0b5d91-4b4a-11e4-ae49-56847afe9799"
)
],
host="10.141.141.10",
id="bridged-webapp.ef0b5d91-4b4a-11e4-ae49-56847afe9799",
ports=[31001],
service_ports=[9000],
staged_at="2014-10-03T22:16:33.814Z",
started_at="2014-10-03T22:57:41.593Z",
version="2014-10-03T22:16:23.634Z"
)]
assert actual_deployments == expected_deployments
示例3: servermarathon
def servermarathon():
APP = os.environ['APPNAME']
# STRING = os.environ['STRING']
# content = STRING
# contentlist = content.split('&')
# list = []
# for i in contentlist:
# p = i.split('=')
# p = p[1]
# l = list.append(p)
# (maurl,mau,map) =tuple(list)
# marathonip = maurl
# user = mau
# password = map
c = MarathonClient(marathonip,username=user,password=password)
buildFile=open('build.txt','r')
dockerimage = buildFile.readline()
buildFile.close()
readed = json.load(open('temp.json', 'r'))
readed['container']['docker']['image'] = dockerimage
readed['id'] = APP
json.dump(readed, open('app.json', 'w'))
try:
c.delete_app(APP,force=True)
print 'delete'
except :
pass
sleep(3)
u= user+':'+password
cmd1 = os.system ('curl -u %s -X POST -H "Content-Type: application/json" %s/v2/apps [email protected]' %(u,marathonip))
示例4: clean_deploy_ids
def clean_deploy_ids(self):
marathon_client = MarathonClient('http://' + str(marathon_host) + ':' + str(marathon_port))
apps = marathon_client.list_apps()
app_ids = [x.id for x in apps]
for deploy_id in self.deploy_ids:
if not deploy_id in app_ids:
print 'deploy_id is not in app id! '+str(deploy_id)
示例5: enable_logstash
def enable_logstash():
print "Checking ELK entries\n"
endpoint = os.getenv('MARATHON_ENDPOINT')
username = os.getenv('MARATHON_HTTP_USER')
password = os.getenv('MARATHON_HTTP_PASSWORD')
elk_host = None
if endpoint:
try:
print 'Discovering configuration from %s\n' % endpoint
c = MarathonClient('https://%s' % endpoint, username=username, password=password)
tasks = c.list_tasks('yroblaelk')
for task in tasks:
if task.started_at:
elk_host = task.host
break
except:
pass
# check entries in wsrep_cluster_address
if elk_host:
print 'Found ELK address %s\n' % elk_host
for line in fileinput.input(LOGSTASH_CONF_FILE, inplace=True):
line_content = line
sys.stdout.write(line.replace("ELK_HOST", elk_host))
# reboot logstash
subprocess.call(["service", "logstash-forwarder", "restart"])
示例6: MarathonDeployer
class MarathonDeployer(object):
def __init__(self, marathon_url):
self.url = marathon_url
self.client = MarathonClient(self.url)
def deploy(self, task_chain, environment_name):
deployed_chain = DeployedTaskChain(task_chain, environment_name)
for task in deployed_chain.list_all_tasks():
task_id = task['id']
safe_name = task_id.lower()
# safe_name = task['name'].replace('.', '').lower()
try:
if self.client.get_app(safe_name):
self.client.delete_app(safe_name)
time.sleep(2)
except Exception:
pass
app = MarathonApp(cmd='/var/riversnake/invoke.py {0} {1} {2}'.format(
task_chain.flow_name,
environment_name,
task_id),
mem=16, cpus=1)
self.client.create_app(safe_name, app)
示例7: update_app
def update_app(app_id, config, instances = 1):
#
# set up marathon client and launch container
#
image_string = 'docker:///' + config['image']
marathon_client = MarathonClient('http://' + str(marathon_host) + ':' + str(marathon_port))
app = marathon_client.get_app(app_id)
#
# set up options for cassandra TODO this is terrible dawg
#
decoded = namespacer.decode_marathon_id(app_id)
options = []
if str(decoded['service']) == "cassandra":
options = ["-p", "7000:7000", "-p", "9042:9042", "-p", "9160:9160", "-p", "22000:22", "-p", "5000:5000"]
# ports = []
# constraints = [["hostname", "UNIQUE"]]
marathon_client.update_app(
app_id,
app,
instances = instances,
container = {
"image" : image_string,
"options" : options
}
)
示例8: new_app
def new_app(request):
data = {}
if request.method == "POST":
data["msg"] = "Post"
post_params = {}
for key in request.POST:
if key.startswith("filehidden"):
fkey = key[11:]
if request.FILES.get(fkey, None):
post_file = request.FILES[fkey]
file_content = ""
for chunk in post_file.chunks():
file_content += chunk.decode("utf8")
post_params[fkey] = convert(file_content)
else:
post_params[fkey] = request.POST[key]
else:
post_params[key] = request.POST[key]
template = Template.objects.get(pk=post_params["template_id"])
content = template.content % post_params
data["content"] = content
mc = MarathonClient("http://{}:{}".format(settings.MARATHON["host"], settings.MARATHON["port"]))
try:
mc.create_app_by_json(content)
data["result"] = "Success"
except Exception as e:
data["result"] = str(e)
templates = Template.objects.filter(type="marathon").all()
for template in templates:
template.params = template.param_set.order_by("id")
data["templates"] = templates
return render(request, "marathon_mgmt/new_app.html", data)
示例9: sync_marathon_app
def sync_marathon_app():
"""Identify the hosts and ports of executing tasks
Optional environment variables:
MARATHON_ROOT_URL: protocol, address or ip and port to Marathon
MARATHON_APP: app name within Marathon used to group all tasks (server instances)
MARATHON_APP_PORT: internal port of service (internal to docker container: default of 8080)
:return:
"""
# Identify the hosts and ports of executing tasks
try:
c = None
if len(DCOS_OAUTH_TOKEN):
c = MarathonClient(MARATHON_ROOT_URLS, auth_token=DCOS_OAUTH_TOKEN)
else:
c = MarathonClient(MARATHON_ROOT_URLS)
app = c.get_app(MARATHON_APP)
port_index = find_port_index_by_container_port(app, MARATHON_APP_PORT)
if port_index is None:
raise Exception('Unable to correlate container to host port.')
instances = []
for task in app.tasks:
logging.info('Queuing configuration refresh of %s at %s:%s' %
(task.id, task.host, task.ports[port_index]))
instances.append('%s:%s' % (task.host, task.ports[port_index]))
reload_config(instances)
except MarathonError, ex:
print 'Error making Marathon API call: %s' % ex.message
示例10: get_marathon_app_id
def get_marathon_app_id(self):
marathon_client = MarathonClient('http://' + str(marathon_host) + ':' + str(marathon_port))
apps = marathon_client.list_apps()
my_encoded_id = self.encode_marathon_id
for app in apps:
if app.id == my_encoded_id:
return app.id
return None
示例11: is_deployed
def is_deployed(self):
marathon_client = MarathonClient('http://' + str(marathon_host) + ':' + str(marathon_port))
apps = marathon_client.list_apps()
my_encoded_id = self.encode_marathon_id
for app in apps:
if my_encoded_id in app.id:
return True
return False
示例12: list_app
def list_app(request):
mc = MarathonClient('http://{}:{}'.format(settings.MARATHON['host'], settings.MARATHON['port']))
apps = mc.list_apps()
apps = sorted(apps, key=lambda app: app.id)
for app in apps:
app.tag_id = app.id.replace("/","__")
data = {'apps': apps}
return render(request, 'marathon_mgmt/list_app.html', data)
示例13: _get_hosts_with_container
def _get_hosts_with_container(self, context, cluster):
marathon_client = MarathonClient(
'http://' + cluster.api_address + '/marathon/')
hosts = set()
for task in marathon_client.list_tasks():
hosts.add(task.host)
return hosts
示例14: launch_qsf
def launch_qsf(marathon_url):
logging.info('Launching QSF using %s' %(marathon_url))
# launch via Marathon REST API
c = MarathonClient(marathon_url)
c.create_app('dromedar-qsf', MarathonApp(cmd='python dromedar-master/qsf.py %s' %(marathon_url), uris=['https://github.com/mhausenblas/dromedar/archive/master.zip'], mem=100, cpus=.5))
logging.info('QSF up and running.')
示例15: get_hosts_dict
def get_hosts_dict(self):
hosts={}
for app in MarathonClient.list_apps(self):
for task in MarathonClient.get_app(self,app.id).tasks:
host = task.host
if not host in hosts:
hosts[host]=[]
hosts[host].append(task)
return hosts