Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.
Open
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# v5.0.0
#### Notes
Major release which supports breaking code changes which will support helper methods implementation

#### Features supported with current release:
- Id pools ipv4 subnet

# 4.7.1
#### Bug fixes
- [#364] (https://github.com/HewlettPackard/python-hpOneView/issues/364) Bug in index_resources.get_all()
Expand Down
10 changes: 5 additions & 5 deletions endpoints-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@
|<sub>/rest/id-pools/ipv4/ranges/{id}/allocated-fragments</sub> | GET | :white_check_mark: | :white_check_mark: |
|<sub>/rest/id-pools/ipv4/ranges/{id}/free-fragments</sub> | GET | :white_check_mark: | :white_check_mark: |
| **ID Pools IPv4 Subnets** |
|<sub>/rest/id-pools/ipv4/subnets</sub> | GET | :white_check_mark: | :white_check_mark: |
|<sub>/rest/id-pools/ipv4/subnets</sub> | POST | :white_check_mark: | :white_check_mark: |
|<sub>/rest/id-pools/ipv4/subnets/{id}</sub> | GET | :white_check_mark: | :white_check_mark: |
|<sub>/rest/id-pools/ipv4/subnets/{id}</sub> | PUT | :white_check_mark: | :white_check_mark: |
|<sub>/rest/id-pools/ipv4/subnets/{id}</sub> | DELETE | :white_check_mark: | :white_check_mark: |
|<sub>/rest/id-pools/ipv4/subnets</sub> | GET | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/id-pools/ipv4/subnets</sub> | POST | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/id-pools/ipv4/subnets/{id}</sub> | GET | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/id-pools/ipv4/subnets/{id}</sub> | PUT | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/id-pools/ipv4/subnets/{id}</sub> | DELETE | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| **ID Pools vMAC Ranges** |
|<sub>/rest/id-pools/vmac/ranges</sub> | POST | :white_check_mark: | :white_check_mark: |
|<sub>/rest/id-pools/vmac/ranges/{id}</sub> | GET | :white_check_mark: | :white_check_mark: |
Expand Down
21 changes: 11 additions & 10 deletions examples/id_pools_ipv4_subnets.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,22 @@
}

print('\n Create IPv4 subnet for id pools')
ipv4_subnet = oneview_client.id_pools_ipv4_subnets.create(options)
pprint(ipv4_subnet)
ipv4_subnet = oneview_client.id_pools_ipv4_subnets.create(data=options)
pprint(ipv4_subnet.data)

print('\n Update IPv4 subnet for id pools')
ipv4_subnet['name'] = 'Changed Name'
ipv4_subnet = oneview_client.id_pools_ipv4_subnets.update(ipv4_subnet)

print('\n Get IPv4 subnet by uri')
ipv4_subnet_byuri = oneview_client.id_pools_ipv4_subnets.get(ipv4_subnet['uri'])
pprint(ipv4_subnet_byuri)
ipv4_subnet.data['name'] = 'Changed Name'
ipv4_subnet = ipv4_subnet.update(data=ipv4_subnet.data)
pprint(ipv4_subnet.data)

print('\n Get all IPv4 subnet')
all_subnets = oneview_client.id_pools_ipv4_subnets.get_all()
all_subnets = ipv4_subnet.get_all()
pprint(all_subnets)

print('\n Get IPv4 subnet by uri')
ipv4_subnet_byuri = oneview_client.id_pools_ipv4_subnets.get_by_uri(ipv4_subnet.data['uri'])
pprint(ipv4_subnet_byuri.data)

print('\n Delete IPv4 subnet')
oneview_client.id_pools_ipv4_subnets.delete(ipv4_subnet)
ipv4_subnet.delete()
print(" Successfully deleted IPv4 subnet")
4 changes: 1 addition & 3 deletions hpOneView/oneview_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,7 @@ def id_pools_ipv4_subnets(self):
Returns:
IdPoolsIpv4Subnets:
"""
if not self.__id_pools_ipv4_subnets:
self.__id_pools_ipv4_subnets = IdPoolsIpv4Subnets(self.__connection)
return self.__id_pools_ipv4_subnets
return IdPoolsIpv4Subnets(self.__connection)

@property
def id_pools(self):
Expand Down
96 changes: 4 additions & 92 deletions hpOneView/resources/servers/id_pools_ipv4_subnets.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,103 +29,15 @@

standard_library.install_aliases()

from hpOneView.resources.resource import ResourceClient
from hpOneView.resources.resource import Resource


class IdPoolsIpv4Subnets(object):
class IdPoolsIpv4Subnets(Resource):
"""
The ID pools IPv4 subnets resource provides a Client API for managing IPv4 subnets.
"""

URI = '/rest/id-pools/ipv4/subnets'

def __init__(self, con):
self._client = ResourceClient(con, self.URI)

def create(self, resource, timeout=-1):
"""
Creates subnet.

Args:
resource (dict): Object to create
timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView; it just stops waiting for its completion.

Returns:
dict: Created subnet.
"""
return self._client.create(resource, timeout=timeout)

def get_all(self, start=0, count=-1, filter='', sort=''):
"""
Gets a list of IPV4 Subnet resources. Returns a list of resources based on optional sorting and filtering,
and constrained by start and count parameters.

Args:
start:
The first item to return, using 0-based indexing.
If not specified, the default is 0 - start with the first available item.
count:
The number of resources to return. A count of -1 requests all items.
The actual number of items in the response might differ from the requested
count if the sum of start and count exceeds the total number of items.
filter (list or str):
A general filter/query string to narrow the list of items returned. The
default is no filter; all resources are returned.
sort:
The sort order of the returned data set. By default, the sort order is based
on create time with the oldest entry first.

Returns:
list: A list of IPV4 Subnet resources.
"""
return self._client.get_all(start, count, filter=filter, sort=sort)

def get(self, id_or_uri):
"""
Gets an IPv4 subnet.

Using the allocator and collector associated with the subnet, IDs may be allocated from or collected back to the
subnet.

Args:
id_or_uri: Can be either the subnet ID or URI.

Returns:
dict: IPv4 subnet.
"""
return self._client.get(id_or_uri)

def update(self, resource, timeout=-1):
"""
Update the resource.

Args:
resource (dict): Information to update.
timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView; it just stops waiting for its completion.

Returns:
dict: Updated resource.
"""

return self._client.update(resource, timeout=timeout)

def delete(self, resource, force=False, timeout=-1):
"""
Deletes the IPv4 subnet.

Args:
resource (dict):
Object to delete
force (bool):
If set to true, the operation completes despite any problems with
network connectivity or errors on the resource itself. The default is false.
timeout:
Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView; it just stops waiting for its completion.

Returns:
bool: Indicates if the resource was successfully deleted.
"""
return self._client.delete(resource, force=force, timeout=timeout)
def __init__(self, connection, options=None):
super(IdPoolsIpv4Subnets, self).__init__(connection, options)
53 changes: 30 additions & 23 deletions tests/unit/resources/servers/test_id_pools_ipv4_subnets.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,52 +23,59 @@
import mock
import unittest
from hpOneView.connection import connection
from hpOneView.resources.resource import ResourceClient
from hpOneView.resources.resource import Resource
from hpOneView.resources.servers.id_pools_ipv4_subnets import IdPoolsIpv4Subnets


class TestIdPoolsIpv4Subnets(unittest.TestCase):
resource_info = {'type': 'Range',
'name': 'No name'}
example_uri = "/rest/id-pools/ipv4/subnets/f0a0a113-ec97-41b4-83ce-d7c92b900e7c"

def setUp(self):
self.host = '127.0.0.1'
self.connection = connection(self.host)
self.client = IdPoolsIpv4Subnets(self.connection)
self.example_uri = "/rest/id-pools/ipv4/subnets/f0a0a113-ec97-41b4-83ce-d7c92b900e7c"
self.client.data = {'uri': "/rest/id-pools/ipv4/subnets/f0a0a113-ec97-41b4-83ce-d7c92b900e7c"}

@mock.patch.object(ResourceClient, 'create')
@mock.patch.object(Resource, 'create')
def test_create_called_once(self, mock_create):
self.client.create(self.resource_info)
mock_create.assert_called_once_with(self.resource_info, timeout=-1)
mock_create.assert_called_once_with(self.resource_info)

@mock.patch.object(ResourceClient, 'get')
def test_get_by_id_called_once(self, mock_get):
@mock.patch.object(Resource, 'load_resource')
@mock.patch.object(Resource, 'get_by_uri')
def test_get_by_id_called_once(self, mock_get_by_uri, load_resource):
id_pools_subnet_id = "f0a0a113-ec97-41b4-83ce-d7c92b900e7c"
self.client.get(id_pools_subnet_id)
mock_get.assert_called_once_with(id_pools_subnet_id)
self.client.get_by_uri(id_pools_subnet_id)
mock_get_by_uri.assert_called_once_with(id_pools_subnet_id)

@mock.patch.object(ResourceClient, 'get')
def test_get_by_uri_called_once(self, mock_get):
self.client.get(self.example_uri)
mock_get.assert_called_once_with(self.example_uri)
@mock.patch.object(Resource, 'load_resource')
@mock.patch.object(Resource, 'get_by_uri')
def test_get_by_uri_called_once(self, mock_get_by_uri, load_resource):
self.client.get_by_uri(self.example_uri)
mock_get_by_uri.assert_called_once_with(self.example_uri)

@mock.patch.object(ResourceClient, 'update')
def test_enable_called_once(self, update):
@mock.patch.object(Resource, 'load_resource')
@mock.patch.object(Resource, 'update')
def test_enable_called_once(self, update, load_resource):
self.client.update(self.resource_info.copy())
update.assert_called_once_with(self.resource_info.copy(), timeout=-1)
update.assert_called_once_with(self.resource_info.copy())

@mock.patch.object(ResourceClient, 'get_all')
def test_get_allocated_fragments_called_once_with_defaults(self, mock_get):
@mock.patch.object(Resource, 'load_resource')
@mock.patch.object(Resource, 'get_all')
def test_get_allocated_fragments_called_once_with_defaults(self, mock_get, load_resource):
self.client.get_all(self.example_uri)
mock_get.assert_called_once_with(self.example_uri, -1, filter='', sort='')
mock_get.assert_called_once_with(self.example_uri)

@mock.patch.object(ResourceClient, 'delete')
def test_delete_called_once(self, mock_delete):
@mock.patch.object(Resource, 'load_resource')
@mock.patch.object(Resource, 'delete')
def test_delete_called_once(self, mock_delete, load_resource):
self.client.delete({'uri': '/rest/uri'}, force=True, timeout=50)
mock_delete.assert_called_once_with({'uri': '/rest/uri'}, force=True, timeout=50)

@mock.patch.object(ResourceClient, 'delete')
def test_delete_called_once_with_defaults(self, mock_delete):
@mock.patch.object(Resource, 'load_resource')
@mock.patch.object(Resource, 'delete')
def test_delete_called_once_with_defaults(self, mock_delete, load_resource):
self.client.delete({'uri': '/rest/uri'})
mock_delete.assert_called_once_with({'uri': '/rest/uri'}, force=False, timeout=-1)
mock_delete.assert_called_once_with({'uri': '/rest/uri'})
4 changes: 0 additions & 4 deletions tests/unit/test_oneview_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,10 +539,6 @@ def test_id_pools_ipv4_ranges_lazy_loading(self):
def test_id_pools_ipv4_subnets_has_right_type(self):
self.assertIsInstance(self._oneview.id_pools_ipv4_subnets, IdPoolsIpv4Subnets)

def test_id_pools_ipv4_subnets_lazy_loading(self):
id_pools_ipv4_subnets = self._oneview.id_pools_ipv4_subnets
self.assertEqual(id_pools_ipv4_subnets, self._oneview.id_pools_ipv4_subnets)

def test_id_pools_has_right_type(self):
self.assertIsInstance(self._oneview.id_pools, IdPools)

Expand Down