forked from HewlettPackard/oneview-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.py
86 lines (67 loc) · 2.67 KB
/
logger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# -*- coding: utf-8 -*-
###
# (C) Copyright [2019] Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###
import logging
from config_loader import try_load_from_file
from hpOneView.oneview_client import OneViewClient
"""
hpOneView do not add any handlers other than NullHandler.
The configuration of handlers is the prerogative of the developer who uses hpOneView library.
This example uses a StreamHandler to send the logging output to streams sys.stdout and sys.stderr.
"""
logger = logging.getLogger('hpOneView')
handler = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s %(levelname)-8s %(name)-12s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
config = {
"ip": "172.16.102.59",
"credentials": {
"userName": "administrator",
"password": ""
}
}
options = {
"name": "OneViewSDK Test FC Network",
"connectionTemplateUri": None,
"autoLoginRedistribution": True,
"fabricType": "FabricAttach",
}
# Try load config from a file (if there is a config file)
config = try_load_from_file(config)
oneview_client = OneViewClient(config)
# Create a FC Network
fc_network = oneview_client.fc_networks.create(options)
# Find recently created network by name
fc_network = oneview_client.fc_networks.get_by('name', 'OneViewSDK Test FC Network')[0]
# Update autoLoginRedistribution from recently created network
fc_network['autoLoginRedistribution'] = False
fc_network = oneview_client.fc_networks.update(fc_network)
# Get all, with defaults
fc_nets = oneview_client.fc_networks.get_all()
# Filter by name
fc_nets_filtered = oneview_client.fc_networks.get_all(filter="\"'name'='OneViewSDK Test FC Network'\"")
# Get all sorting by name descending
fc_nets_sorted = oneview_client.fc_networks.get_all(sort='name:descending')
# Get the first 10 records
fc_nets_limited = oneview_client.fc_networks.get_all(0, 10)
# Get the created network by uri
oneview_client.fc_networks.get(fc_network['uri'])
# Delete the created network
oneview_client.fc_networks.delete(fc_network)
# Get by Id. This Id doesn't exist
oneview_client.fc_networks.get('3518be0e-17c1-4189-8f81-66t3444f6155')