Class: OsCtl::Image::Operations::Builder::WaitForNetwork
- Inherits:
-
OsCtl::Image::Operations::Base
- Object
- OsCtl::Image::Operations::Base
- OsCtl::Image::Operations::Builder::WaitForNetwork
- Defined in:
- lib/osctl/image/operations/builder/wait_for_network.rb
Instance Attribute Summary collapse
- #builder ⇒ Builder readonly
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(builder) ⇒ WaitForNetwork
constructor
A new instance of WaitForNetwork.
Methods inherited from OsCtl::Image::Operations::Base
Constructor Details
#initialize(builder) ⇒ WaitForNetwork
Returns a new instance of WaitForNetwork.
9 10 11 12 |
# File 'lib/osctl/image/operations/builder/wait_for_network.rb', line 9 def initialize(builder) super() @builder = builder end |
Instance Attribute Details
#builder ⇒ Builder (readonly)
6 7 8 |
# File 'lib/osctl/image/operations/builder/wait_for_network.rb', line 6 def builder @builder end |
Instance Method Details
#execute ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/osctl/image/operations/builder/wait_for_network.rb', line 14 def execute script = <<~EOF #!/bin/sh test_network() { curl --head https://images.vpsadminos.org > /dev/null 2>&1 [ $? = 0 ] && return 0 wget -q -O - https://images.vpsadminos.org > /dev/null 2>&1 [ $? = 0 ] && return 0 ping -c 1 images.vpsadminos.org > /dev/null 2>&1 [ $? = 0 ] && return 0 return 1 } test_network if [ $? != 0 ] ; then echo -n "Waiting for network..." for i in $(seq 1 60); do test_network && exit 0 echo -n "." sleep 1 done exit 1 else echo "Network online" fi EOF rc = Operations::Builder::ControlledRunscript.run( builder, script:, name: 'osctl-image.wait-for-network' ) return unless rc != 0 raise OperationError, "network setup failed with exit status #{rc}" end |