|
30 | 30 |
|
31 | 31 | from gcloud.client import JSONClient |
32 | 32 | from gcloud.monitoring.connection import Connection |
| 33 | +from gcloud.monitoring.group import Group |
33 | 34 | from gcloud.monitoring.metric import MetricDescriptor |
34 | 35 | from gcloud.monitoring.metric import MetricKind |
35 | 36 | from gcloud.monitoring.metric import ValueType |
@@ -282,3 +283,82 @@ def list_resource_descriptors(self, filter_string=None): |
282 | 283 | https://cloud.google.com/monitoring/api/v3/filters |
283 | 284 | """ |
284 | 285 | return ResourceDescriptor._list(self, filter_string) |
| 286 | + |
| 287 | + def group(self, group_id=None, display_name=None, parent_id=None, |
| 288 | + filter_string=None, is_cluster=False): |
| 289 | + """Factory constructor for group object. |
| 290 | +
|
| 291 | + .. note:: |
| 292 | + This will not make an HTTP request; it simply instantiates |
| 293 | + a group object owned by this client. |
| 294 | +
|
| 295 | + :type group_id: string or None |
| 296 | + :param group_id: The ID of the group. |
| 297 | +
|
| 298 | + :type display_name: string or None |
| 299 | + :param display_name: |
| 300 | + A user-assigned name for this group, used only for display |
| 301 | + purposes. |
| 302 | +
|
| 303 | + :type parent_id: string or None |
| 304 | + :param parent_id: |
| 305 | + The ID of the group's parent, if it has one. |
| 306 | +
|
| 307 | + :type filter_string: string or None |
| 308 | + :param filter_string: |
| 309 | + The filter string used to determine which monitored resources |
| 310 | + belong to this group. |
| 311 | +
|
| 312 | + :type is_cluster: boolean |
| 313 | + :param is_cluster: |
| 314 | + If true, the members of this group are considered to be a cluster. |
| 315 | + The system can perform additional analysis on groups that are |
| 316 | + clusters. |
| 317 | +
|
| 318 | + :rtype: :class:`Group` |
| 319 | + :returns: The group created with the passed-in arguments. |
| 320 | +
|
| 321 | + :raises: |
| 322 | + :exc:`ValueError` if both ``group_id`` and ``name`` are specified. |
| 323 | + """ |
| 324 | + return Group( |
| 325 | + self, |
| 326 | + group_id=group_id, |
| 327 | + display_name=display_name, |
| 328 | + parent_id=parent_id, |
| 329 | + filter_string=filter_string, |
| 330 | + is_cluster=is_cluster, |
| 331 | + ) |
| 332 | + |
| 333 | + def fetch_group(self, group_id): |
| 334 | + """Fetch a group from the API based on it's ID. |
| 335 | +
|
| 336 | + Example:: |
| 337 | +
|
| 338 | + >>> try: |
| 339 | + >>> group = client.fetch_group('1234') |
| 340 | + >>> except gcloud.exceptions.NotFound: |
| 341 | + >>> print('That group does not exist!') |
| 342 | +
|
| 343 | + :type group_id: string |
| 344 | + :param group_id: The ID of the group. |
| 345 | +
|
| 346 | + :rtype: :class:`~gcloud.monitoring.group.Group` |
| 347 | + :returns: The group instance. |
| 348 | +
|
| 349 | + :raises: :class:`gcloud.exceptions.NotFound` if the group is not found. |
| 350 | + """ |
| 351 | + return Group._fetch(self, group_id) |
| 352 | + |
| 353 | + def list_groups(self): |
| 354 | + """List all groups for the project. |
| 355 | +
|
| 356 | + Example:: |
| 357 | +
|
| 358 | + >>> for group in client.list_groups(): |
| 359 | + ... print((group.display_name, group.name)) |
| 360 | +
|
| 361 | + :rtype: list of :class:`~gcloud.monitoring.group.Group` |
| 362 | + :returns: A list of group instances. |
| 363 | + """ |
| 364 | + return Group._list(self) |
0 commit comments