Skip to content

Commit ea4b4de

Browse files
author
Art Hall
committed
Releasing version 2.0.1
1 parent 97d49d0 commit ea4b4de

File tree

5 files changed

+234
-1
lines changed

5 files changed

+234
-1
lines changed

CHANGELOG.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on `Keep a Changelog <http://keepachangelog.com/>`_.
66

7+
====================
8+
2.0.1 - 2018-08-09
9+
====================
10+
11+
Added
12+
-----
13+
* Support for fault domains in the Compute service
14+
* A sample showing how to use Search service from the SDK is available on `GitHub <https://github.com/oracle/oci-python-sdk/blob/master/examples/search_example.py>`__.
15+
716
====================
817
2.0.0 - 2018-07-26
918
====================

examples/search_example.py

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# coding: utf-8
2+
# Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
3+
4+
# This example demonstrates how to programatically retrieve resource types and
5+
# query for resources.
6+
#
7+
# The search service documentation can be found here:
8+
# https://docs.cloud.oracle.com/iaas/Content/Search/Concepts/queryoverview.htm
9+
#
10+
# When running this example, it is assumed that you already have active users
11+
# resources associated with your tenant to display the search results.
12+
#
13+
# Querying for resources may be done via a structured query or free text.
14+
# For more information on how to format queries, please refer to
15+
# https://docs.cloud.oracle.com/iaas/Content/Search/Concepts/querysyntax.htm
16+
17+
from __future__ import print_function
18+
import oci
19+
20+
21+
# Load the default configuration
22+
config = oci.config.from_file()
23+
24+
# This is the root compartment. You can use another compartment in your tenancy.
25+
compartment_id = config["tenancy"]
26+
27+
search_client = oci.resource_search.ResourceSearchClient(config)
28+
29+
30+
def resource_types():
31+
# Resource types
32+
# This is will produce a printed list of the resource types and fields
33+
# There are more details available than what is displayed.
34+
print()
35+
print("Resources and their fields")
36+
print("==========================")
37+
response = search_client.list_resource_types()
38+
for resource_type in response.data:
39+
print(resource_type.name)
40+
for field in resource_type.fields:
41+
print("\t {}".format(field.field_name))
42+
43+
44+
def fields_in_instance_resource():
45+
# A more detailed look at the freeformTags field in the Instance resource
46+
print()
47+
print("Instance resource, freeformTags field")
48+
print("=====================================")
49+
response = search_client.list_resource_types()
50+
for resource_type in response.data:
51+
if resource_type.name == "Instance":
52+
instance = resource_type
53+
for field in instance.fields:
54+
print(field)
55+
56+
57+
def field_names_in_instance_resource():
58+
# The details for a single resource type can be retrieved without
59+
# retrieving all the resources.
60+
print()
61+
print("Get a single resource type (Instance) from Search service")
62+
print("=========================================================")
63+
instance = search_client.get_resource_type('Instance').data
64+
fields = [x.field_name for x in instance.fields]
65+
print(fields)
66+
67+
68+
def active_users():
69+
# Get all users which do not have the inactiveStatus set.
70+
# This is the same as "query user resources where lifecycleState = 'ACTIVE'"
71+
print()
72+
print("Get users which are active, using StructuredSearchDetails")
73+
print("=========================================================")
74+
structured_search = oci.resource_search.models.StructuredSearchDetails(query="query user resources where inactiveStatus = 0",
75+
type='Structured',
76+
matching_context_type=oci.resource_search.models.SearchDetails.MATCHING_CONTEXT_TYPE_NONE)
77+
users = search_client.search_resources(structured_search)
78+
79+
for user in users.data.items:
80+
print(user.display_name)
81+
82+
83+
def search_with_free_text():
84+
# Get all resources whose lifecycleState is AVAILABLE
85+
# Using pagination
86+
print("Get resources which are available, using FreeTextSearchDetails")
87+
print("==============================================================")
88+
89+
free_text_search = oci.resource_search.models.FreeTextSearchDetails(text="lifecycleState as AVAILABLE",
90+
type='FreeText',
91+
matching_context_type=oci.resource_search.models.SearchDetails.MATCHING_CONTEXT_TYPE_HIGHLIGHTS)
92+
93+
for response in oci.pagination.list_call_get_all_results_generator(search_client.search_resources, 'response', free_text_search):
94+
for resource in response.data.items:
95+
print("Resource type: {}, Resource name: {}".format(resource.resource_type, resource.display_name))
96+
97+
98+
def users_by_freeformTag(tag):
99+
# Search for user resources with a freeform tag.
100+
print()
101+
print("Get users based on having a freeformTag")
102+
print("=======================================")
103+
structured_search = oci.resource_search.models.StructuredSearchDetails(query="query user resources where freeformTags.key = '{}'".format(tag),
104+
type='Structured',
105+
matching_context_type=oci.resource_search.models.SearchDetails.MATCHING_CONTEXT_TYPE_NONE)
106+
users = search_client.search_resources(structured_search)
107+
108+
for user in users.data.items:
109+
print(user)
110+
111+
112+
def users_by_freeformTag_and_value(tag, value):
113+
# Search for users with a freeform tag set to a particular value.
114+
print()
115+
print("Get users based on having a freeformTag which matches a value")
116+
print("=============================================================")
117+
structured_search = oci.resource_search.models.StructuredSearchDetails(query="query user resources where (freeformTags.key = '{}' && freeformTags.value = '{}')".format(tag, value),
118+
type='Structured',
119+
matching_context_type=oci.resource_search.models.SearchDetails.MATCHING_CONTEXT_TYPE_NONE)
120+
users = search_client.search_resources(structured_search)
121+
122+
for user in users.data.items:
123+
print(user)
124+
125+
126+
# Run examples
127+
resource_types()
128+
fields_in_instance_resource()
129+
field_names_in_instance_resource()
130+
search_with_free_text()
131+
active_users()
132+
133+
# These next examples need to be customized to your situation.
134+
# Let's assume you added a freeform tag "role" to some of your users and
135+
# one of the values is "developer". Then you could replace the
136+
# <your_tag_here> with role and <your_value_here> with developer.
137+
# These examples will then retrieve every user that had the role freeform tag
138+
# and the role freeform tag where the value is set to developer.
139+
# users_by_freeformTag("<your_tag_here>")
140+
# users_by_freeformTag_and_value("<your_tag_here>", "<your_value_here>")

src/oci/core/models/instance.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ def __init__(self, **kwargs):
9191
The value to assign to the extended_metadata property of this Instance.
9292
:type extended_metadata: dict(str, object)
9393
94+
:param fault_domain:
95+
The value to assign to the fault_domain property of this Instance.
96+
:type fault_domain: str
97+
9498
:param freeform_tags:
9599
The value to assign to the freeform_tags property of this Instance.
96100
:type freeform_tags: dict(str, str)
@@ -150,6 +154,7 @@ def __init__(self, **kwargs):
150154
'defined_tags': 'dict(str, dict(str, object))',
151155
'display_name': 'str',
152156
'extended_metadata': 'dict(str, object)',
157+
'fault_domain': 'str',
153158
'freeform_tags': 'dict(str, str)',
154159
'id': 'str',
155160
'image_id': 'str',
@@ -170,6 +175,7 @@ def __init__(self, **kwargs):
170175
'defined_tags': 'definedTags',
171176
'display_name': 'displayName',
172177
'extended_metadata': 'extendedMetadata',
178+
'fault_domain': 'faultDomain',
173179
'freeform_tags': 'freeformTags',
174180
'id': 'id',
175181
'image_id': 'imageId',
@@ -189,6 +195,7 @@ def __init__(self, **kwargs):
189195
self._defined_tags = None
190196
self._display_name = None
191197
self._extended_metadata = None
198+
self._fault_domain = None
192199
self._freeform_tags = None
193200
self._id = None
194201
self._image_id = None
@@ -346,6 +353,42 @@ def extended_metadata(self, extended_metadata):
346353
"""
347354
self._extended_metadata = extended_metadata
348355

356+
@property
357+
def fault_domain(self):
358+
"""
359+
Gets the fault_domain of this Instance.
360+
The name of the Fault Domain the instance is running in.
361+
362+
A Fault Domain is a logical grouping of hardware and infrastructure within an Availability Domain that can become
363+
unavailable in its entirety either due to hardware failure such as Top-of-rack (TOR) switch failure or due to
364+
planned software maintenance such as security updates that reboot your instances.
365+
366+
Example: `FAULT-DOMAIN-1`
367+
368+
369+
:return: The fault_domain of this Instance.
370+
:rtype: str
371+
"""
372+
return self._fault_domain
373+
374+
@fault_domain.setter
375+
def fault_domain(self, fault_domain):
376+
"""
377+
Sets the fault_domain of this Instance.
378+
The name of the Fault Domain the instance is running in.
379+
380+
A Fault Domain is a logical grouping of hardware and infrastructure within an Availability Domain that can become
381+
unavailable in its entirety either due to hardware failure such as Top-of-rack (TOR) switch failure or due to
382+
planned software maintenance such as security updates that reboot your instances.
383+
384+
Example: `FAULT-DOMAIN-1`
385+
386+
387+
:param fault_domain: The fault_domain of this Instance.
388+
:type: str
389+
"""
390+
self._fault_domain = fault_domain
391+
349392
@property
350393
def freeform_tags(self):
351394
"""

src/oci/core/models/launch_instance_details.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ def __init__(self, **kwargs):
4242
The value to assign to the extended_metadata property of this LaunchInstanceDetails.
4343
:type extended_metadata: dict(str, object)
4444
45+
:param fault_domain:
46+
The value to assign to the fault_domain property of this LaunchInstanceDetails.
47+
:type fault_domain: str
48+
4549
:param freeform_tags:
4650
The value to assign to the freeform_tags property of this LaunchInstanceDetails.
4751
:type freeform_tags: dict(str, str)
@@ -82,6 +86,7 @@ def __init__(self, **kwargs):
8286
'defined_tags': 'dict(str, dict(str, object))',
8387
'display_name': 'str',
8488
'extended_metadata': 'dict(str, object)',
89+
'fault_domain': 'str',
8590
'freeform_tags': 'dict(str, str)',
8691
'hostname_label': 'str',
8792
'image_id': 'str',
@@ -99,6 +104,7 @@ def __init__(self, **kwargs):
99104
'defined_tags': 'definedTags',
100105
'display_name': 'displayName',
101106
'extended_metadata': 'extendedMetadata',
107+
'fault_domain': 'faultDomain',
102108
'freeform_tags': 'freeformTags',
103109
'hostname_label': 'hostnameLabel',
104110
'image_id': 'imageId',
@@ -115,6 +121,7 @@ def __init__(self, **kwargs):
115121
self._defined_tags = None
116122
self._display_name = None
117123
self._extended_metadata = None
124+
self._fault_domain = None
118125
self._freeform_tags = None
119126
self._hostname_label = None
120127
self._image_id = None
@@ -294,6 +301,40 @@ def extended_metadata(self, extended_metadata):
294301
"""
295302
self._extended_metadata = extended_metadata
296303

304+
@property
305+
def fault_domain(self):
306+
"""
307+
Gets the fault_domain of this LaunchInstanceDetails.
308+
The name of the Fault Domain in which to launch an instance.
309+
310+
To get a list of Fault Domains, use the :func:`list_fault_domains`
311+
operation in the Identity and Access Management Service API.
312+
313+
Example: `FAULT-DOMAIN-1`
314+
315+
316+
:return: The fault_domain of this LaunchInstanceDetails.
317+
:rtype: str
318+
"""
319+
return self._fault_domain
320+
321+
@fault_domain.setter
322+
def fault_domain(self, fault_domain):
323+
"""
324+
Sets the fault_domain of this LaunchInstanceDetails.
325+
The name of the Fault Domain in which to launch an instance.
326+
327+
To get a list of Fault Domains, use the :func:`list_fault_domains`
328+
operation in the Identity and Access Management Service API.
329+
330+
Example: `FAULT-DOMAIN-1`
331+
332+
333+
:param fault_domain: The fault_domain of this LaunchInstanceDetails.
334+
:type: str
335+
"""
336+
self._fault_domain = fault_domain
337+
297338
@property
298339
def freeform_tags(self):
299340
"""

src/oci/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# coding: utf-8
22
# Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
33

4-
__version__ = "2.0.0"
4+
__version__ = "2.0.1"

0 commit comments

Comments
 (0)