当前位置: 首页>>代码示例>>Python>>正文


Python MarathonClient.list_deployments方法代码示例

本文整理汇总了Python中marathon.MarathonClient.list_deployments方法的典型用法代码示例。如果您正苦于以下问题:Python MarathonClient.list_deployments方法的具体用法?Python MarathonClient.list_deployments怎么用?Python MarathonClient.list_deployments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在marathon.MarathonClient的用法示例。


在下文中一共展示了MarathonClient.list_deployments方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ajax_deployments

# 需要导入模块: from marathon import MarathonClient [as 别名]
# 或者: from marathon.MarathonClient import list_deployments [as 别名]
def ajax_deployments(request):
    mc = MarathonClient('http://{}:{}'.format(settings.MARATHON['host'], settings.MARATHON['port']))
    deployments = mc.list_deployments()
    data = {}
    for deployment in deployments:
        deployment.complete = (deployment.current_step-1) * 100 / deployment.total_steps

    data['deployments'] = deployments
    data['total_depl'] = len(deployments)
    return render(request, 'marathon_mgmt/ajax_deployments.html', data)
开发者ID:huanpc,项目名称:mesos-admin,代码行数:12,代码来源:views.py

示例2: test_get_deployments

# 需要导入模块: from marathon import MarathonClient [as 别名]
# 或者: from marathon.MarathonClient import list_deployments [as 别名]
def test_get_deployments(m):
    fake_response = '[ { "affectedApps": [ "/test" ], "id": "fakeid", "steps": [ [ { "action": "ScaleApplication", "app": "/test" } ] ], "currentActions": [ { "action": "ScaleApplication", "app": "/test" } ], "version": "fakeversion", "currentStep": 1, "totalSteps": 1 } ]'
    m.get('http://fake_server/v2/deployments', text=fake_response)
    mock_client = MarathonClient(servers='http://fake_server')
    actual_deployments = mock_client.list_deployments()
    expected_deployments = [ models.MarathonDeployment(
        id=u"fakeid",
        steps=[[models.MarathonDeploymentAction(action="ScaleApplication", app="/test")]],
        current_actions=[models.MarathonDeploymentAction(action="ScaleApplication", app="/test")],
        current_step=1,
        total_steps=1,
        affected_apps=[u"/test"],
        version=u"fakeversion"
    )]
    assert expected_deployments == actual_deployments
开发者ID:ashi-austin,项目名称:marathon-python,代码行数:17,代码来源:test_api.py

示例3: test_get_deployments_post_1_0

# 需要导入模块: from marathon import MarathonClient [as 别名]
# 或者: from marathon.MarathonClient import list_deployments [as 别名]
def test_get_deployments_post_1_0():
    fake_response = """[
      {
        "id": "4d2ff4d8-fbe5-4239-a886-f0831ed68d20",
        "version": "2016-04-20T18:00:20.084Z",
        "affectedApps": [
          "/test-trivial-app"
        ],
        "steps": [
          {
            "actions": [
              {
                "type": "StartApplication",
                "app": "/test-trivial-app"
              }
            ]
          },
          {
            "actions": [
              {
                "type": "ScaleApplication",
                "app": "/test-trivial-app"
              }
            ]
          }
        ],
        "currentActions": [
          {
            "action": "ScaleApplication",
            "app": "/test-trivial-app",
            "readinessCheckResults": []
          }
        ],
        "currentStep": 2,
        "totalSteps": 2
      }
    ]"""
    with requests_mock.mock() as m:
        m.get('http://fake_server/v2/deployments', text=fake_response)
        mock_client = MarathonClient(servers='http://fake_server')
        actual_deployments = mock_client.list_deployments()
        expected_deployments = [models.MarathonDeployment(
            id=u"4d2ff4d8-fbe5-4239-a886-f0831ed68d20",
            steps=[
                models.MarathonDeploymentStep(
                    actions=[models.MarathonDeploymentAction(
                        type="StartApplication", app="/test-trivial-app")],
                ),
                models.MarathonDeploymentStep(
                    actions=[models.MarathonDeploymentAction(
                        type="ScaleApplication", app="/test-trivial-app")],
                ),
            ],
            current_actions=[models.MarathonDeploymentAction(
                action="ScaleApplication", app="/test-trivial-app", readiness_check_results=[])
            ],
            current_step=2,
            total_steps=2,
            affected_apps=[u"/test-trivial-app"],
            version=u"2016-04-20T18:00:20.084Z"
        )]
        # Helpful for tox to see the diff
        assert expected_deployments[0].__dict__ == actual_deployments[0].__dict__
        assert expected_deployments == actual_deployments
开发者ID:annorax,项目名称:marathon-python,代码行数:66,代码来源:test_api.py

示例4: MarathonIF

# 需要导入模块: from marathon import MarathonClient [as 别名]
# 或者: from marathon.MarathonClient import list_deployments [as 别名]
class MarathonIF(object):
    def __init__(self, marathon_addr, my_addr, mesos):
        self.mcli = MarathonClient(marathon_addr)
        self.myAddr = my_addr
        self.mesos = mesos

    def get_apps(self):
        listapps = self.mcli.list_apps()
        return listapps

    def get_app(self, app_id):
        try:
            a = self.mcli.get_app(app_id)
        except marathon.exceptions.NotFoundError as e:  # NOQA
            return None
        return a

    def delete_app(self, app_id, force=False):
        return self.mcli.delete_app(app_id, force)

    def delete_deployment(self, dep_id):
        return self.mcli.delete_deployment(dep_id)

    def get_deployments(self):
        return self.mcli.list_deployments()

    def delete_app_ifexisting(self, app_id, trys=4):
        for idx in range(0, trys):
            try:
                a = self.get_app(app_id)
                if a:
                    return self.delete_app(app_id)
                return None
            except:
                e = sys.exc_info()[0]
                pprint("<p>Error: %s</p>" % e)
                time.sleep(10)
        raise

    @staticmethod
    def is_valid_app_id(app_id):
        # allowed: lowercase letters, digits, hyphens, slash, dot
        if re.match("^[A-Za-z0-9-/.]*$", app_id):
            return True
        return False

    def create_app(self, app_id, attr):
        """
            Create and start an app.
            :param app_id: (str) - Application ID
            :param attr: marathon.models.app.MarathonApp application to create.
            :return: the created app
        """
        # Validate that app_id conforms to allowed naming scheme.
        if not self.is_valid_app_id(app_id):
            l.error("Error: Only lowercase letters, digits, hyphens are allowed in app_id. %s" % app_id)
            raise Exception("Invalid app_id")

        for idx in range(0, 10):
            try:
                a = self.mcli.create_app(app_id, attr)
                return a
            except marathon.exceptions.MarathonHttpError as e:
                if str(e).find('App is locked by one or more deployments. Override with the option') >= 0:
                    time.sleep(1)
                else:
                    raise
        raise

    def wait_app_removal(self, app):
        cnt = 0
        while True:
            if not self.get_app(app):
                break
            time.sleep(0.2)
            cnt += 1
            if cnt > 0:
                l.info("Stuck waiting for %s to be deleted CNT=%d" % (app, cnt))
        return True

    def wait_app_ready(self, app, running_count):
        cnt = 0
        while True:
            a1 = self.get_app(app)
            if a1.tasks_running == running_count:
                return a1
            cnt += 1
            time.sleep(1)
            if (cnt % 30) == 29:
                l.info("[%d]Waiting for task to move to running stage, " % cnt +
                       "current stat staged=%d running=%d expected Running=%d" %
                       (a1.tasks_staged, a1.tasks_running, running_count))

    def scale_app(self, app, scale):
        return self.mcli.scale_app(app, scale)

    def ping(self):
        return self.mcli.ping()
开发者ID:annym,项目名称:hydra,代码行数:100,代码来源:mmapi.py

示例5: MarathonIF

# 需要导入模块: from marathon import MarathonClient [as 别名]
# 或者: from marathon.MarathonClient import list_deployments [as 别名]
class MarathonIF(object):
    def __init__(self, marathon_addr, my_addr, mesos):
        self.mcli = MarathonClient(marathon_addr)
        self.myAddr = my_addr
        self.mesos = mesos

    def get_apps(self):
        listapps = self.mcli.list_apps()
        return listapps

    def get_app(self, app_id):
        try:
            a = self.mcli.get_app(app_id)
        except marathon.exceptions.NotFoundError as e:  # NOQA
            return None
        return a

    def delete_app(self, app_id, force=False):
        return self.mcli.delete_app(app_id, force)

    def delete_deployment(self, dep_id):
        return self.mcli.delete_deployment(dep_id)

    def get_deployments(self):
        return self.mcli.list_deployments()

    def delete_app_ifexisting(self, app_id, trys=4):
        for idx in range(0, trys):
            try:
                a = self.get_app(app_id)
                if a:
                    return self.delete_app(app_id)
                return None
            except:
                e = sys.exc_info()[0]
                pprint("<p>Error: %s</p>" % e)
                time.sleep(10)
        raise

    def create_app(self, app_id, attr):
        for idx in range(0, 10):
            try:
                a = self.mcli.create_app(app_id, attr)
                return a
            except marathon.exceptions.MarathonHttpError as e:
                if str(e).find('App is locked by one or more deployments. Override with the option') >= 0:
                    time.sleep(1)
                else:
                    raise
        raise

    def wait_app_removal(self, app):
        cnt = 0
        while True:
            if not self.get_app(app):
                break
            time.sleep(0.2)
            cnt += 1
            if cnt > 0:
                l.info("Stuck waiting for %s to be deleted CNT=%d" % (app, cnt))
        return True

    def wait_app_ready(self, app, running_count):
        cnt = 0
        while True:
            a1 = self.get_app(app)
            if a1.tasks_running == running_count:
                return a1
            cnt += 1
            time.sleep(1)
            if (cnt % 30) == 29:
                l.info("[%d]Waiting for task to move to running stage, " % cnt +
                       "current stat staged=%d running=%d expected Running=%d" %
                       (a1.tasks_staged, a1.tasks_running, running_count))

    def scale_app(self, app, scale):
        return self.mcli.scale_app(app, scale)

    def ping(self):
        return self.mcli.ping()
开发者ID:lorenzodavid,项目名称:hydra,代码行数:82,代码来源:mmapi.py

示例6: MarathonIF

# 需要导入模块: from marathon import MarathonClient [as 别名]
# 或者: from marathon.MarathonClient import list_deployments [as 别名]
class MarathonIF(object):
    def __init__(self, marathon_addr, my_addr, mesos):
        self.mcli = MarathonClient(marathon_addr)
        self.myAddr = my_addr
        self.mesos = mesos

    def get_apps(self):
        listapps = self.mcli.list_apps()
        return listapps

    def get_app(self, app_id, timeout=300):
        st_time = time.time()
        while(time.time() - st_time < timeout):
            try:
                try:
                    a = self.mcli.get_app(app_id)
                except marathon.exceptions.NotFoundError as e:  # NOQA
                    return None
                return a
            except:
                l.info("mcli: get_app returned error")
                l.info(traceback.format_exc())
                l.info("Retrying after 10 secs timeout=%d", timeout)
                time.sleep(10)
        raise Exception("mcli get_app timed out, possible zookeper/marathon/mesos malfunction")

    def delete_app(self, app_id, force=False, timeout=200):
        st_time = time.time()
        while(time.time() - st_time < timeout):
            try:
                self.mcli.delete_app(app_id, force)
                return
            except:
                l.info("mcli: delete_app returned error")
                l.info(traceback.format_exc())
                l.info("Retrying after 10 secs timeout=%d", timeout)
                time.sleep(10)
        raise Exception("mcli delete_app timed out, possible zookeper/marathon/mesos malfunction")

    def delete_deployment(self, dep_id):
        return self.mcli.delete_deployment(dep_id)

    def get_deployments(self):
        return self.mcli.list_deployments()

    def delete_app_ifexisting(self, app_id, trys=4):
        for idx in range(0, trys):
            try:
                a = self.get_app(app_id)
                if a:
                    return self.delete_app(app_id)
                return None
            except:
                e = sys.exc_info()[0]
                pprint("<p>Error: %s</p>" % e)
                time.sleep(10)
        raise

    @staticmethod
    def is_valid_app_id(app_id):
        # allowed: lowercase letters, digits, hyphens, slash, dot
        if re.match("^[A-Za-z0-9-/.]*$", app_id):
            return True
        return False

    def create_app(self, app_id, attr):
        """
            Create and start an app.
            :param app_id: (str) - Application ID
            :param attr: marathon.models.app.MarathonApp application to create.
            :return: the created app
        """
        # Validate that app_id conforms to allowed naming scheme.
        if not self.is_valid_app_id(app_id):
            l.error("Error: Only lowercase letters, digits, hyphens are allowed in app_id. %s" % app_id)
            raise Exception("Invalid app_id")

        for idx in range(0, 10):
            try:
                a = self.mcli.create_app(app_id, attr)
                return a
            except marathon.exceptions.MarathonHttpError as e:
                if str(e).find('App is locked by one or more deployments. Override with the option') >= 0:
                    time.sleep(1)
                else:
                    raise
        raise

    def wait_app_removal(self, app):
        cnt = 0
        while True:
            if not self.get_app(app):
                break
            time.sleep(0.2)
            cnt += 1
            if cnt > 0:
                l.info("Stuck waiting for %s to be deleted CNT=%d" % (app, cnt))
        return True

    def wait_app_ready(self, app, running_count, sleep_before_next_try=1):
#.........这里部分代码省略.........
开发者ID:kratos7,项目名称:hydra,代码行数:103,代码来源:mmapi.py

示例7: ajax_list_deployments

# 需要导入模块: from marathon import MarathonClient [as 别名]
# 或者: from marathon.MarathonClient import list_deployments [as 别名]
def ajax_list_deployments(request):
    mc = MarathonClient('http://{}:{}'.format(settings.MARATHON['host'], settings.MARATHON['port']))
    deployments = mc.list_deployments()
    data = {}
    data['deployments'] = deployments
    return render(request, 'marathon_mgmt/ajax_list_deployments.html', data)
开发者ID:huanpc,项目名称:mesos-admin,代码行数:8,代码来源:views.py


注:本文中的marathon.MarathonClient.list_deployments方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。