Query all machine groups in a specific project
Call the ListMachineGroup operation to query all machine groups in a specific project.
Prerequisites
-
Simple Log Service is activated. For more information, see Activate Simple Log Service.
-
The Simple Log Service SDK for Python is initialized. For more information, see Initialize Simple Log Service SDK for Python.
Parameters
def list_machine_group(self, project_name, offset=0, size=100):
Request parameters
|
Parameter |
Type |
Required |
Description |
|
project_name |
String |
Yes |
The name of the project. The project in Simple Log Service is used to isolate the resources of different users and control access to specific resources. See Manage projects. |
|
offset |
int |
No |
The line from which the query starts. Default value: 0. |
|
size |
int |
No |
The number of entries per page. Default value: 100. Maximum: 500. |
Response parameters
For details about the response parameters, see ListMachineGroup.
Sample code
from aliyun.log import LogClient
import os
# In this example, the AccessKey ID and AccessKey secret are obtained from environment variables.
access_key_id = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', '')
access_key_secret = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', '')
# The Simple Log Service endpoint.
endpoint = "cn-hangzhou.log.aliyuncs.com"
# Create an instance of the LogClient class.
client = LogClient(endpoint, access_key_id, access_key_secret)
project_name = "proj-test-1"
def main():
# Query all machine groups.
res = client.list_machine_group(project_name)
res.log_print()
if __name__ == '__main__':
main()
Sample response
ListMachineGroupResponse:
headers: {'Server': 'AliyunSLS', 'Content-Type': 'application/json', 'Content-Length': '62', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Tue, 15 Oct 2024 03:34:26 GMT', 'x-log-time': '1728963266', 'x-log-requestid': '670DE2C2B33AF4059C93****'}
count: 2
total: 2
machine_groups: ['group-1', 'group-2']
References
-
Use the following APIs to manage machine groups: