Discussion:
How to attach a volume to the server instance (openstack)?
Igor Karpov
2013-09-10 09:52:19 UTC
Permalink
Hi,

most likely my questions are stupid but I'm stuck

I got no idea how to attach a volume to the server using fog. I tried

v = conn.volumes.create(size: 20, display_name: 'test20', description: 'Fog
Testing')

v.attach(server.id,"vdc")

but get

in `<main>': undefined method `attach' for
#<Fog::Volume::OpenStack::Volume:0x00000001afbfa8> (NoMethodError)

I suspect this is not supposed to work this way but I can't find any
example how to do this right. I am not a programmer so I can't figure it
out by myself.

Regards,
Igor
--
You received this message because you are subscribed to the Google Groups "ruby-fog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-fog+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Kyle Rames
2013-09-10 16:02:08 UTC
Permalink
Hi Igor,

The volume is actually attached from the Compute service rather than the
BlockStorage service. So you will need to do something like the following:

volume_service = Fog::Volume::OpenStack.new VOLUME_SERVICE_CONFIG
compute_service = Fog::Compute::OpenStack.new COMPUTE_SERVICE_CONFIG

v = volume_service.volumes.create(size: 20, display_name: 'test20',
description: 'Fog Testing')

server = compute_service.servers.get SERVER_ID
server.attach_volume v.id, "/dev/xvda"

You will need to replace the values in uppercase with the appropriate
values. Once this has been attached to the server, you should be able to
find it in "/dev/xvda".

Please feel free to reach out to me if you have anymore questions.

Kyle
Post by Igor Karpov
Hi,
most likely my questions are stupid but I'm stuck
I got no idea how to attach a volume to the server using fog. I tried
'Fog Testing')
v.attach(server.id,"vdc")
but get
in `<main>': undefined method `attach' for
#<Fog::Volume::OpenStack::Volume:0x00000001afbfa8> (NoMethodError)
I suspect this is not supposed to work this way but I can't find any
example how to do this right. I am not a programmer so I can't figure it
out by myself.
Regards,
Igor
--
You received this message because you are subscribed to the Google Groups "ruby-fog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-fog+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Igor Karpov
2013-09-11 08:49:53 UTC
Permalink
Hi Kyle!

Thank you for clarification, it works now. I also had to add a volume
status check before trying to attach the volume:

v.reload
while v.status == "creating" do
sleep 5
v.reload
end

As far as I can see, *ready?* can't be applied to the volume status...

Regards,
Igor
Post by Kyle Rames
Hi Igor,
The volume is actually attached from the Compute service rather than the
volume_service = Fog::Volume::OpenStack.new VOLUME_SERVICE_CONFIG
compute_service = Fog::Compute::OpenStack.new COMPUTE_SERVICE_CONFIG
v = volume_service.volumes.create(size: 20, display_name: 'test20',
description: 'Fog Testing')
server = compute_service.servers.get SERVER_ID
server.attach_volume v.id, "/dev/xvda"
You will need to replace the values in uppercase with the appropriate
values. Once this has been attached to the server, you should be able to
find it in "/dev/xvda".
Please feel free to reach out to me if you have anymore questions.
Kyle
Post by Igor Karpov
Hi,
most likely my questions are stupid but I'm stuck
I got no idea how to attach a volume to the server using fog. I tried
'Fog Testing')
v.attach(server.id,"vdc")
but get
in `<main>': undefined method `attach' for
#<Fog::Volume::OpenStack::Volume:0x00000001afbfa8> (NoMethodError)
I suspect this is not supposed to work this way but I can't find any
example how to do this right. I am not a programmer so I can't figure it
out by myself.
Regards,
Igor
--
You received this message because you are subscribed to the Google Groups "ruby-fog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-fog+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Kyle Rames
2013-09-11 13:29:41 UTC
Permalink
Hi!

You're right! I looked through OpenStack's volume code and it does not
appear to implement a ready? method. I will have to fix that!

Your code is looks great, but just so you know fog has a wait_for method
for this exact purpose. You could have written it as follows

v.wait_for { status == 'available' }

This will reload the volume object for you and then evaluate the { status
== 'available' } bock. If that block evaluates to false, wait_for will
sleep 5 seconds and repeat the process. If after 10 minutes the volume is
still not ready it will throw a TimeOut exception.

Kyle
Post by Igor Karpov
Hi Kyle!
Thank you for clarification, it works now. I also had to add a volume
v.reload
while v.status == "creating" do
sleep 5
v.reload
end
As far as I can see, *ready?* can't be applied to the volume status...
Regards,
Igor
Post by Kyle Rames
Hi Igor,
The volume is actually attached from the Compute service rather than the
volume_service = Fog::Volume::OpenStack.new VOLUME_SERVICE_CONFIG
compute_service = Fog::Compute::OpenStack.new COMPUTE_SERVICE_CONFIG
v = volume_service.volumes.create(size: 20, display_name: 'test20',
description: 'Fog Testing')
server = compute_service.servers.get SERVER_ID
server.attach_volume v.id, "/dev/xvda"
You will need to replace the values in uppercase with the appropriate
values. Once this has been attached to the server, you should be able to
find it in "/dev/xvda".
Please feel free to reach out to me if you have anymore questions.
Kyle
Post by Igor Karpov
Hi,
most likely my questions are stupid but I'm stuck
I got no idea how to attach a volume to the server using fog. I tried
'Fog Testing')
v.attach(server.id,"vdc")
but get
in `<main>': undefined method `attach' for
#<Fog::Volume::OpenStack::Volume:0x00000001afbfa8> (NoMethodError)
I suspect this is not supposed to work this way but I can't find any
example how to do this right. I am not a programmer so I can't figure it
out by myself.
Regards,
Igor
--
You received this message because you are subscribed to the Google Groups "ruby-fog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-fog+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Igor Karpov
2013-09-11 14:31:38 UTC
Permalink
Hi!

Thanks, this line looks much better than my status-reload-in-a-while-loop
horror. The point is I am not a programmer (well, I was... twenty five
years ago and I used to use good old C back then). So I have no any
illusion about my ruby code ;)
Post by Kyle Rames
Hi!
You're right! I looked through OpenStack's volume code and it does not
appear to implement a ready? method. I will have to fix that!
Your code is looks great, but just so you know fog has a wait_for method
for this exact purpose. You could have written it as follows
v.wait_for { status == 'available' }
This will reload the volume object for you and then evaluate the { status
== 'available' } bock. If that block evaluates to false, wait_for will
sleep 5 seconds and repeat the process. If after 10 minutes the volume is
still not ready it will throw a TimeOut exception.
Kyle
Post by Igor Karpov
Hi Kyle!
Thank you for clarification, it works now. I also had to add a volume
v.reload
while v.status == "creating" do
sleep 5
v.reload
end
As far as I can see, *ready?* can't be applied to the volume status...
Regards,
Igor
Post by Kyle Rames
Hi Igor,
The volume is actually attached from the Compute service rather than the
volume_service = Fog::Volume::OpenStack.new VOLUME_SERVICE_CONFIG
compute_service = Fog::Compute::OpenStack.new COMPUTE_SERVICE_CONFIG
v = volume_service.volumes.create(size: 20, display_name: 'test20',
description: 'Fog Testing')
server = compute_service.servers.get SERVER_ID
server.attach_volume v.id, "/dev/xvda"
You will need to replace the values in uppercase with the appropriate
values. Once this has been attached to the server, you should be able to
find it in "/dev/xvda".
Please feel free to reach out to me if you have anymore questions.
Kyle
Post by Igor Karpov
Hi,
most likely my questions are stupid but I'm stuck
I got no idea how to attach a volume to the server using fog. I tried
'Fog Testing')
v.attach(server.id,"vdc")
but get
in `<main>': undefined method `attach' for
#<Fog::Volume::OpenStack::Volume:0x00000001afbfa8> (NoMethodError)
I suspect this is not supposed to work this way but I can't find any
example how to do this right. I am not a programmer so I can't figure it
out by myself.
Regards,
Igor
--
You received this message because you are subscribed to the Google Groups "ruby-fog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-fog+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Loading...