Quantum API support for the ruby-openstack rubygem

As part of work to include Network related resource management the Deltacloud API I added support for the OpenStack Quantum API to the ruby-openstack rubygem. This code will be part of the next release of the rubygem - 1.1.0. For now you need to build the gem from my fork of ruby-openstack and these are some notes for how to try it out:


Build the Rubygem:

Clone from my fork of the repo:

[marios@name Downloads]$ git clone git://github.com/marios/ruby-openstack.git
Cloning into 'ruby-openstack'...
remote: Counting objects: 295, done.
remote: Compressing objects: 100% (155/155), done.
remote: Total 295 (delta 133), reused 282 (delta 126)
Receiving objects: 100% (295/295), 75.52 KiB | 101 KiB/s, done.
Resolving deltas: 100% (133/133), done.

Build the rubygem:

[marios@name Downloads]$ cd ruby-openstack/
[marios@name ruby-openstack]$ gem build openstack.gemspec
Successfully built RubyGem
Name: openstack
Version: 1.1.0
File: openstack-1.1.0.gem

And install:

[marios@name ruby-openstack]$ gem install openstack-1.1.0.gem
Successfully installed openstack-1.1.0
1 gem installed
Installing ri documentation for openstack-1.1.0...
Building YARD (yri) index for openstack-1.1.0...
Installing RDoc documentation for openstack-1.1.0...



Try it out against your Quantum setup:

Using irb, authenticate and get a handle to your Openstack setup. See the README for a full explanation of the parameters - note the use of “network” for “service_type”, specifying that you want a handle to the Quantum service.

[marios@name ~]$ irb -rubygems
irb(main):001:0> require 'openstack'
=> true
irb(main):003:0>  quantum = OpenStack::Connection.create({:username => "admin",
  :api_key=>"le-password", :auth_method=>"password",
  :auth_url => "http://192.168.1.21:5000/v2.0/", :authtenant_name =>"admin",
  :service_type=>"network"})

=> #<OpenStack::Network::Connection:0xa6b0dc8 @connection=#<OpenStack::Connection:0xa6b0f94
    @authuser="admin", @authkey="le-password", @auth_url="http://192.168.1.21:5000/v2.0/",
    @authtenant={:type=>"tenantName", :value=>"admin"}, @auth_method="password",
    @service_name=nil, @service_type="network", @region=nil,
    @regions_list={"RegionOne"=>[{:service=>"image", :versionId=>nil}, {:service=>"compute",
    :versionId=>nil}, {:service=>"ec2", :versionId=>nil}, {:service=>"identity", :versionId=>nil},
     {:service=>"network", :versionId=>nil}]}, @is_debug=nil, @auth_host="192.168.1.21",
    @auth_port=5000, @auth_scheme="http", @auth_path="/v2.0/", @retry_auth=nil, @proxy_host=nil,
    @proxy_port=nil, @authok=true, @http={}, @authtoken="4ac51855458a435089873833b5c225fe",
    @service_host="192.168.1.21", @service_path="/v2.0", @service_port=9696, @service_scheme="http">>

Networks:

Create a Network:

irb(main):016:0> net2 = quantum.create_network("my_net")
=> #<OpenStack::Network::Network:0xa8aff70 @id="6b09a5b3-02d3-4996-9933-4792bd4ca11e",
@name="my_net", @admin_state_up=true, @status="ACTIVE", @subnets=[], @shared=false,
 @tenant_id="7be215d541ea4db4a23b3a84b0882408">

List your Networks:

irb(main):012:0> quantum.networks
=> [#<OpenStack::Network::Network:0xa7c8f94 @id="b4abfaff-9e24-4192-9219-a4a60819aba2",
@name="net_1363343212", @admin_state_up=true, @status="ACTIVE",
@subnets=["34ea9f1e-d71a-48bd-89b0-af2f5c051912",
"7780f890-8334-43a1-934c-f1ce5edc4561"], @shared=false,
@tenant_id="7be215d541ea4db4a23b3a84b0882408">,
#<OpenStack::Network::Network:0xa7c8ef4 @id="1cfad632-3473-4c5b-b2d3-405cc3093286",
@name="net_1363344435", @admin_state_up=true, @status="ACTIVE",
@subnets=["c4293c24-07d0-47dc-bead-ec8d3934b8db"], @shared=false,
@tenant_id="7be215d541ea4db4a23b3a84b0882408">]

irb(main):013:0> net1 = quantum.network("b4abfaff-9e24-4192-9219-a4a60819aba2")
=> #<OpenStack::Network::Network:0xa7f28e4 @id="b4abfaff-9e24-4192-9219-a4a60819aba2",
@name="net_1363343212", @admin_state_up=true, @status="ACTIVE",
@subnets=["34ea9f1e-d71a-48bd-89b0-af2f5c051912",
"7780f890-8334-43a1-934c-f1ce5edc4561"], @shared=false,
@tenant_id="7be215d541ea4db4a23b3a84b0882408">

Delete a Network:

irb(main):017:0> quantum.delete_network("6b09a5b3-02d3-4996-9933-4792bd4ca11e")
=> true

Subnets:

Create a Subnet: - the parameters here are the network_id and cidr

irb(main):030:0> subnet1 = quantum.create_subnet("b4abfaff-9e24-4192-9219-a4a60819aba2",
"192.168.1.0/24")
=> #<OpenStack::Network::Subnet:0xa772a2c @id="e978da1c-9c95-4e58-b4b6-4dcce4640a7f",
@network_id="b4abfaff-9e24-4192-9219-a4a60819aba2", @name="", @ip_version=4,
@cidr="192.168.1.0/24", @gateway_ip="192.168.1.1", @dns_nameservers=[],
@allocation_pools=[{"start"=>"192.168.1.2", "end"=>"192.168.1.254"}], @host_routes=[],
@enable_dhcp=true, @tenant_id="7be215d541ea4db4a23b3a84b0882408">

List Subnets:

irb(main):014:0> quantum.subnets
=> [#<OpenStack::Network::Subnet:0xa850958 @id="34ea9f1e-d71a-48bd-89b0-af2f5c051912",
@network_id="b4abfaff-9e24-4192-9219-a4a60819aba2", @name="", @ip_version=4,
@cidr="123.123.0.0/16", @gateway_ip="123.123.0.1", @dns_nameservers=[],
@allocation_pools=[{"start"=>"123.123.0.2", "end"=>"123.123.255.254"}],
@host_routes=[], @enable_dhcp=true, @tenant_id="7be215d541ea4db4a23b3a84b0882408">,
#<OpenStack::Network::Subnet:0xa850868 @id="7780f890-8334-43a1-934c-f1ce5edc4561",
@network_id="b4abfaff-9e24-4192-9219-a4a60819aba2", @name="", @ip_version=4,
@cidr="192.168.1.0/24", @gateway_ip="192.168.1.1", @dns_nameservers=[],
@allocation_pools=[{"start"=>"192.168.1.2", "end"=>"192.168.1.254"}], @host_routes=[],
@enable_dhcp=true, @tenant_id="7be215d541ea4db4a23b3a84b0882408">]

irb(main):015:0> subnet1 = quantum.subnet("34ea9f1e-d71a-48bd-89b0-af2f5c051912")
=> #<OpenStack::Network::Subnet:0xa88ec1c @id="34ea9f1e-d71a-48bd-89b0-af2f5c051912",
@network_id="b4abfaff-9e24-4192-9219-a4a60819aba2", @name="", @ip_version=4,
@cidr="123.123.0.0/16", @gateway_ip="123.123.0.1", @dns_nameservers=[],
@allocation_pools=[{"start"=>"123.123.0.2", "end"=>"123.123.255.254"}],
@host_routes=[], @enable_dhcp=true, @tenant_id="7be215d541ea4db4a23b3a84b0882408">

Delete a Subnet:

irb(main):023:0> quantum.delete_subnet("89136e4d-da26-4495-9384-0fd1309e274a")
=> true

Ports:

Create a Port - note that the port is created on the specified Network. Furthermore, the “fixed_ips” structure specified the subnet for the port, as well as the’device-id’ which associates that server with this port (and network+subnet):

irb(main):058:0> created_port = quantum.create_port(network.id,
{"fixed_ips"=>[{"subnet_id"=>subnet.id}], "device_id"=>machine.id})

=> #<OpenStack::Network::Port:0x95a833c @id="d601db9e-c936-4811-904a-bb5a27d105f3",
@network_id="c4dfe90e-a7ce-41f7-b9b2-2f9773f42a6b", @name="", @admin_state_up=true,
@status="ACTIVE", @mac_address="fa:16:3e:f4:e8:bc",
@fixed_ips=[{"subnet_id"=>"f78bfc05-ead0-40a6-8325-a35eb2b535c3", "ip_address"=>"10.0.0.4"}],
@device_id="fe4022fa-a77c-4adf-be45-6e069fb3a314", @device_owner="",
@tenant_id="7be215d541ea4db4a23b3a84b0882408">

List all Ports:

irb(main):032:0> quantum.ports
=> [#<OpenStack::Network::Port:0xa73bdd8 @id="f0db2c95-9449-4eb3-8b12-c66b23c8de41",
@network_id="b4abfaff-9e24-4192-9219-a4a60819aba2", @name="", @admin_state_up=true,
@status="ACTIVE", @mac_address="fa:16:3e:7e:e0:1b",
@fixed_ips=[{"subnet_id"=>"34ea9f1e-d71a-48bd-89b0-af2f5c051912",
"ip_address"=>"123.123.0.2"}], @device_id="4357665c-e2fe-4bf0-8a69-b531d11add2d",
@device_owner="compute:nova", @tenant_id="7be215d541ea4db4a23b3a84b0882408">,
#<OpenStack::Network::Port:0xa73bcac @id="93c210cd-b086-49e1-aa12-d207aa28a981",
@network_id="b4abfaff-9e24-4192-9219-a4a60819aba2", @name="", @admin_state_up=true,
@status="ACTIVE", @mac_address="fa:16:3e:08:eb:92",
@fixed_ips=[{"subnet_id"=>"34ea9f1e-d71a-48bd-89b0-af2f5c051912",
"ip_address"=>"123.123.0.3"}], @device_id="5a114ba2-4f49-4655-93f9-96954632cb67",
@device_owner="compute:nova", @tenant_id="7be215d541ea4db4a23b3a84b0882408">]


irb(main):033:0> port1 = quantum.port("f0db2c95-9449-4eb3-8b12-c66b23c8de41")
=> #<OpenStack::Network::Port:0xa70f51c @id="f0db2c95-9449-4eb3-8b12-c66b23c8de41",
@network_id="b4abfaff-9e24-4192-9219-a4a60819aba2", @name="", @admin_state_up=true,
@status="ACTIVE", @mac_address="fa:16:3e:7e:e0:1b",
@fixed_ips=[{"subnet_id"=>"34ea9f1e-d71a-48bd-89b0-af2f5c051912",
"ip_address"=>"123.123.0.2"}], @device_id="4357665c-e2fe-4bf0-8a69-b531d11add2d",
@device_owner="compute:nova", @tenant_id="7be215d541ea4db4a23b3a84b0882408">

Delete a Port:

irb(main):034:0> quantum.delete_port("f0db2c95-9449-4eb3-8b12-c66b23c8de41")
=> true


blog comments powered by Disqus
RSS Feed Icon site.xml
RSS Feed Icon tripleo.xml