Merge pull request #107 from opscode/adamed-oc-10125
OC-10125: knife-azure should auto-generate azure dns name
This commit is contained in:
Коммит
d30862f72c
|
@ -20,6 +20,8 @@
|
|||
|
||||
require 'chef/knife/azure_base'
|
||||
require 'chef/knife/winrm_base'
|
||||
require 'securerandom'
|
||||
|
||||
class Chef
|
||||
class Knife
|
||||
class AzureServerCreate < Knife
|
||||
|
@ -119,7 +121,7 @@ class Chef
|
|||
option :azure_vm_name,
|
||||
:long => "--azure-vm-name NAME",
|
||||
:description => "Required for advanced server-create option.
|
||||
Specifies the name for the virtual machine. The name must be unique within the deployment."
|
||||
Specifies the name for the virtual machine. The name must be unique within the deployment. The azure vm name cannot be more than 15 characters long"
|
||||
|
||||
option :azure_service_location,
|
||||
:short => "-m LOCATION",
|
||||
|
@ -135,7 +137,7 @@ class Chef
|
|||
option :azure_dns_name,
|
||||
:short => "-d DNS_NAME",
|
||||
:long => "--azure-dns-name DNS_NAME",
|
||||
:description => "Required. The DNS prefix name that can be used to access the cloud service which is unique within Windows Azure.
|
||||
:description => "The DNS prefix name that can be used to access the cloud service which is unique within Windows Azure. Default is 'azure-dns-any_random_text'(e.g: azure-dns-be9b0f6f-7dda-456f-b2bf-4e28a3bc0add).
|
||||
If you want to add new VM to an existing service/deployment, specify an exiting dns-name,
|
||||
along with --azure-connect-to-existing-dns option.
|
||||
Otherwise a new deployment is created. For example, if the DNS of cloud service is MyService you could access the cloud service
|
||||
|
@ -271,6 +273,7 @@ class Chef
|
|||
|
||||
Chef::Log.info("creating...")
|
||||
|
||||
config[:azure_dns_name] = get_dns_name(locate_config_value(:azure_dns_name))
|
||||
if not locate_config_value(:azure_vm_name)
|
||||
config[:azure_vm_name] = locate_config_value(:azure_dns_name)
|
||||
end
|
||||
|
@ -441,7 +444,6 @@ class Chef
|
|||
:azure_subscription_id,
|
||||
:azure_mgmt_cert,
|
||||
:azure_api_host_name,
|
||||
:azure_dns_name,
|
||||
:azure_source_image,
|
||||
:azure_vm_size,
|
||||
])
|
||||
|
@ -537,7 +539,17 @@ class Chef
|
|||
exit 1
|
||||
end
|
||||
|
||||
private
|
||||
# generate a random dns_name if azure_dns_name is empty
|
||||
def get_dns_name(azure_dns_name, prefix = "azure-dns-")
|
||||
return azure_dns_name unless azure_dns_name.nil?
|
||||
if locate_config_value(:azure_vm_name).nil?
|
||||
azure_dns_name = prefix + SecureRandom.hex((15 - prefix.length)/2)
|
||||
else
|
||||
azure_dns_name = prefix + locate_config_value(:azure_vm_name)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -80,11 +80,7 @@ describe "parameter test:" do
|
|||
@server_instance.ui.should_receive(:error)
|
||||
expect {@server_instance.run}.to raise_error
|
||||
end
|
||||
it "azure_dns_name" do
|
||||
Chef::Config[:knife].delete(:azure_dns_name)
|
||||
@server_instance.ui.should_receive(:error)
|
||||
expect {@server_instance.run}.to raise_error
|
||||
end
|
||||
|
||||
it "azure_service_location and azure_affinity_group not allowed" do
|
||||
Chef::Config[:knife][:azure_affinity_group] = 'test-affinity'
|
||||
@server_instance.ui.should_receive(:error)
|
||||
|
@ -112,6 +108,7 @@ describe "parameter test:" do
|
|||
it "quick create" do
|
||||
@server_instance.should_receive(:is_image_windows?).at_least(:twice).and_return(false)
|
||||
Chef::Config[:knife][:azure_dns_name] = 'vmname' # service name to be used as vm name
|
||||
@server_instance.should_receive(:get_dns_name)
|
||||
@server_instance.run
|
||||
@server_instance.config[:azure_vm_name].should == "vmname"
|
||||
testxml = Nokogiri::XML(@receivedXML)
|
||||
|
@ -185,6 +182,29 @@ describe "parameter test:" do
|
|||
end
|
||||
end
|
||||
|
||||
context "when --azure-dns-name is not specified" do
|
||||
before(:each) do
|
||||
Chef::Config[:knife][:azure_dns_name] = nil
|
||||
Chef::Config[:knife][:azure_vm_name] = nil
|
||||
end
|
||||
|
||||
it "generate unique dns name" do
|
||||
dns_name = []
|
||||
5.times do
|
||||
# send() to access private get_dns_name method of @server_instance
|
||||
dns = @server_instance.send(:get_dns_name, Chef::Config[:knife][:azure_dns_name])
|
||||
dns_name.should_not include(dns)
|
||||
dns_name.push(dns)
|
||||
end
|
||||
end
|
||||
|
||||
it "include vmname in dnsname if --azure-vm-name specified" do
|
||||
Chef::Config[:knife][:azure_vm_name] = "vmname"
|
||||
dns = @server_instance.send(:get_dns_name, Chef::Config[:knife][:azure_dns_name])
|
||||
dns.should include("vmname")
|
||||
end
|
||||
end
|
||||
|
||||
context "#cleanup_and_exit" do
|
||||
it "service leak cleanup" do
|
||||
expect {@server_instance.cleanup_and_exit("hosted_srvc", "storage_srvc")}.to raise_error
|
||||
|
|
Загрузка…
Ссылка в новой задаче