|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | ### |
3 | | -# (C) Copyright (2012-2017) Hewlett Packard Enterprise Development LP |
| 3 | +# (C) Copyright (2012-2019) Hewlett Packard Enterprise Development LP |
4 | 4 | # |
5 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
6 | 6 | # of this software and associated documentation files (the "Software"), to deal |
|
25 | 25 | from pprint import pprint |
26 | 26 |
|
27 | 27 | from config_loader import try_load_from_file |
28 | | -from hpOneView.exceptions import HPOneViewException |
29 | 28 | from hpOneView.oneview_client import OneViewClient |
30 | 29 |
|
31 | 30 | config = { |
|
38 | 37 |
|
39 | 38 | # Try load config from a file (if there is a config file) |
40 | 39 | config = try_load_from_file(config) |
41 | | - |
42 | 40 | oneview_client = OneViewClient(config) |
| 41 | +logical_interconnect_groups = oneview_client.logical_interconnect_groups |
| 42 | +interconnect_types = oneview_client.interconnect_types |
43 | 43 |
|
44 | 44 | # Define the scope name to add the logical interconnect group to it |
45 | 45 | scope_name = "" |
46 | 46 |
|
47 | | -# Get the interconnect type named 'HP VC FlexFabric 10Gb/24-Port Module' and using the uri in the values for the fields |
| 47 | +interconnect_type_name = "Synergy 10Gb Interconnect Link Module" |
| 48 | +# Get the interconnect type by name and using the uri in the values for the fields |
48 | 49 | # "permittedInterconnectTypeUri" and create a Logical Interconnect Group. |
49 | 50 | # Note: If this type does not exist, select another name |
50 | | -interconnect_type = oneview_client.interconnect_types.get_by('name', 'HP VC FlexFabric 10Gb/24-Port Module')[0]['uri'] |
| 51 | +interconnect_type = oneview_client.interconnect_types.get_by_name(interconnect_type_name) |
| 52 | +if interconnect_type: |
| 53 | + pprint(interconnect_type.data) |
| 54 | + interconnect_type_url = interconnect_type.data["uri"] |
51 | 55 |
|
52 | 56 | options = { |
53 | 57 | "category": None, |
|
76 | 80 | } |
77 | 81 | ] |
78 | 82 | }, |
79 | | - "permittedInterconnectTypeUri": interconnect_type |
| 83 | + "permittedInterconnectTypeUri": interconnect_type_url |
80 | 84 | }, |
81 | 85 | { |
82 | 86 | "logicalDownlinkUri": None, |
|
193 | 197 | } |
194 | 198 | } |
195 | 199 |
|
196 | | -# Create a logical interconnect group |
197 | | -print("Create a logical interconnect group") |
198 | | -created_lig = oneview_client.logical_interconnect_groups.create(options) |
199 | | -pprint(created_lig) |
| 200 | +# Get all, with defaults |
| 201 | +print("Get all Logical Interconnect Groups") |
| 202 | +ligs = logical_interconnect_groups.get_all() |
| 203 | +pprint(ligs) |
| 204 | + |
| 205 | +# Get by uri |
| 206 | +print("Get a Logical Interconnect Group by uri") |
| 207 | +lig_byuri = logical_interconnect_groups.get_by_uri(ligs[0]["uri"]) |
| 208 | +pprint(lig_byuri.data) |
200 | 209 |
|
201 | 210 | # Get the first 10 records, sorting by name descending, filtering by name |
202 | 211 | print("Get the first Logical Interconnect Groups, sorting by name descending, filtering by name") |
203 | | -ligs = oneview_client.logical_interconnect_groups.get_all( |
| 212 | +ligs = logical_interconnect_groups.get_all( |
204 | 213 | 0, 10, sort='name:descending', filter="\"'name'='OneView Test Logical Interconnect Group'\"") |
205 | 214 | pprint(ligs) |
206 | 215 |
|
207 | 216 | # Get Logical Interconnect Group by property |
208 | | -lig = oneview_client.logical_interconnect_groups.get_by('name', 'OneView Test Logical Interconnect Group')[0] |
| 217 | +lig = logical_interconnect_groups.get_by('name', 'SYN-LIG')[0] |
209 | 218 | print("Found lig by name: '%s'.\n uri = '%s'" % (lig['name'], lig['uri'])) |
210 | 219 |
|
| 220 | +# Get Logical Interconnect Group by scope_uris |
| 221 | +if oneview_client.api_version >= 600: |
| 222 | + lig_by_scope_uris = logical_interconnect_groups.get_all(scope_uris="\"'/rest/scopes/3bb0c754-fd38-45af-be8a-4d4419de06e9'\"") |
| 223 | + if len(lig_by_scope_uris) > 0: |
| 224 | + print("Found %d Logical Interconnect Groups" % (len(lig_by_scope_uris))) |
| 225 | + i = 0 |
| 226 | + while i < len(lig_by_scope_uris): |
| 227 | + print("Found Logical Interconnect Group by scope_uris: '%s'.\n uri = '%s'" % (lig_by_scope_uris[i]['name'], lig_by_scope_uris[i]['uri'])) |
| 228 | + i += 1 |
| 229 | + pprint(lig_by_scope_uris) |
| 230 | + else: |
| 231 | + print("No Logical Interconnect Group found.") |
| 232 | + |
| 233 | +# Get logical interconnect group by name |
| 234 | +lig = logical_interconnect_groups.get_by_name(options["name"]) |
| 235 | +if not lig: |
| 236 | + # Create a logical interconnect group |
| 237 | + print("Create a logical interconnect group") |
| 238 | + lig = logical_interconnect_groups.create(options) |
| 239 | + pprint(lig.data) |
| 240 | + |
211 | 241 | # Update a logical interconnect group |
212 | 242 | print("Update a logical interconnect group") |
213 | | -lig_to_update = created_lig.copy() |
| 243 | +lig_to_update = lig.data.copy() |
214 | 244 | lig_to_update["name"] = "Renamed Logical Interconnect Group" |
215 | | -updated_lig = oneview_client.logical_interconnect_groups.update(lig_to_update) |
216 | | -pprint(updated_lig) |
217 | | - |
218 | | -# Get all, with defaults |
219 | | -print("Get all Logical Interconnect Groups") |
220 | | -ligs = oneview_client.logical_interconnect_groups.get_all() |
221 | | -pprint(ligs) |
222 | | - |
223 | | -# Get by Id |
224 | | -try: |
225 | | - print("Get a Logical Interconnect Group by id") |
226 | | - lig_byid = oneview_client.logical_interconnect_groups.get('f0a0a113-ec97-41b4-83ce-d7c92b900e7c') |
227 | | - pprint(lig_byid) |
228 | | -except HPOneViewException as e: |
229 | | - print(e.msg) |
230 | | - |
231 | | -# Get by uri |
232 | | -try: |
233 | | - print("Get a Logical Interconnect Group by uri") |
234 | | - lig_byuri = oneview_client.logical_interconnect_groups.get(created_lig["uri"]) |
235 | | - pprint(lig_byuri) |
236 | | -except HPOneViewException as e: |
237 | | - print(e.msg) |
| 245 | +lig.update(lig_to_update) |
| 246 | +pprint(lig.data) |
238 | 247 |
|
239 | 248 | # Performs a patch operation |
240 | | -scope = oneview_client.scopes.get_by_name(scope_name) |
241 | | -if scope: |
242 | | - print("\nPatches the logical interconnect group adding one scope to it") |
243 | | - updated_lig = oneview_client.logical_interconnect_groups.patch(updated_lig['uri'], |
244 | | - 'replace', |
245 | | - '/scopeUris', |
246 | | - [scope['uri']]) |
247 | | - pprint(updated_lig) |
| 249 | +if oneview_client.api_version <= 500: |
| 250 | + scope = oneview_client.scopes.get_by_name(scope_name) |
| 251 | + if scope: |
| 252 | + print("\nPatches the logical interconnect group adding one scope to it") |
| 253 | + updated_lig = lig.patch('replace', |
| 254 | + '/scopeUris', |
| 255 | + [scope['uri']]) |
| 256 | + pprint(updated_lig.data) |
248 | 257 |
|
249 | 258 | # Get default settings |
250 | 259 | print("Get the default interconnect settings for a logical interconnect group") |
251 | | -lig_default_settings = oneview_client.logical_interconnect_groups.get_default_settings() |
| 260 | +lig_default_settings = lig.get_default_settings() |
252 | 261 | pprint(lig_default_settings) |
253 | 262 |
|
254 | 263 | # Get settings |
255 | 264 | print("Gets the interconnect settings for a logical interconnect group") |
256 | | -lig_settings = oneview_client.logical_interconnect_groups.get_settings(created_lig["uri"]) |
| 265 | +lig_settings = lig.get_settings() |
257 | 266 | pprint(lig_settings) |
258 | 267 |
|
259 | | -# Get Logical Interconnect Group by scope_uris |
260 | | -if oneview_client.api_version >= 600: |
261 | | - lig_by_scope_uris = oneview_client.logical_interconnect_groups.get_all(scope_uris="\"'/rest/scopes/3bb0c754-fd38-45af-be8a-4d4419de06e9'\"") |
262 | | - if len(lig_by_scope_uris) > 0: |
263 | | - print("Found %d Logical Interconnect Groups" % (len(lig_by_scope_uris))) |
264 | | - i = 0 |
265 | | - while i < len(lig_by_scope_uris): |
266 | | - print("Found Logical Interconnect Group by scope_uris: '%s'.\n uri = '%s'" % (lig_by_scope_uris[i]['name'], lig_by_scope_uris[i]['uri'])) |
267 | | - i += 1 |
268 | | - pprint(lig_by_scope_uris) |
269 | | - else: |
270 | | - print("No Logical Interconnect Group found.") |
271 | | - |
272 | 268 | # Delete a logical interconnect group |
273 | 269 | print("Delete the created logical interconnect group") |
274 | | -oneview_client.logical_interconnect_groups.delete(updated_lig) |
| 270 | +lig.delete() |
275 | 271 | print("Successfully deleted logical interconnect group") |
0 commit comments