openstacksdk/examples/list.py
Terry Howe b9cc376271 Server IP resource
The server IP resource can only list.  The Resource.list method
needed to be overridden because:
* The url path contains the server_id.
* The output is a dict of networks rather than an array.

Also in this change:
* ServerIP objects have sufficient information to stand on their
  own because they contain the server_id and network_label.
* An ips(session) convenience method has been added to the Server.
* The list example has been updated to pass data to path_args so
  the list method and format the url.

The path_args parameter to list may be convenient for other
classes.  I didn't add it to the Resource.list method because
that isn't required for this change.

Change-Id: Iac77aba144d2e5b4ca4cdbf97e534d83519066ef
2014-08-14 14:33:08 -06:00

33 lines
988 B
Python

# 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 sys
from examples import common
from examples import session
def run_list(opts):
sess = session.make_session(opts)
cls = common.find_resource_cls(opts)
path_args = None
if opts.data:
path_args = common.get_data_option(opts)
for obj in cls.list(sess, path_args=path_args):
print(str(obj))
return
if __name__ == "__main__":
opts = common.setup()
sys.exit(common.main(opts, run_list))