Skip to content

Commit

Permalink
Implemented the before_bootstrap method to provide a static IP addres…
Browse files Browse the repository at this point in the history
…s taken from an environment variable.
  • Loading branch information
vondrt4 committed Oct 25, 2019
1 parent 7ffbbf9 commit ab29f0e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
31 changes: 20 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,28 @@ Create a new server in the oVirt cluster based off an existing template. One of

* `--ovirt_cloud_init <cloud_init yaml>` specify a yaml string containing the cloud_init data needed to pass to the system. One method is to do it this way in a the knife.rb config:
```ruby
knife[:ovirt_cloud_init] = {
ssh_authorized_keys: [File.read("#{ENV['HOME']}/.ssh/ovirt.pub")],
user: knife[:ssh_user],
ip: knife[:bootstrap_ip_address],
netmask: '255.255.255.0',
gateway: '192.168.1.1',
nicname: 'eth0',
dns: '192.168.1.1',
domain: 'example.com',
hostname: knife[:chef_node_name],
}.to_yaml
knife[:bootstrap_ip_address_temp]="#{ENV['BOOTSTRAP_IP_ADDRESS_ENV']}"
knife[:ovirt_cloud_init] = {
ssh_authorized_keys: [File.read("#{ENV['HOME']}/.ssh/id_rsa.pub")],
ip: knife[:bootstrap_ip_address_temp],
netmask: '255.255.255.0',
gateway: '192.168.250.1',
nicname: 'ens3',
dns: '192.168.250.200',
domain: 'example.com',
hostname: knife[:chef_node_name],
# custom_script: File.read("#{ENV['HOME']}/.chef/cloud-init-ubuntu.yaml")
}.to_yaml
```

You then create and bootstrap a new server like this:
```bash
BOOTSTRAP_IP_ADDRESS_ENV=192.168.250.241 knife ovirt server create --ssh-user root --identity-file ~/.ssh/id_rsa --no-host-key-verify -N node-name --ovirt-template-name template-name -r 'role[name]'
```
TODO: support IP addresses obtained from DHCP and reported to oVirt by ovirt-guest-agent

TODO: refactor to work with Chef 15; for now this gem depends on knife-cloud-1.2.3, which is not compatible. Made to work by reverting attribute names from https://github.com/chef/knife-cloud/pull/117/files and manually fixing some dependencies.

### `knife ovirt server delete VMID|VMNAME [VMID|VMNAME] (options)`

Delete a Virtual Machine or list of Virtual Machines
Expand Down
1 change: 1 addition & 0 deletions lib/chef/knife/cloud/ovirt_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def initialize(options = {})
ovirt_username: Chef::Config[:knife][:ovirt_username],
ovirt_password: Chef::Config[:knife][:ovirt_password],
ovirt_url: Chef::Config[:knife][:ovirt_url],
ovirt_ca_no_verify: true
}))
end

Expand Down
14 changes: 14 additions & 0 deletions lib/chef/knife/ovirt_server_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ class OvirtServerCreate < ServerCreateCommand

banner 'knife ovirt server create (options)'

def before_bootstrap
super

bootstrap_ip_address = "#{ENV['BOOTSTRAP_IP_ADDRESS_ENV']}"

Chef::Log.debug("Bootstrap IP Address: #{bootstrap_ip_address}")
if bootstrap_ip_address.nil?
error_message = "No IP address available for bootstrapping."
ui.error(error_message)
raise CloudExceptions::BootstrapError, error_message
end
config[:bootstrap_ip_address] = bootstrap_ip_address
end

def before_exec_command
super
# setup the create options
Expand Down

0 comments on commit ab29f0e

Please sign in to comment.