def create_server(host_name, service_name, template_name, disk_name=nil, zone_name=nil, network_names=[], extra_params)

      if host_name then
        if get_server(host_name) then
          puts "\nError: Server '#{host_name}' already exists."
          exit 1
        end
      end

      service = get_service_offering(service_name)
      if !service then
        puts "\nError: Service offering '#{service_name}' is invalid"
        exit 1
      end

      template = get_template(template_name, zone_name)
      template = get_iso(template_name, zone_name) unless template

      if !template then
        puts "\nError: Template / ISO name: '#{template_name}' is invalid"
        exit 1
      end

      if disk_name then
        disk = get_disk_offering(disk_name)
        if !disk then
          puts "\nError: Disk offering '#{disk_name}' is invalid"
          exit 1
        end
      end

      zone = zone_name ? get_zone(zone_name) : get_default_zone
      if !zone then
        msg = zone_name ? "Zone '#{zone_name}' is invalid" : "No default zone found"
        puts "\nError: #{msg}"
        exit 1
      end

      if zone['networktype'] != 'Basic' then
      # If this is a Basic zone no networkids are needed in the params

        networks = []
        if network_names.nil? then
          networks << get_default_network(zone['id'])
        else
          network_names.each do |name|
            network = get_network(name)
            if !network then
              puts "\nError: Network '#{name}' not found"
            end
            networks << get_network(name)
          end
        end

        if networks.empty? then
          networks << get_default_network(zone['id'])
        end
        if networks.empty? then
          puts "\nError: No default network found"
          exit 1
        end
        network_ids = networks.map { |network|
          network['id']
        }

        params = {
            'command' => 'deployVirtualMachine',
            'serviceOfferingId' => service['id'],
            'templateId' => template['id'],
            'zoneId' => zone['id'],
            'networkids' => network_ids.join(',')
        }

      else

        params = {
            'command' => 'deployVirtualMachine',
            'serviceOfferingId' => service['id'],
            'templateId' => template['id'],
            'zoneId' => zone['id']
        }

      end

      params.merge!(extra_params) if extra_params

      params['name'] = host_name if host_name
      params['diskOfferingId'] = disk['id'] if disk

      json = send_async_request(params)
      json['virtualmachine']
    end
def create_server(host_name, service_name, template_name, disk_name=nil, zone_name=nil, network_names=[], extra_params)

      if host_name then
        if get_server(host_name) then
          puts "\nError: Server '#{host_name}' already exists."
          exit 1
        end
      end

      service = get_service_offering(service_name)
      if !service then
        puts "\nError: Service offering '#{service_name}' is invalid"
        exit 1
      end

      template = get_template(template_name, zone_name)
      template = get_iso(template_name, zone_name) unless template

      if !template then
        puts "\nError: Template / ISO name: '#{template_name}' is invalid"
        exit 1
      end

      if disk_name then
        disk = get_disk_offering(disk_name)
        if !disk then
          puts "\nError: Disk offering '#{disk_name}' is invalid"
          exit 1
        end
      end

      zone = zone_name ? get_zone(zone_name) : get_default_zone
      if !zone then
        msg = zone_name ? "Zone '#{zone_name}' is invalid" : "No default zone found"
        puts "\nError: #{msg}"
        exit 1
      end

      if zone['networktype'] != 'Basic' then
      # If this is a Basic zone no networkids are needed in the params

        networks = []
        if network_names.nil? then
          networks << get_default_network(zone['id'])
        else
          network_names.each do |name|
            network = get_network(name)
            if !network then
              puts "\nError: Network '#{name}' not found"
            end
            networks << get_network(name)
          end
        end

        if networks.empty? then
          networks << get_default_network(zone['id'])
        end
        if networks.empty? then
          puts "\nError: No default network found"
          exit 1
        end
        network_ids = networks.map { |network|
          network['id']
        }

        params = {
            'command' => 'deployVirtualMachine',
            'serviceOfferingId' => service['id'],
            'templateId' => template['id'],
            'zoneId' => zone['id'],
            'networkids' => network_ids.join(',')
        }

      else

        params = {
            'command' => 'deployVirtualMachine',
            'serviceOfferingId' => service['id'],
            'templateId' => template['id'],
            'zoneId' => zone['id']
        }

      end

      params.merge!(extra_params) if extra_params

      params['name'] = host_name if host_name
      params['diskOfferingId'] = disk['id'] if disk

      json = send_async_request(params)
      json['virtualmachine']
    end
Deploys a new server using the specified parameters.