Skip to content

Commit 07eca3b

Browse files
authored
Merge pull request #309 from oracle/release_2020-11-24
Releasing version 2.24.1
2 parents f663b9a + afcd143 commit 07eca3b

15 files changed

+1032
-22
lines changed

CHANGELOG.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ Change Log
33
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/>`_.
6+
====================
7+
2.24.1 - 2020-11-24
8+
====================
9+
10+
Added
11+
-----
12+
* Provide example for pagination that creates a *Details object for pagination
13+
* Provide example to turn response and model to JSON
14+
15+
Security
16+
-----
17+
* cryptography pinning to cryptography=3.2.1 to address vulnerability `Github security alerts <https://github.com/oracle/oci-python-sdk/pull/299>`__
18+
619
====================
720
2.24.0 - 2020-11-17
821
====================

examples/json_response_example.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# coding: utf-8
2+
# Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
3+
# This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
4+
5+
# This script provides an example to demostrate converting a response payload to a json string.
6+
# For more information see: https://docs.python.org/3/library/json.html
7+
import oci
8+
import json
9+
10+
# Load the default configuration
11+
config = oci.config.from_file()
12+
identity_client = oci.identity.IdentityClient(config)
13+
response = identity_client.list_regions().data
14+
15+
# Convert the response to a json string
16+
json_response = json.dumps(str(response))
17+
print("My json string response: ", json_response)

examples/object_storage/object_storage_bulk_copy.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# -dt - Use Instance Principals with delegation token for cloud shell
2222
# -sb source_bucket
2323
# -sr source_region
24+
# -sn source_namespace
2425
# -sp source_prefix_include
2526
# -se source_prefix_exclude
2627
# -db destination_bucket
@@ -52,10 +53,12 @@
5253
parser.add_argument('-c', type=argparse.FileType('r'), dest='config_file', help="Config File (default=~/.oci/config)")
5354
parser.add_argument('-sb', default="", dest='source_bucket', help='Source Bucket Name')
5455
parser.add_argument('-sr', default="", dest='source_region', help='Source Region (Default current connection)')
56+
parser.add_argument('-sn', default="", dest='source_namespace', help='Source Namespace (Default current connection)')
5557
parser.add_argument('-sp', default="", dest='source_prefix_include', help='Source Prefix Include')
5658
parser.add_argument('-se', default="", dest='source_prefix_exclude', help='Source Prefix Exclude')
5759
parser.add_argument('-db', default="", dest='destination_bucket', help='Destination Bucket Name')
5860
parser.add_argument('-dr', default="", dest='destination_region', help='Destination Region')
61+
parser.add_argument('-dn', default="", dest='destination_namespace', help='Destination Namespace (Default current connection)')
5962
parser.add_argument('-ig', action='store_true', default=False, dest='ignore_exist', help='Ignore Check if files exist at Destination')
6063
cmd = parser.parse_args()
6164

@@ -88,11 +91,11 @@
8891
# Global Variables
8992
object_storage_client = None
9093
object_storage_client_dest = None
91-
destination_namespace = ""
92-
source_namespace = ""
9394

9495
source_bucket = cmd.source_bucket
9596
source_region = cmd.source_region
97+
source_namespace = cmd.source_namespace
98+
destination_namespace = cmd.destination_namespace
9699
source_prefix = cmd.source_prefix_include
97100
source_prefix_exclude = cmd.source_prefix_exclude
98101
destination_bucket = cmd.destination_bucket
@@ -446,7 +449,8 @@ def connect_to_object_storage():
446449
object_storage_client.base_client.session.proxies = {'https': cmd.proxy}
447450

448451
# retrieve namespace from object storage
449-
source_namespace = object_storage_client.get_namespace().data
452+
if not source_namespace:
453+
source_namespace = object_storage_client.get_namespace().data
450454
print("Succeed.")
451455

452456
except Exception as e:
@@ -463,7 +467,8 @@ def connect_to_object_storage():
463467
object_storage_client_dest.base_client.session.proxies = {'https': cmd.proxy}
464468

465469
# retrieve namespace from object storage
466-
destination_namespace = object_storage_client_dest.get_namespace().data
470+
if not destination_namespace:
471+
destination_namespace = object_storage_client_dest.get_namespace().data
467472
print("Succeed.")
468473

469474
except Exception as e:

examples/object_storage/object_storage_bulk_delete.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
parser.add_argument('-c', type=argparse.FileType('r'), dest='config_file', help="Config File (default=~/.oci/config)")
4848
parser.add_argument('-sb', default="", dest='source_bucket', help='Source Bucket Name')
4949
parser.add_argument('-sp', default="", dest='source_prefix', help='Source Prefix Include')
50+
parser.add_argument('-se', default="", dest='source_prefix_exclude', help='Source Prefix Exclude')
51+
parser.add_argument('-exclude_dirs', action='store_true', default=False, dest='source_exclude_dirs', help='Exclude Directories')
5052
parser.add_argument('-sr', default="", dest='source_region', help='Source Region')
5153
cmd = parser.parse_args()
5254

@@ -78,7 +80,9 @@
7880
source_namespace = ""
7981
source_bucket = cmd.source_bucket
8082
source_prefix = cmd.source_prefix
83+
source_prefix_exclude = cmd.source_prefix_exclude
8184
source_region = cmd.source_region
85+
source_exclude_dirs = cmd.source_exclude_dirs
8286

8387
# Update Variables based on the parameters
8488
config_file = (cmd.config_file if cmd.config_file else oci.config.DEFAULT_LOCATION)
@@ -187,7 +191,10 @@ def print_command_info():
187191
print("Source Namespace : " + source_namespace)
188192
print("Source Bucket : " + source_bucket)
189193
print("Source Prefix Include : " + source_prefix)
194+
print("Source Prefix Exclude : " + source_prefix_exclude)
190195
print("Source Region : " + source_region)
196+
if source_exclude_dirs:
197+
print("Source Exclude Dirs : True")
191198

192199

193200
##############################################################################
@@ -237,6 +244,11 @@ def add_objects_to_queue(ns, source_bucket):
237244
next_starts_with = response.data.next_start_with
238245

239246
for object_ in response.data.objects:
247+
if source_prefix_exclude and object_.name.startswith(source_prefix_exclude):
248+
continue
249+
if source_exclude_dirs and "/" in object_.name:
250+
continue
251+
240252
q.put(object_.name)
241253
count += 1
242254

examples/object_storage/object_storage_list_objects.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
# -co - count only
2323
# -f - write to file
2424
# -sb source_bucket
25-
# -sp source_prefix
25+
# -sp source_prefix_include
26+
# -se source_prefix_exclude
2627
# -sr source_region
2728
##########################################################################
2829
import oci
@@ -44,7 +45,9 @@
4445
parser.add_argument('-c', type=argparse.FileType('r'), dest='config_file', help="Config File (default=~/.oci/config)")
4546
parser.add_argument('-sb', default="", dest='source_bucket', help='Source Bucket Name')
4647
parser.add_argument('-sp', default="", dest='source_prefix', help='Source Prefix Include')
48+
parser.add_argument('-se', default="", dest='source_prefix_exclude', help='Source Prefix Exclude')
4749
parser.add_argument('-sr', default="", dest='source_region', help='Source Region')
50+
parser.add_argument('-exclude_dirs', action='store_true', default=False, dest='source_exclude_dirs', help='Exclude Directories')
4851
parser.add_argument('-f', type=argparse.FileType('w'), dest='file', help="Output to file (as csv)")
4952
parser.add_argument('-co', action='store_true', default=False, dest='count_only', help='Count only files and size')
5053
cmd = parser.parse_args()
@@ -160,11 +163,14 @@ def print_header(name):
160163
def print_command_info(source_namespace):
161164
print_header("Running List/Count Objects")
162165
print("Written By Adi Zohar, June 2020")
163-
print("Starts at :" + get_time(full=True))
164-
print("Command Line : " + ' '.join(x for x in sys.argv[1:]))
165-
print("Source Namespace: " + source_namespace)
166-
print("Source Bucket : " + cmd.source_bucket)
167-
print("Source Prefix : " + cmd.source_prefix)
166+
print("Starts at :" + get_time(full=True))
167+
print("Command Line : " + ' '.join(x for x in sys.argv[1:]))
168+
print("Source Namespace : " + source_namespace)
169+
print("Source Bucket : " + cmd.source_bucket)
170+
print("Source Prefix : " + cmd.source_prefix)
171+
print("Source Pre-Exclude : " + cmd.source_prefix_exclude)
172+
if cmd.source_exclude_dirs:
173+
print("Source Exclude Dirs : True")
168174

169175

170176
##############################################################################
@@ -175,6 +181,8 @@ def main():
175181
source_namespace = None
176182
source_bucket = cmd.source_bucket
177183
source_prefix = cmd.source_prefix
184+
source_prefix_exclude = cmd.source_prefix_exclude
185+
source_exclude_dirs = cmd.source_exclude_dirs
178186

179187
# get signer
180188
config, signer = create_signer(cmd.config_file, cmd.config_profile, cmd.is_instance_principals, cmd.is_delegation_token)
@@ -222,6 +230,11 @@ def main():
222230
next_starts_with = response.data.next_start_with
223231

224232
for object_file in response.data.objects:
233+
if source_prefix_exclude and object_file.name.startswith(source_prefix_exclude):
234+
continue
235+
if source_exclude_dirs and "/" in object_file.name:
236+
continue
237+
225238
count += 1
226239
size += object_file.size
227240

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# coding: utf-8
2+
# Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
3+
# This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
4+
5+
# This script gives an example on passing in a request model for an API to the pagination call.
6+
7+
import oci
8+
9+
config = oci.config.from_file()
10+
compartment_id = config["tenancy"]
11+
monitoring = oci.monitoring.MonitoringClient(config)
12+
13+
paginated_response = oci.pagination.list_call_get_all_results(
14+
monitoring.list_metrics,
15+
compartment_id,
16+
oci.monitoring.models.ListMetricsDetails() # Request model passed in as specified from monitoring.ListMetricsDetail API
17+
).data
18+
19+
print("paginated response: ", paginated_response)

examples/showoci/CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ 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+
20.11.24 - 20.11.24
9+
=====================
10+
* Added multiple VCN CIDR blocks
11+
712
=====================
813
20.11.17 - 20.11.17
914
=====================

examples/showoci/showoci.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
import argparse
9292
import datetime
9393

94-
version = "20.11.17"
94+
version = "20.11.24"
9595

9696
##########################################################################
9797
# check OCI version

examples/showoci/showoci_data.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,9 @@ def __get_core_network_vcn(self, region_name, compartment):
839839
'name': vcn['name'],
840840
'display_name': vcn['display_name'],
841841
'cidr_block': vcn['cidr_block'],
842+
'cidr_blocks': vcn['cidr_blocks'],
843+
'ipv6_cidr_block': vcn['ipv6_cidr_block'],
844+
'ipv6_public_cidr_block': vcn['ipv6_public_cidr_block'],
842845
'compartment_name': str(compartment['name']),
843846
'compartment_id': str(compartment['id']),
844847
'data': val})

examples/showoci/showoci_service.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def is_load_basic_network(self):
133133
# class ShowOCIService
134134
##########################################################################
135135
class ShowOCIService(object):
136-
oci_compatible_version = "2.23.4"
136+
oci_compatible_version = "2.23.5"
137137

138138
##########################################################################
139139
# Global Constants
@@ -1851,13 +1851,18 @@ def __load_core_network_vcn(self, virtual_network, compartments):
18511851
# loop on the array
18521852
# vcn = oci.core.models.Vcn()
18531853
for vcn in vcns:
1854-
val = {'id': str(vcn.id), 'name': str(vcn.cidr_block) + " - " + str(vcn.display_name) + " - " + str(vcn.vcn_domain_name),
1854+
val = {'id': str(vcn.id), 'name': str(', '.join(x for x in vcn.cidr_blocks)) + " - " + str(vcn.display_name) + " - " + str(vcn.vcn_domain_name),
18551855
'display_name': str(vcn.display_name),
18561856
'cidr_block': str(vcn.cidr_block),
1857-
'time_created': str(vcn.time_created), 'compartment_name': str(compartment['name']),
1857+
'cidr_blocks': vcn.cidr_blocks,
1858+
'ipv6_cidr_block': str(vcn.ipv6_cidr_block),
1859+
'ipv6_public_cidr_block': str(vcn.ipv6_public_cidr_block),
1860+
'time_created': str(vcn.time_created),
1861+
'compartment_name': str(compartment['name']),
18581862
'defined_tags': [] if vcn.defined_tags is None else vcn.defined_tags,
18591863
'freeform_tags': [] if vcn.freeform_tags is None else vcn.freeform_tags,
1860-
'compartment_id': str(compartment['id']), 'region_name': str(self.config['region'])}
1864+
'compartment_id': str(compartment['id']),
1865+
'region_name': str(self.config['region'])}
18611866
data.append(val)
18621867
cnt += 1
18631868

@@ -2751,7 +2756,7 @@ def __load_core_network_subnet(self, virtual_network, compartments, vcns):
27512756
for vcn in vcns:
27522757
if str(subnet.vcn_id) == vcn['id']:
27532758
val['vcn_name'] = vcn['display_name']
2754-
val['vcn_cidr'] = vcn['cidr_block']
2759+
val['vcn_cidr'] = str(', '.join(x for x in vcn['cidr_blocks']))
27552760

27562761
data.append(val)
27572762
cnt += 1
@@ -4663,7 +4668,10 @@ def __load_load_balancers(self, load_balancer, compartments):
46634668
raise
46644669

46654670
# add the rest
4666-
val = {'id': str(arr.id), 'shape_name': str(arr.shape_name), 'display_name': str(arr.display_name), 'is_private': str(arr.is_private),
4671+
val = {'id': str(arr.id),
4672+
'shape_name': str(arr.shape_name),
4673+
'display_name': str(arr.display_name),
4674+
'is_private': str(arr.is_private),
46674675
'status': str(status),
46684676
'ip_addresses': [(str(ip.ip_address) + " - " + ("Public" if ip.is_public else "Private")) for ip in arr.ip_addresses],
46694677
'compartment_name': str(compartment['name']),
@@ -4672,7 +4680,8 @@ def __load_load_balancers(self, load_balancer, compartments):
46724680
'nsg_names': "",
46734681
'defined_tags': [] if arr.defined_tags is None else arr.defined_tags,
46744682
'freeform_tags': [] if arr.freeform_tags is None else arr.freeform_tags,
4675-
'region_name': str(self.config['region']), 'subnet_ids': []}
4683+
'region_name': str(self.config['region']),
4684+
'subnet_ids': []}
46764685

46774686
# subnets
46784687
if arr.subnet_ids:

0 commit comments

Comments
 (0)