OpenStack Compute (Nova) Client
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tenant_networks.py 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # Copyright 2013 OpenStack Foundation
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from novaclient import base
  15. from novaclient.i18n import _
  16. from novaclient.openstack.common import cliutils
  17. from novaclient import utils
  18. class TenantNetwork(base.Resource):
  19. def delete(self):
  20. self.manager.delete(network=self)
  21. class TenantNetworkManager(base.ManagerWithFind):
  22. resource_class = base.Resource
  23. def list(self):
  24. return self._list('/os-tenant-networks', 'networks')
  25. def get(self, network):
  26. return self._get('/os-tenant-networks/%s' % base.getid(network),
  27. 'network')
  28. def delete(self, network):
  29. self._delete('/os-tenant-networks/%s' % base.getid(network))
  30. def create(self, label, cidr):
  31. body = {'network': {'label': label, 'cidr': cidr}}
  32. return self._create('/os-tenant-networks', body, 'network')
  33. @cliutils.arg('network_id', metavar='<network_id>', help='ID of network')
  34. def do_net(cs, args):
  35. """
  36. Show a network
  37. """
  38. network = cs.tenant_networks.get(args.network_id)
  39. utils.print_dict(network._info)
  40. def do_net_list(cs, args):
  41. """
  42. List networks
  43. """
  44. networks = cs.tenant_networks.list()
  45. utils.print_list(networks, ['ID', 'Label', 'CIDR'])
  46. @cliutils.arg(
  47. 'label',
  48. metavar='<network_label>',
  49. help=_('Network label (ex. my_new_network)'))
  50. @cliutils.arg(
  51. 'cidr',
  52. metavar='<cidr>',
  53. help=_('IP block to allocate from (ex. 172.16.0.0/24 or 2001:DB8::/64)'))
  54. def do_net_create(cs, args):
  55. """
  56. Create a network
  57. """
  58. network = cs.tenant_networks.create(args.label, args.cidr)
  59. utils.print_dict(network._info)
  60. @cliutils.arg('network_id', metavar='<network_id>', help='ID of network')
  61. def do_net_delete(cs, args):
  62. """
  63. Delete a network
  64. """
  65. cs.tenant_networks.delete(args.network_id)