vagrant-1cloud 1.0.8 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/vagrant-1cloud/actions.rb +67 -51
- data/lib/vagrant-1cloud/actions/create.rb +2 -2
- data/lib/vagrant-1cloud/actions/destroy.rb +1 -0
- data/lib/vagrant-1cloud/actions/private_network.rb +10 -1
- data/lib/vagrant-1cloud/commands/add_network.rb +59 -0
- data/lib/vagrant-1cloud/helpers/client.rb +37 -0
- data/lib/vagrant-1cloud/plugin.rb +5 -0
- data/lib/vagrant-1cloud/version.rb +1 -1
- data/locales/en.yml +1 -0
- metadata +3 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: f707ed0657b4714d685b8430fc3b29b8d941373e
         | 
| 4 | 
            +
              data.tar.gz: e3366df7e2408f5932631877ec9cbbf5c9b8fbc8
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 9651c55c3be75ea4d99ca8577f6a205f3231f0930fef12bb4361824bcda99b9cf0e17bf53fe001f783fc0f843341c12fb160bea43c89520d5bfae3a1f2ba3e7a
         | 
| 7 | 
            +
              data.tar.gz: d31e13aadf3cd4eeb66efc5b02d7425873d3035a1674da296c15ed71207599df852768d6f31b45cce04f67d9a8a85897876831a43a979a89d8133d7b877d8d0c
         | 
    
        data/README.md
    CHANGED
    
    | @@ -12,6 +12,7 @@ Features include: | |
| 12 12 | 
             
            - Setup a SSH public key for authentication
         | 
| 13 13 | 
             
            - Create a new user account during VPS creation
         | 
| 14 14 | 
             
            - Create private network
         | 
| 15 | 
            +
            - Add VPS to private network
         | 
| 15 16 | 
             
            - Rebuild VPS
         | 
| 16 17 |  | 
| 17 18 |  | 
| @@ -97,6 +98,7 @@ The provider supports the following Vagrant sub-commands: | |
| 97 98 | 
             
            - `vagrant reload` - Reboots the VPS instance.
         | 
| 98 99 | 
             
            - `vagrant status` - Outputs the status (active, off, not created) for the VPS instance.
         | 
| 99 100 | 
             
            - `vagrant create-network` - Creates private network.
         | 
| 101 | 
            +
            - `vagrant add-network` - Adds VPS to specified private network.
         | 
| 100 102 | 
             
            - `vagrant rebuild` - Rebuilds the VPS.
         | 
| 101 103 |  | 
| 102 104 | 
             
            Troubleshooting
         | 
| @@ -22,15 +22,15 @@ module VagrantPlugins | |
| 22 22 | 
             
                      builder.use ConfigValidate
         | 
| 23 23 | 
             
                      builder.use Call, CheckState do |env, b|
         | 
| 24 24 | 
             
                        case env[:machine_state]
         | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 25 | 
            +
                          when :not_created
         | 
| 26 | 
            +
                            env[:ui].info I18n.t('vagrant_1cloud.info.not_created')
         | 
| 27 | 
            +
                          else
         | 
| 28 | 
            +
                            b.use Call, DestroyConfirm do |env2, b2|
         | 
| 29 | 
            +
                              if env2[:result]
         | 
| 30 | 
            +
                                b2.use Destroy
         | 
| 31 | 
            +
                                b2.use ProvisionerCleanup if defined?(ProvisionerCleanup)
         | 
| 32 | 
            +
                              end
         | 
| 32 33 | 
             
                            end
         | 
| 33 | 
            -
                          end
         | 
| 34 34 | 
             
                        end
         | 
| 35 35 | 
             
                      end
         | 
| 36 36 | 
             
                    end
         | 
| @@ -41,12 +41,12 @@ module VagrantPlugins | |
| 41 41 | 
             
                      builder.use ConfigValidate
         | 
| 42 42 | 
             
                      builder.use Call, CheckState do |env, b|
         | 
| 43 43 | 
             
                        case env[:machine_state]
         | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
             | 
| 44 | 
            +
                          when :Active
         | 
| 45 | 
            +
                            b.use SSHExec
         | 
| 46 | 
            +
                          when :off
         | 
| 47 | 
            +
                            env[:ui].info I18n.t('vagrant_1cloud.info.off')
         | 
| 48 | 
            +
                          when :not_created
         | 
| 49 | 
            +
                            env[:ui].info I18n.t('vagrant_1cloud.info.not_created')
         | 
| 50 50 | 
             
                        end
         | 
| 51 51 | 
             
                      end
         | 
| 52 52 | 
             
                    end
         | 
| @@ -73,14 +73,30 @@ module VagrantPlugins | |
| 73 73 | 
             
                      builder.use ConfigValidate
         | 
| 74 74 | 
             
                      builder.use Call, CheckState do |env, b|
         | 
| 75 75 | 
             
                        case env[:machine_state]
         | 
| 76 | 
            -
             | 
| 77 | 
            -
             | 
| 78 | 
            -
             | 
| 79 | 
            -
             | 
| 80 | 
            -
             | 
| 81 | 
            -
             | 
| 82 | 
            -
             | 
| 83 | 
            -
             | 
| 76 | 
            +
                          when :Active
         | 
| 77 | 
            +
                            b.use Provision
         | 
| 78 | 
            +
                            b.use ModifyProvisionPath
         | 
| 79 | 
            +
                            b.use SyncedFolders
         | 
| 80 | 
            +
                          when :off
         | 
| 81 | 
            +
                            env[:ui].info I18n.t('vagrant_1cloud.info.off')
         | 
| 82 | 
            +
                          when :not_created
         | 
| 83 | 
            +
                            env[:ui].info I18n.t('vagrant_1cloud.info.not_created')
         | 
| 84 | 
            +
                        end
         | 
| 85 | 
            +
                      end
         | 
| 86 | 
            +
                    end
         | 
| 87 | 
            +
                  end
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                  def self.addnet
         | 
| 90 | 
            +
                    return Vagrant::Action::Builder.new.tap do |builder|
         | 
| 91 | 
            +
                      builder.use ConfigValidate
         | 
| 92 | 
            +
                      builder.use Call, CheckState do |env, b|
         | 
| 93 | 
            +
                        case env[:machine_state]
         | 
| 94 | 
            +
                          when :Active
         | 
| 95 | 
            +
                            b.use PrivateNetwork
         | 
| 96 | 
            +
                          when :off
         | 
| 97 | 
            +
                            env[:ui].info I18n.t('vagrant_1cloud.info.off')
         | 
| 98 | 
            +
                          when :not_created
         | 
| 99 | 
            +
                            env[:ui].info I18n.t('vagrant_1cloud.info.not_created')
         | 
| 84 100 | 
             
                        end
         | 
| 85 101 | 
             
                      end
         | 
| 86 102 | 
             
                    end
         | 
| @@ -91,18 +107,18 @@ module VagrantPlugins | |
| 91 107 | 
             
                      builder.use ConfigValidate
         | 
| 92 108 | 
             
                      builder.use Call, CheckState do |env, b|
         | 
| 93 109 | 
             
                        case env[:machine_state]
         | 
| 94 | 
            -
             | 
| 95 | 
            -
             | 
| 96 | 
            -
             | 
| 97 | 
            -
             | 
| 98 | 
            -
             | 
| 99 | 
            -
             | 
| 100 | 
            -
             | 
| 101 | 
            -
             | 
| 102 | 
            -
             | 
| 103 | 
            -
             | 
| 104 | 
            -
             | 
| 105 | 
            -
             | 
| 110 | 
            +
                          when :Active
         | 
| 111 | 
            +
                            env[:ui].info I18n.t('vagrant_1cloud.info.already_active')
         | 
| 112 | 
            +
                          when :off
         | 
| 113 | 
            +
                            b.use PowerOn
         | 
| 114 | 
            +
                            b.use provision
         | 
| 115 | 
            +
                          when :not_created
         | 
| 116 | 
            +
                            b.use SetupKey
         | 
| 117 | 
            +
                            b.use Create
         | 
| 118 | 
            +
                            b.use PrivateNetwork
         | 
| 119 | 
            +
                            b.use SetupSudo
         | 
| 120 | 
            +
                            b.use SetupUser
         | 
| 121 | 
            +
                            b.use provision
         | 
| 106 122 | 
             
                        end
         | 
| 107 123 | 
             
                      end
         | 
| 108 124 | 
             
                    end
         | 
| @@ -113,16 +129,16 @@ module VagrantPlugins | |
| 113 129 | 
             
                      builder.use ConfigValidate
         | 
| 114 130 | 
             
                      builder.use Call, CheckState do |env, b|
         | 
| 115 131 | 
             
                        case env[:machine_state]
         | 
| 116 | 
            -
             | 
| 117 | 
            -
             | 
| 118 | 
            -
             | 
| 119 | 
            -
             | 
| 120 | 
            -
             | 
| 121 | 
            -
             | 
| 122 | 
            -
             | 
| 123 | 
            -
             | 
| 124 | 
            -
             | 
| 125 | 
            -
             | 
| 132 | 
            +
                          when :Active
         | 
| 133 | 
            +
                            if env[:force_halt]
         | 
| 134 | 
            +
                              b.use PowerOff
         | 
| 135 | 
            +
                            else
         | 
| 136 | 
            +
                              b.use ShutDown
         | 
| 137 | 
            +
                            end
         | 
| 138 | 
            +
                          when :off
         | 
| 139 | 
            +
                            env[:ui].info I18n.t('vagrant_1cloud.info.already_off')
         | 
| 140 | 
            +
                          when :not_created
         | 
| 141 | 
            +
                            env[:ui].info I18n.t('vagrant_1cloud.info.not_created')
         | 
| 126 142 | 
             
                        end
         | 
| 127 143 | 
             
                      end
         | 
| 128 144 | 
             
                    end
         | 
| @@ -133,13 +149,13 @@ module VagrantPlugins | |
| 133 149 | 
             
                      builder.use ConfigValidate
         | 
| 134 150 | 
             
                      builder.use Call, CheckState do |env, b|
         | 
| 135 151 | 
             
                        case env[:machine_state]
         | 
| 136 | 
            -
             | 
| 137 | 
            -
             | 
| 138 | 
            -
             | 
| 139 | 
            -
             | 
| 140 | 
            -
             | 
| 141 | 
            -
             | 
| 142 | 
            -
             | 
| 152 | 
            +
                          when :Active
         | 
| 153 | 
            +
                            b.use Reload
         | 
| 154 | 
            +
                            b.use provision
         | 
| 155 | 
            +
                          when :off
         | 
| 156 | 
            +
                            env[:ui].info I18n.t('vagrant_1cloud.info.off')
         | 
| 157 | 
            +
                          when :not_created
         | 
| 158 | 
            +
                            env[:ui].info I18n.t('vagrant_1cloud.info.not_created')
         | 
| 143 159 | 
             
                        end
         | 
| 144 160 | 
             
                      end
         | 
| 145 161 | 
             
                    end
         | 
| @@ -24,7 +24,7 @@ module VagrantPlugins | |
| 24 24 | 
             
                        :RAM => @machine.provider_config.ram,
         | 
| 25 25 | 
             
                        :DCLocation => @machine.provider_config.region,
         | 
| 26 26 | 
             
                        :ImageID => @machine.provider_config.image,
         | 
| 27 | 
            -
                        :Name => @machine. | 
| 27 | 
            +
                        :Name => @machine.name,
         | 
| 28 28 | 
             
                        :SshKeys => ssh_key_id,
         | 
| 29 29 | 
             
                        :isHighPerformance => @machine.provider_config.hi_perf
         | 
| 30 30 | 
             
                      }.delete_if { |k, v| v.nil? })
         | 
| @@ -58,7 +58,7 @@ module VagrantPlugins | |
| 58 58 |  | 
| 59 59 | 
             
                        ifdown -a
         | 
| 60 60 | 
             
                        export INTERFACE=eth0
         | 
| 61 | 
            -
                        export MATCHADDR=$(ifconfig  | 
| 61 | 
            +
                        export MATCHADDR=$(ifconfig eth0 | awk 'NR==1{print $NF}')
         | 
| 62 62 | 
             
                        export MATCHID=$(udevadm info /sys/class/net/eth0 | grep P: | awk -F/ '{print $(NF-2)}')
         | 
| 63 63 | 
             
                        /lib/udev/write_net_rules
         | 
| 64 64 | 
             
                        udevadm control --reload-rules && udevadm trigger
         | 
| @@ -26,8 +26,17 @@ module VagrantPlugins | |
| 26 26 |  | 
| 27 27 | 
             
                        raise "Private network #{net} is not created" if !private_network
         | 
| 28 28 |  | 
| 29 | 
            +
                        # Checking if machine is already added to network
         | 
| 30 | 
            +
                        result = @client.request("/server/#{@machine.id}")
         | 
| 31 | 
            +
                        linked_network = result['body']['LinkedNetworks'].find { |network| network['NetworkID'] == private_network['ID'] }
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                        if linked_network
         | 
| 34 | 
            +
                            env[:ui].info I18n.t('vagrant_1cloud.info.already_connected', network: net)
         | 
| 35 | 
            +
                            next
         | 
| 36 | 
            +
                        end
         | 
| 37 | 
            +
             | 
| 29 38 | 
             
                        # Adding server to specified network
         | 
| 30 | 
            -
                        result = @client.post("/ | 
| 39 | 
            +
                        result = @client.post("/server/#{@machine.id}/Action", {
         | 
| 31 40 | 
             
                            :Type => "AddNetwork",
         | 
| 32 41 | 
             
                            :NetworkID => private_network['ID']
         | 
| 33 42 | 
             
                        })
         | 
| @@ -0,0 +1,59 @@ | |
| 1 | 
            +
            require 'optparse'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module VagrantPlugins
         | 
| 4 | 
            +
              module OneCloud
         | 
| 5 | 
            +
                module Commands
         | 
| 6 | 
            +
                  class AddNetwork < Vagrant.plugin('2', :command)
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                    # Show description when `vagrant list-commands` is triggered
         | 
| 9 | 
            +
                    def self.synopsis
         | 
| 10 | 
            +
                      "plugin: vagrant-1cloud: adds VPS to specific private network"
         | 
| 11 | 
            +
                    end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                    def execute
         | 
| 14 | 
            +
                      options = {}
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                      optparse = OptionParser.new do |opts|
         | 
| 17 | 
            +
                        opts.banner = 'Usage: vagrant add-network [vm-name] [options]'
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                        opts.on('-n', '--net NETNAME', 'Network name') do |net|
         | 
| 20 | 
            +
                          options[:Net] = net
         | 
| 21 | 
            +
                        end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                        options[:IP] = nil
         | 
| 24 | 
            +
                        opts.on('-i', '--ip [IP]', 'Private IP address') do |ip|
         | 
| 25 | 
            +
                          options[:IP] = ip
         | 
| 26 | 
            +
                        end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                        opts.on('-h', '--help', 'Display this screen') do
         | 
| 29 | 
            +
                          puts opts
         | 
| 30 | 
            +
                          exit
         | 
| 31 | 
            +
                        end
         | 
| 32 | 
            +
                      end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                      begin
         | 
| 35 | 
            +
                        optparse.parse!
         | 
| 36 | 
            +
                        mandatory = [:Net]
         | 
| 37 | 
            +
                        missing = mandatory.select{ |param| options[param].nil? }
         | 
| 38 | 
            +
                        unless missing.empty?
         | 
| 39 | 
            +
                          raise OptionParser::MissingArgument.new(missing.join(', '))
         | 
| 40 | 
            +
                        end
         | 
| 41 | 
            +
                      rescue OptionParser::InvalidOption, OptionParser::MissingArgument
         | 
| 42 | 
            +
                        puts $!.to_s
         | 
| 43 | 
            +
                        puts optparse
         | 
| 44 | 
            +
                        exit
         | 
| 45 | 
            +
                      end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                      argv = parse_options(optparse)
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                      with_target_vms(argv) do |machine|
         | 
| 50 | 
            +
                        machine.provider_config.private_net = {options[:Net] => options[:IP]}
         | 
| 51 | 
            +
                        machine.action(:addnet)
         | 
| 52 | 
            +
                      end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                      0
         | 
| 55 | 
            +
                    end
         | 
| 56 | 
            +
                  end
         | 
| 57 | 
            +
                end
         | 
| 58 | 
            +
              end
         | 
| 59 | 
            +
            end
         | 
| @@ -94,6 +94,43 @@ module VagrantPlugins | |
| 94 94 | 
             
                      end
         | 
| 95 95 | 
             
                    end
         | 
| 96 96 |  | 
| 97 | 
            +
                    def wait_for_destroy(env, id)
         | 
| 98 | 
            +
                      retryable(:tries => 400, :sleep => 10) do
         | 
| 99 | 
            +
                        # stop waiting if interrupted
         | 
| 100 | 
            +
                        next if env[:interrupted]
         | 
| 101 | 
            +
             | 
| 102 | 
            +
                        # check action status
         | 
| 103 | 
            +
                        begin
         | 
| 104 | 
            +
                          result = @client.send(:get) do |req|
         | 
| 105 | 
            +
                            req.url "/server/#{id}"
         | 
| 106 | 
            +
                            req.headers['Authorization'] = "Bearer #{@config.token}"
         | 
| 107 | 
            +
                          end
         | 
| 108 | 
            +
                        rescue Faraday::Error::ConnectionFailed => e
         | 
| 109 | 
            +
                          # TODO this is suspect but because faraday wraps the exception
         | 
| 110 | 
            +
                          #      in something generic there doesn't appear to be another
         | 
| 111 | 
            +
                          #      way to distinguish different connection errors :(
         | 
| 112 | 
            +
                          if e.message =~ /certificate verify failed/
         | 
| 113 | 
            +
                            raise Errors::CertificateError
         | 
| 114 | 
            +
                          end
         | 
| 115 | 
            +
                          raise e
         | 
| 116 | 
            +
                        end
         | 
| 117 | 
            +
                        begin
         | 
| 118 | 
            +
                          body = JSON.parse(%Q[{"body":#{result.body}}])
         | 
| 119 | 
            +
                          @logger.info "Response: #{body}"
         | 
| 120 | 
            +
                        rescue JSON::ParserError => e
         | 
| 121 | 
            +
                          raise(Errors::JSONError, {
         | 
| 122 | 
            +
                              :message => e.message,
         | 
| 123 | 
            +
                              :path => path,
         | 
| 124 | 
            +
                              :params => params,
         | 
| 125 | 
            +
                              :response => result.body
         | 
| 126 | 
            +
                          })
         | 
| 127 | 
            +
                        end
         | 
| 128 | 
            +
                        result = Result.new(body)
         | 
| 129 | 
            +
                        yield result if block_given?
         | 
| 130 | 
            +
                        raise 'Destroy is not completed' if result['body']['Message'] != 'Server not found'
         | 
| 131 | 
            +
                      end
         | 
| 132 | 
            +
                    end
         | 
| 133 | 
            +
             | 
| 97 134 | 
             
                    def wait_for_network(env, net_id)
         | 
| 98 135 | 
             
                      retryable(:tries => 400, :sleep => 10) do
         | 
| 99 136 | 
             
                        # stop waiting if interrupted
         | 
| @@ -22,6 +22,11 @@ module VagrantPlugins | |
| 22 22 | 
             
                    Commands::Rebuild
         | 
| 23 23 | 
             
                  end
         | 
| 24 24 |  | 
| 25 | 
            +
                  command("add-network") do
         | 
| 26 | 
            +
                    require_relative 'commands/add_network'
         | 
| 27 | 
            +
                    Commands::AddNetwork
         | 
| 28 | 
            +
                  end
         | 
| 29 | 
            +
             | 
| 25 30 | 
             
                  command("create-network") do
         | 
| 26 31 | 
             
                    require_relative 'commands/create_network'
         | 
| 27 32 | 
             
                    Commands::CreateNetwork
         | 
    
        data/locales/en.yml
    CHANGED
    
    | @@ -27,6 +27,7 @@ en: | |
| 27 27 | 
             
                  request: "Request: %{path}"
         | 
| 28 28 | 
             
                  params: "Parameters: %{params}"
         | 
| 29 29 | 
             
                  response: "Response: %{body}"
         | 
| 30 | 
            +
                  already_connected: "VPS is already connected to %{network} network"
         | 
| 30 31 | 
             
                config:
         | 
| 31 32 | 
             
                  token: "Token is required"
         | 
| 32 33 | 
             
                  private_key: "SSH private key path is required"
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: vagrant-1cloud
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.0 | 
| 4 | 
            +
              version: 1.1.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Bulat Yusupov
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2017- | 
| 11 | 
            +
            date: 2017-07-12 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: faraday
         | 
| @@ -79,6 +79,7 @@ files: | |
| 79 79 | 
             
            - lib/vagrant-1cloud/actions/setup_sudo.rb
         | 
| 80 80 | 
             
            - lib/vagrant-1cloud/actions/setup_user.rb
         | 
| 81 81 | 
             
            - lib/vagrant-1cloud/actions/shut_down.rb
         | 
| 82 | 
            +
            - lib/vagrant-1cloud/commands/add_network.rb
         | 
| 82 83 | 
             
            - lib/vagrant-1cloud/commands/create_network.rb
         | 
| 83 84 | 
             
            - lib/vagrant-1cloud/commands/rebuild.rb
         | 
| 84 85 | 
             
            - lib/vagrant-1cloud/config.rb
         |