Skip to content

Commit c8e6556

Browse files
author
lijianguo
committed
chore(ps):drycc ps:list show autoscale num
1 parent bc5ea75 commit c8e6556

3 files changed

Lines changed: 14 additions & 9 deletions

File tree

rootfs/api/models/app.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,7 @@ def pod_name(size=5, chars=string.ascii_lowercase + string.digits):
923923

924924
def list_pods(self, *args, **kwargs):
925925
"""Used to list basic information about pods running for a given application"""
926+
autoscale = self.appsettings_set.latest().autoscale
926927
try:
927928
labels = self._scheduler_filter(**kwargs)
928929

@@ -935,7 +936,6 @@ def list_pods(self, *args, **kwargs):
935936
pods = []
936937

937938
data = []
938-
exist_pod_type = []
939939
for p in pods:
940940
labels = p['metadata']['labels']
941941
# specifically ignore run pods
@@ -962,9 +962,9 @@ def list_pods(self, *args, **kwargs):
962962
else:
963963
started = str(datetime.utcnow().strftime(settings.DRYCC_DATETIME_FORMAT))
964964
item['started'] = started
965-
item['replicas'] = self.structure.get(labels['type'])
966-
if labels['type'] not in exist_pod_type:
967-
exist_pod_type.append(labels['type'])
965+
replicas = str(autoscale[labels['type']]['min']) + '-' + str(autoscale[labels['type']]['max']) \
966+
if autoscale.get(labels['type']) is not None else self.structure.get(labels['type']) # noqa
967+
item['replicas'] = str(replicas)
968968
data.append(item)
969969

970970
# sorting so latest start date is first

rootfs/api/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ class PodSerializer(serializers.BaseSerializer):
574574
type = serializers.CharField()
575575
release = serializers.CharField(required=False)
576576
started = serializers.DateTimeField(required=False)
577-
replicas = serializers.IntegerField(required=False)
577+
replicas = serializers.CharField(required=False)
578578

579579
def to_representation(self, obj):
580580
return obj

rootfs/api/views.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,18 +342,23 @@ def list(self, *args, **kwargs):
342342
data = self.get_serializer(pods, many=True).data
343343

344344
if not kwargs.get("type"):
345+
autoscale = self.get_app().appsettings_set.latest().autoscale
345346
exist_pod_type = list(set([_["type"] for _ in data if _["type"]]))
346-
for _ in self.get_app().structure.keys():
347+
structure = self.get_app().structure
348+
procfile_structure = self.get_app().procfile_structure
349+
for _ in structure.keys():
347350
if _ not in exist_pod_type:
351+
replicas = str(autoscale[_]['min']) + '-' + str(autoscale[_]['max']) \
352+
if (autoscale.get(_) is not None and structure[_] !=0) else structure[_] # noqa
348353
exist_pod_type.append(_)
349354
data.append({"type": _,
350-
"replicas": self.get_app().structure[_],
355+
"replicas": str(replicas),
351356
"state": "stopped"})
352357

353-
for _ in self.get_app().procfile_structure.keys():
358+
for _ in procfile_structure:
354359
if _ not in exist_pod_type:
355360
data.append({"type": _,
356-
"replicas": 0,
361+
"replicas": str(0),
357362
"state": "started"})
358363

359364
# # fake out pagination for now

0 commit comments

Comments
 (0)