Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.

Commit 525fd44

Browse files
authored
Merge pull request #426 from HewlettPackard/upgrade/800/logical_switch_group
Upgrade/800/logical switch group
2 parents 1b9ff85 + 097309f commit 525fd44

File tree

7 files changed

+90
-237
lines changed

7 files changed

+90
-237
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Resource data will be available with the resource object. This enhancement helps
3434
- Internal link set
3535
- Logical enclosure
3636
- Logical interconnect group
37+
- Logical switch group
3738
- Managed SAN
3839
- SAS interconnect
3940
- SAS interconnect type

endpoints-support.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,12 @@
301301
|<sub>/rest/logical-interconnects/compliance</sub> | POST | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: |:heavy_multiplication_x: |
302302
|<sub>/rest/logical-interconnects/{id}</sub> | PATCH | :heavy_minus_sign: | :white_check_mark: | :white_check_mark: | :heavy_minus_sign: |
303303
| **Logical Switch Groups** |
304-
|<sub>/rest/logical-switch-groups</sub> | GET | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark:
305-
|<sub>/rest/logical-switch-groups</sub> |POST | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark:
306-
|<sub>/rest/logical-switch-groups/{id}</sub> |GET | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark:
307-
|<sub>/rest/logical-switch-groups/{id}</sub> | PATCH | :heavy_minus_sign: | :white_check_mark: | :white_check_mark: | :heavy_minus_sign:
308-
|<sub>/rest/logical-switch-groups/{id}</sub> |PUT | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark:
309-
|<sub>/rest/logical-switch-groups/{id}</sub> |DELETE | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark:
304+
|<sub>/rest/logical-switch-groups</sub> | GET | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
305+
|<sub>/rest/logical-switch-groups</sub> |POST | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
306+
|<sub>/rest/logical-switch-groups/{id}</sub> |GET | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
307+
|<sub>/rest/logical-switch-groups/{id}</sub> | PATCH | :heavy_minus_sign: | :white_check_mark: | :white_check_mark: | :heavy_minus_sign: | :heavy_minus_sign: |
308+
|<sub>/rest/logical-switch-groups/{id}</sub> |PUT | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
309+
|<sub>/rest/logical-switch-groups/{id}</sub> |DELETE | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
310310
| **Logical Switches** |
311311
|<sub>/rest/logical-switches</sub> | GET | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
312312
|<sub>/rest/logical-switches</sub> |POST | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |

examples/logical_switch_groups.py

Lines changed: 39 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
###
3-
# (C) Copyright (2012-2017) Hewlett Packard Enterprise Development LP
3+
# (C) Copyright (2012-2019) Hewlett Packard Enterprise Development LP
44
#
55
# Permission is hereby granted, free of charge, to any person obtaining a copy
66
# of this software and associated documentation files (the "Software"), to deal
@@ -25,7 +25,6 @@
2525
from pprint import pprint
2626

2727
from config_loader import try_load_from_file
28-
from hpOneView.exceptions import HPOneViewException
2928
from hpOneView.oneview_client import OneViewClient
3029

3130
# This resource is only available on C7000 enclosures
@@ -38,11 +37,8 @@
3837
}
3938
}
4039

41-
# To run the get operations by ID, an ID is required.
42-
lsg_id = "ff94bbb5-c5a6-4f10-ac20-11ecf4cd4ecb"
43-
4440
# To run the scope patch operations in this example, a scope name is required.
45-
scope_name = "scope1"
41+
scope_name = "test"
4642

4743
options = {
4844
"name": "OneView Test Logical Switch Group",
@@ -61,90 +57,81 @@
6157

6258
# Try load config from a file (if there is a config file)
6359
config = try_load_from_file(config)
64-
6560
oneview_client = OneViewClient(config)
66-
67-
# Get switch type to use in creation of logical switch group
68-
print("\nGet switch type to use in creation of logical switch group")
69-
switch_type = oneview_client.switch_types.get_all()[0]
70-
print(" Found switch type at uri: '{}'".format(switch_type['uri']))
71-
72-
# Create a logical switch group
73-
print("\nCreate a logical switch group")
74-
options['switchMapTemplate']['switchMapEntryTemplates'][0]['permittedSwitchTypeUri'] = switch_type['uri']
75-
created_lsg = oneview_client.logical_switch_groups.create(options)
76-
print(" Created logical switch group '{name}' at uri: '{uri}'".format(**created_lsg))
61+
logical_switch_groups = oneview_client.logical_switch_groups
62+
switch_types = oneview_client.switch_types
7763

7864
# Get all, with defaults
7965
print("\nGet all Logical Switch Groups")
80-
lsgs = oneview_client.logical_switch_groups.get_all()
66+
lsgs = logical_switch_groups.get_all()
8167
for lsg in lsgs:
8268
print(" '{name}' at uri: '{uri}'".format(**lsg))
8369

8470
# Get the first 10 records, sorting by name descending, filtering by name
8571
print("\nGet the first Logical Switch Groups, sorting by name descending, filtering by name")
86-
lsgs = oneview_client.logical_switch_groups.get_all(
72+
lsgs = logical_switch_groups.get_all(
8773
0, 10, sort='name:descending', filter="\"'name'='OneView Test Logical Switch Group'\"")
8874
for lsg in lsgs:
8975
print(" '{name}' at uri: '{uri}'".format(**lsg))
9076

9177
# Get Logical Switch by property
92-
lsg_getby = oneview_client.logical_switch_groups.get_by('name', 'OneView Test Logical Switch Group')[0]
93-
print("\nFound logical switch group by name: '{name}' at uri = '{uri}'".format(**lsg_getby))
78+
lsg_getby = logical_switch_groups.get_by('name', 'OneView Test Logical Switch Group')
79+
if lsg_getby:
80+
print("\nFound logical switch group by name: '{name}' at uri = '{uri}'".format(**lsg_getby[0]))
81+
82+
print("\nGet a Logical Switch Group by uri")
83+
lsg_byuri = logical_switch_groups.get_by_uri(lsg_getby[0]["uri"])
84+
print(" Found logical switch group '{name}' by uri '{uri}'".format(**lsg_byuri.data))
85+
86+
# Get switch type to use in creation of logical switch group
87+
print("\nGet switch type to use in creation of logical switch group")
88+
switch_type = switch_types.get_by_name("Arista 7060X")
89+
print(" Found switch type at uri: '{}'".format(switch_type.data['uri']))
90+
91+
lsg = logical_switch_groups.get_by_name(options["name"])
92+
if not lsg:
93+
# Create a logical switch group
94+
print("\nCreate a logical switch group")
95+
options['switchMapTemplate']['switchMapEntryTemplates'][0]['permittedSwitchTypeUri'] = switch_type.data['uri']
96+
lsg = oneview_client.logical_switch_groups.create(options)
97+
print(" Created logical switch group '{name}' at uri: '{uri}'".format(**lsg.data))
9498

9599
# Update a logical switch group
96100
print("\nUpdate the name of a logical switch group")
97-
lsg_to_update = created_lsg.copy()
101+
lsg_to_update = lsg.data.copy()
98102
lsg_to_update["name"] = "Renamed Logical Switch Group"
99-
updated_lsg = oneview_client.logical_switch_groups.update(lsg_to_update)
100-
print(" Successfully updated logical switch group with name '{name}'".format(**updated_lsg))
103+
lsg.update(lsg_to_update)
104+
print(" Successfully updated logical switch group with name '{name}'".format(**lsg.data))
101105

102106
# Update a logical switch group by adding another switch with a relative value of 2
103107
print("\nUpdate a logical switch group by adding another switch with a relative value of 2")
104-
lsg_to_update = updated_lsg.copy()
108+
lsg_to_update = lsg.data.copy()
105109
switch_options = {
106110
"logicalLocation": {
107111
"locationEntries": [{
108112
"relativeValue": 2,
109113
"type": "StackingMemberId",
110114
}]
111115
},
112-
"permittedSwitchTypeUri": switch_type['uri']
116+
"permittedSwitchTypeUri": switch_type.data['uri']
113117
}
114118
lsg_to_update['switchMapTemplate']['switchMapEntryTemplates'].append(switch_options)
115-
updated_lsg = oneview_client.logical_switch_groups.update(lsg_to_update)
116-
pprint(updated_lsg)
119+
lsg.update(lsg_to_update)
120+
pprint(lsg.data)
117121

118122
# Get scope to be added
119123
print("\nGet the scope named '%s'." % scope_name)
120124
scope = oneview_client.scopes.get_by_name(scope_name)
121125

122126
# Performs a patch operation on the Logical Switch Group
123-
if scope:
127+
if scope and oneview_client.api_version <= 500:
124128
print("\nPatches the logical switch group assigning the '%s' scope to it." % scope_name)
125-
updated_lsg = oneview_client.logical_switch_groups.patch(updated_lsg['uri'],
126-
'replace',
127-
'/scopeUris',
128-
[scope['uri']])
129-
pprint(updated_lsg)
130-
131-
# Get by ID
132-
try:
133-
print("\nGet a Logical Switch Group by ID '{}'".format(lsg_id))
134-
lsg_byid = oneview_client.logical_switch_groups.get(lsg_id)
135-
print(" Found logical switch group '{name}' by ID at uri '{uri}'".format(**lsg_byid))
136-
except HPOneViewException as e:
137-
print(e.msg)
138-
139-
# Get by uri
140-
try:
141-
print("\nGet a Logical Switch Group by uri")
142-
lsg_byuri = oneview_client.logical_switch_groups.get(created_lsg["uri"])
143-
print(" Found logical switch group '{name}' by uri '{uri}'".format(**lsg_byuri))
144-
except HPOneViewException as e:
145-
print(e.msg)
129+
lsg.patch('replace',
130+
'/scopeUris',
131+
[scope['uri']])
132+
pprint(lsg.data)
146133

147134
# Delete a logical switch group
148135
print("\nDelete the created logical switch group")
149-
oneview_client.logical_switch_groups.delete(updated_lsg)
136+
lsg.delete()
150137
print(" Successfully deleted logical switch group")

hpOneView/oneview_client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,7 @@ def logical_switch_groups(self):
571571
Returns:
572572
LogicalSwitchGroups:
573573
"""
574-
if not self.__logical_switch_groups:
575-
self.__logical_switch_groups = LogicalSwitchGroups(self.__connection)
576-
return self.__logical_switch_groups
574+
return LogicalSwitchGroups(self.__connection)
577575

578576
@property
579577
def logical_switches(self):
Lines changed: 7 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
###
3-
# (C) Copyright (2012-2017) Hewlett Packard Enterprise Development LP
3+
# (C) Copyright (2012-2019) Hewlett Packard Enterprise Development LP
44
#
55
# Permission is hereby granted, free of charge, to any person obtaining a copy
66
# of this software and associated documentation files (the "Software"), to deal
@@ -31,10 +31,10 @@
3131
standard_library.install_aliases()
3232

3333

34-
from hpOneView.resources.resource import ResourceClient
34+
from hpOneView.resources.resource import Resource, ResourcePatchMixin
3535

3636

37-
class LogicalSwitchGroups(object):
37+
class LogicalSwitchGroups(ResourcePatchMixin, Resource):
3838
"""
3939
Logical Switch Groups API client.
4040
@@ -48,129 +48,9 @@ class LogicalSwitchGroups(object):
4848
'200': {"type": "logical-switch-group"},
4949
'300': {"type": "logical-switch-groupV300"},
5050
'500': {"type": "logical-switch-groupV300"},
51-
'600': {"type": "logical-switch-groupV4"}
51+
'600': {"type": "logical-switch-groupV4"},
52+
'800': {"type": "logical-switch-groupV4"}
5253
}
5354

54-
def __init__(self, con):
55-
self._connection = con
56-
self._client = ResourceClient(con, self.URI)
57-
58-
def get_all(self, start=0, count=-1, filter='', sort=''):
59-
"""
60-
Gets a list of logical switch groups based on optional sorting and filtering and is constrained by start
61-
and count parameters.
62-
63-
Args:
64-
start:
65-
The first item to return, using 0-based indexing.
66-
If not specified, the default is 0 - start with the first available item.
67-
count:
68-
The number of resources to return. A count of -1 requests all items.
69-
The actual number of items in the response might differ from the requested
70-
count if the sum of start and count exceeds the total number of items.
71-
filter (list or str):
72-
A general filter/query string to narrow the list of items returned. The
73-
default is no filter; all resources are returned.
74-
sort:
75-
The sort order of the returned data set. By default, the sort order is based
76-
on create time with the oldest entry first.
77-
78-
Returns:
79-
list: A list of logical switch groups.
80-
"""
81-
return self._client.get_all(start, count, filter=filter, sort=sort)
82-
83-
def get(self, id_or_uri):
84-
"""
85-
Gets a logical switch group by ID or by URI.
86-
87-
Args:
88-
id_or_uri: Can be either the logical switch group id or the logical switch group uri.
89-
90-
Returns:
91-
dict: The logical switch group.
92-
"""
93-
return self._client.get(id_or_uri)
94-
95-
def create(self, resource, timeout=-1):
96-
"""
97-
Creates a logical switch group.
98-
99-
Args:
100-
resource (dict): Object to create
101-
timeout:
102-
Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
103-
in OneView; it just stops waiting for its completion.
104-
105-
Returns:
106-
dict: Created logical switch group.
107-
"""
108-
return self._client.create(resource, timeout=timeout, default_values=self.DEFAULT_VALUES)
109-
110-
def update(self, resource, timeout=-1):
111-
"""
112-
Updates a logical switch group.
113-
114-
Args:
115-
resource (dict): Object to update
116-
timeout:
117-
Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
118-
in OneView; it just stops waiting for its completion.
119-
120-
Returns:
121-
dict: Updated logical switch group.
122-
"""
123-
return self._client.update(resource, timeout=timeout, default_values=self.DEFAULT_VALUES)
124-
125-
def delete(self, resource, force=False, timeout=-1):
126-
"""
127-
Deletes a logical switch group.
128-
129-
Args:
130-
resource (dict): object to delete.
131-
force (bool):
132-
If set to true, the operation completes despite any problems with
133-
network connectivity or errors on the resource itself. The default is false.
134-
timeout:
135-
Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
136-
in OneView; it just stops waiting for its completion.
137-
138-
Returns:
139-
bool: Indicates if the resource was successfully deleted.
140-
141-
"""
142-
return self._client.delete(resource, force=force, timeout=timeout)
143-
144-
def get_by(self, field, value):
145-
"""
146-
Gets all Logical switch groups that match the filter.
147-
148-
The search is case-insensitive.
149-
150-
Args:
151-
field: Field name to filter.
152-
value: Value to filter.
153-
154-
Returns:
155-
list: A list of logical switch groups that match the filter.
156-
"""
157-
return self._client.get_by(field, value)
158-
159-
def patch(self, id_or_uri, operation, path, value, timeout=-1):
160-
"""
161-
Uses the PATCH to update a resource for a given logical switch group.
162-
163-
Only one operation can be performed in each PATCH call.
164-
165-
Args:
166-
id_or_uri: Can be either the resource ID or the resource URI.
167-
operation: Patch operation
168-
path: Path
169-
value: Value
170-
timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
171-
in OneView; it just stops waiting for its completion.
172-
173-
Returns:
174-
dict: Updated resource.
175-
"""
176-
return self._client.patch(id_or_uri, operation, path, value, timeout=timeout)
55+
def __init__(self, connection, data=None):
56+
super(LogicalSwitchGroups, self).__init__(connection, data)

0 commit comments

Comments
 (0)