Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.

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

====================
2.0.1 - 2018-08-09
====================

Added
-----
* Support for fault domains in the Compute service
* 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>`__.

====================
2.0.0 - 2018-07-26
====================
Expand Down
140 changes: 140 additions & 0 deletions examples/search_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# coding: utf-8
# Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.

# This example demonstrates how to programatically retrieve resource types and
# query for resources.
#
# The search service documentation can be found here:
# https://docs.cloud.oracle.com/iaas/Content/Search/Concepts/queryoverview.htm
#
# When running this example, it is assumed that you already have active users
# resources associated with your tenant to display the search results.
#
# Querying for resources may be done via a structured query or free text.
# For more information on how to format queries, please refer to
# https://docs.cloud.oracle.com/iaas/Content/Search/Concepts/querysyntax.htm

from __future__ import print_function
import oci


# Load the default configuration
config = oci.config.from_file()

# This is the root compartment. You can use another compartment in your tenancy.
compartment_id = config["tenancy"]

search_client = oci.resource_search.ResourceSearchClient(config)


def resource_types():
# Resource types
# This is will produce a printed list of the resource types and fields
# There are more details available than what is displayed.
print()
print("Resources and their fields")
print("==========================")
response = search_client.list_resource_types()
for resource_type in response.data:
print(resource_type.name)
for field in resource_type.fields:
print("\t {}".format(field.field_name))


def fields_in_instance_resource():
# A more detailed look at the freeformTags field in the Instance resource
print()
print("Instance resource, freeformTags field")
print("=====================================")
response = search_client.list_resource_types()
for resource_type in response.data:
if resource_type.name == "Instance":
instance = resource_type
for field in instance.fields:
print(field)


def field_names_in_instance_resource():
# The details for a single resource type can be retrieved without
# retrieving all the resources.
print()
print("Get a single resource type (Instance) from Search service")
print("=========================================================")
instance = search_client.get_resource_type('Instance').data
fields = [x.field_name for x in instance.fields]
print(fields)


def active_users():
# Get all users which do not have the inactiveStatus set.
# This is the same as "query user resources where lifecycleState = 'ACTIVE'"
print()
print("Get users which are active, using StructuredSearchDetails")
print("=========================================================")
structured_search = oci.resource_search.models.StructuredSearchDetails(query="query user resources where inactiveStatus = 0",
type='Structured',
matching_context_type=oci.resource_search.models.SearchDetails.MATCHING_CONTEXT_TYPE_NONE)
users = search_client.search_resources(structured_search)

for user in users.data.items:
print(user.display_name)


def search_with_free_text():
# Get all resources whose lifecycleState is AVAILABLE
# Using pagination
print("Get resources which are available, using FreeTextSearchDetails")
print("==============================================================")

free_text_search = oci.resource_search.models.FreeTextSearchDetails(text="lifecycleState as AVAILABLE",
type='FreeText',
matching_context_type=oci.resource_search.models.SearchDetails.MATCHING_CONTEXT_TYPE_HIGHLIGHTS)

for response in oci.pagination.list_call_get_all_results_generator(search_client.search_resources, 'response', free_text_search):
for resource in response.data.items:
print("Resource type: {}, Resource name: {}".format(resource.resource_type, resource.display_name))


def users_by_freeformTag(tag):
# Search for user resources with a freeform tag.
print()
print("Get users based on having a freeformTag")
print("=======================================")
structured_search = oci.resource_search.models.StructuredSearchDetails(query="query user resources where freeformTags.key = '{}'".format(tag),
type='Structured',
matching_context_type=oci.resource_search.models.SearchDetails.MATCHING_CONTEXT_TYPE_NONE)
users = search_client.search_resources(structured_search)

for user in users.data.items:
print(user)


def users_by_freeformTag_and_value(tag, value):
# Search for users with a freeform tag set to a particular value.
print()
print("Get users based on having a freeformTag which matches a value")
print("=============================================================")
structured_search = oci.resource_search.models.StructuredSearchDetails(query="query user resources where (freeformTags.key = '{}' && freeformTags.value = '{}')".format(tag, value),
type='Structured',
matching_context_type=oci.resource_search.models.SearchDetails.MATCHING_CONTEXT_TYPE_NONE)
users = search_client.search_resources(structured_search)

for user in users.data.items:
print(user)


# Run examples
resource_types()
fields_in_instance_resource()
field_names_in_instance_resource()
search_with_free_text()
active_users()

# These next examples need to be customized to your situation.
# Let's assume you added a freeform tag "role" to some of your users and
# one of the values is "developer". Then you could replace the
# <your_tag_here> with role and <your_value_here> with developer.
# These examples will then retrieve every user that had the role freeform tag
# and the role freeform tag where the value is set to developer.
# users_by_freeformTag("<your_tag_here>")
# users_by_freeformTag_and_value("<your_tag_here>", "<your_value_here>")
43 changes: 43 additions & 0 deletions src/oci/core/models/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def __init__(self, **kwargs):
The value to assign to the extended_metadata property of this Instance.
:type extended_metadata: dict(str, object)

:param fault_domain:
The value to assign to the fault_domain property of this Instance.
:type fault_domain: str

:param freeform_tags:
The value to assign to the freeform_tags property of this Instance.
:type freeform_tags: dict(str, str)
Expand Down Expand Up @@ -150,6 +154,7 @@ def __init__(self, **kwargs):
'defined_tags': 'dict(str, dict(str, object))',
'display_name': 'str',
'extended_metadata': 'dict(str, object)',
'fault_domain': 'str',
'freeform_tags': 'dict(str, str)',
'id': 'str',
'image_id': 'str',
Expand All @@ -170,6 +175,7 @@ def __init__(self, **kwargs):
'defined_tags': 'definedTags',
'display_name': 'displayName',
'extended_metadata': 'extendedMetadata',
'fault_domain': 'faultDomain',
'freeform_tags': 'freeformTags',
'id': 'id',
'image_id': 'imageId',
Expand All @@ -189,6 +195,7 @@ def __init__(self, **kwargs):
self._defined_tags = None
self._display_name = None
self._extended_metadata = None
self._fault_domain = None
self._freeform_tags = None
self._id = None
self._image_id = None
Expand Down Expand Up @@ -346,6 +353,42 @@ def extended_metadata(self, extended_metadata):
"""
self._extended_metadata = extended_metadata

@property
def fault_domain(self):
"""
Gets the fault_domain of this Instance.
The name of the Fault Domain the instance is running in.

A Fault Domain is a logical grouping of hardware and infrastructure within an Availability Domain that can become
unavailable in its entirety either due to hardware failure such as Top-of-rack (TOR) switch failure or due to
planned software maintenance such as security updates that reboot your instances.

Example: `FAULT-DOMAIN-1`


:return: The fault_domain of this Instance.
:rtype: str
"""
return self._fault_domain

@fault_domain.setter
def fault_domain(self, fault_domain):
"""
Sets the fault_domain of this Instance.
The name of the Fault Domain the instance is running in.

A Fault Domain is a logical grouping of hardware and infrastructure within an Availability Domain that can become
unavailable in its entirety either due to hardware failure such as Top-of-rack (TOR) switch failure or due to
planned software maintenance such as security updates that reboot your instances.

Example: `FAULT-DOMAIN-1`


:param fault_domain: The fault_domain of this Instance.
:type: str
"""
self._fault_domain = fault_domain

@property
def freeform_tags(self):
"""
Expand Down
41 changes: 41 additions & 0 deletions src/oci/core/models/launch_instance_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def __init__(self, **kwargs):
The value to assign to the extended_metadata property of this LaunchInstanceDetails.
:type extended_metadata: dict(str, object)

:param fault_domain:
The value to assign to the fault_domain property of this LaunchInstanceDetails.
:type fault_domain: str

:param freeform_tags:
The value to assign to the freeform_tags property of this LaunchInstanceDetails.
:type freeform_tags: dict(str, str)
Expand Down Expand Up @@ -82,6 +86,7 @@ def __init__(self, **kwargs):
'defined_tags': 'dict(str, dict(str, object))',
'display_name': 'str',
'extended_metadata': 'dict(str, object)',
'fault_domain': 'str',
'freeform_tags': 'dict(str, str)',
'hostname_label': 'str',
'image_id': 'str',
Expand All @@ -99,6 +104,7 @@ def __init__(self, **kwargs):
'defined_tags': 'definedTags',
'display_name': 'displayName',
'extended_metadata': 'extendedMetadata',
'fault_domain': 'faultDomain',
'freeform_tags': 'freeformTags',
'hostname_label': 'hostnameLabel',
'image_id': 'imageId',
Expand All @@ -115,6 +121,7 @@ def __init__(self, **kwargs):
self._defined_tags = None
self._display_name = None
self._extended_metadata = None
self._fault_domain = None
self._freeform_tags = None
self._hostname_label = None
self._image_id = None
Expand Down Expand Up @@ -294,6 +301,40 @@ def extended_metadata(self, extended_metadata):
"""
self._extended_metadata = extended_metadata

@property
def fault_domain(self):
"""
Gets the fault_domain of this LaunchInstanceDetails.
The name of the Fault Domain in which to launch an instance.

To get a list of Fault Domains, use the :func:`list_fault_domains`
operation in the Identity and Access Management Service API.

Example: `FAULT-DOMAIN-1`


:return: The fault_domain of this LaunchInstanceDetails.
:rtype: str
"""
return self._fault_domain

@fault_domain.setter
def fault_domain(self, fault_domain):
"""
Sets the fault_domain of this LaunchInstanceDetails.
The name of the Fault Domain in which to launch an instance.

To get a list of Fault Domains, use the :func:`list_fault_domains`
operation in the Identity and Access Management Service API.

Example: `FAULT-DOMAIN-1`


:param fault_domain: The fault_domain of this LaunchInstanceDetails.
:type: str
"""
self._fault_domain = fault_domain

@property
def freeform_tags(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/oci/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# coding: utf-8
# Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.

__version__ = "2.0.0"
__version__ = "2.0.1"