Class: Octo::OctoMachineShow

Inherits:
Chef::Knife
  • Object
show all
Defined in:
lib/chef/knife/octo.rb

Instance Method Summary collapse

Instance Method Details

#runObject



925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
# File 'lib/chef/knife/octo.rb', line 925

def run
  if Chef::Config[:knife][:octo_instance].nil?
    ui.error("Please specify your Octopus Deploy instance in your knife config as -\nknife[:octo_instance] = 'MYOCTO.MYDOMAIN'")
    exit
  end
  if Chef::Config[:knife][:octo_apikey].nil?
    ui.error("Please specify your Octopus API key in your knife config as -\nknife[:octo_apikey]  = 'MYKEY'\nSee Also : https://octopus.com/docs/api-and-integration/api/how-to-create-an-api-key")
    exit
  end
  if name_args.size > 1
    ui.error("You provided two machines.\nSupply only one machine name or try quotes.")
    return
  end

  unless name_args.size == 1
    ui.error("#{'Provide the machine name!'.red}")
    return
  end
  octo_methods = OctoHelperMethods.new(Chef::Config[:knife][:octo_apikey],Chef::Config[:knife][:octo_instance])
  m_id = octo_methods.mid_from_mname("#{name_args[0]}")
  if m_id['response'] == 'ok'
    request = octo_methods.generic_call('GET', "machines/#{m_id['message']}", false)
    if config[:long]
      print octo_methods.parse_machine_deets(request['message'],true)
      print "\n"
    else
      print octo_methods.parse_machine_deets(request['message'],false)
      print "\n"
    end
  else
    ui.error(m_id['message'])
  end
end