Class: Morpheus::APIClient

Inherits:
Object
  • Object
show all
Defined in:
lib/morpheus/api/api_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(access_token, refresh_token = nil, expires_in = nil, base_url = nil, verify_ssl = true) ⇒ APIClient

Returns a new instance of APIClient.



6
7
8
9
10
11
12
13
14
# File 'lib/morpheus/api/api_client.rb', line 6

def initialize(access_token, refresh_token=nil,expires_in = nil, base_url=nil, verify_ssl=true) 
  @access_token = access_token
  @refresh_token = refresh_token
  @base_url = base_url
  if expires_in != nil
    @expires_at = DateTime.now + expires_in.seconds
  end
  set_ssl_verification_enabled(verify_ssl)
end

Instance Method Details

#accountsObject



136
137
138
# File 'lib/morpheus/api/api_client.rb', line 136

def accounts
  Morpheus::AccountsInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#app_templatesObject



116
117
118
# File 'lib/morpheus/api/api_client.rb', line 116

def app_templates
  Morpheus::AppTemplatesInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#appsObject



112
113
114
# File 'lib/morpheus/api/api_client.rb', line 112

def apps
  Morpheus::AppsInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#archive_bucketsObject

def incidents

# Morpheus::IncidentsInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
monitoring.incidents

end



194
195
196
# File 'lib/morpheus/api/api_client.rb', line 194

def archive_buckets
  Morpheus::ArchiveBucketsInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#archive_filesObject



198
199
200
# File 'lib/morpheus/api/api_client.rb', line 198

def archive_files
  Morpheus::ArchiveFilesInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#authObject



56
57
58
# File 'lib/morpheus/api/api_client.rb', line 56

def auth
  Morpheus::AuthInterface.new(@base_url, @access_token)
end

#cloudsObject



72
73
74
# File 'lib/morpheus/api/api_client.rb', line 72

def clouds
  Morpheus::CloudsInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#containersObject



84
85
86
# File 'lib/morpheus/api/api_client.rb', line 84

def containers
  Morpheus::ContainersInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#custom_instance_typesObject



160
161
162
# File 'lib/morpheus/api/api_client.rb', line 160

def custom_instance_types
  Morpheus::CustomInstanceTypesInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#dashboardObject



172
173
174
# File 'lib/morpheus/api/api_client.rb', line 172

def dashboard
  Morpheus::DashboardInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#deployObject



120
121
122
# File 'lib/morpheus/api/api_client.rb', line 120

def deploy
  Morpheus::DeployInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#deploymentsObject



124
125
126
# File 'lib/morpheus/api/api_client.rb', line 124

def deployments
  Morpheus::DeploymentsInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#dryObject



21
22
23
# File 'lib/morpheus/api/api_client.rb', line 21

def dry()
  dry_run(true)
end

#dry_run(val = true) ⇒ Object



16
17
18
19
# File 'lib/morpheus/api/api_client.rb', line 16

def dry_run(val=true)
  @dry_run = !!val
  self
end

#execute(opts, parse_json = true) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/morpheus/api/api_client.rb', line 33

def execute(opts, parse_json=true)
  # @verify_ssl is not used atm
  # todo: finish this and use it instead of the global variable RestClient.ssl_verification_enabled?
  # gotta clean up all APIClient subclasses new() methods to support this
  # the CliCommand subclasses should be changed to @users_interface = @api_client.users
  # also.. Credentials.new()
  if @verify_ssl == false
    opts[:verify_ssl] = OpenSSL::SSL::VERIFY_NONE
  end
  if @dry_run
    # JD: could return a Request object instead...
    return opts
  end
  # Morpheus::Logging::DarkPrinter.puts "Morpheus::RestClient.execute(#{opts})" if Morpheus::Logging.debug?
  # instead, using ::RestClient.log = STDOUT 
  response = Morpheus::RestClient.execute(opts)
  if parse_json
    return JSON.parse(response.to_s)
  else
    return response
  end
end

#groupsObject



68
69
70
# File 'lib/morpheus/api/api_client.rb', line 68

def groups
  Morpheus::GroupsInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#image_builderObject



202
203
204
# File 'lib/morpheus/api/api_client.rb', line 202

def image_builder
  Morpheus::ImageBuilderInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#instance_typesObject



88
89
90
# File 'lib/morpheus/api/api_client.rb', line 88

def instance_types
  Morpheus::InstanceTypesInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#instancesObject



80
81
82
# File 'lib/morpheus/api/api_client.rb', line 80

def instances
  Morpheus::InstancesInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#key_pairsObject



152
153
154
# File 'lib/morpheus/api/api_client.rb', line 152

def key_pairs
  Morpheus::KeyPairsInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#licenseObject



156
157
158
# File 'lib/morpheus/api/api_client.rb', line 156

def license
  Morpheus::LicenseInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#load_balancersObject



96
97
98
# File 'lib/morpheus/api/api_client.rb', line 96

def load_balancers
  Morpheus::LoadBalancersInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#logsObject



144
145
146
# File 'lib/morpheus/api/api_client.rb', line 144

def logs
  Morpheus::LogsInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#monitoringObject



180
181
182
# File 'lib/morpheus/api/api_client.rb', line 180

def monitoring
  Morpheus::MonitoringInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#option_type_listsObject



168
169
170
# File 'lib/morpheus/api/api_client.rb', line 168

def option_type_lists
  Morpheus::OptionTypeListsInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#option_typesObject



164
165
166
# File 'lib/morpheus/api/api_client.rb', line 164

def option_types
  Morpheus::OptionTypesInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#optionsObject



64
65
66
# File 'lib/morpheus/api/api_client.rb', line 64

def options
  Morpheus::OptionsInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#provision_typesObject



92
93
94
# File 'lib/morpheus/api/api_client.rb', line 92

def provision_types
  Morpheus::ProvisionTypesInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#rolesObject



148
149
150
# File 'lib/morpheus/api/api_client.rb', line 148

def roles
  Morpheus::RolesInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#security_group_rulesObject



132
133
134
# File 'lib/morpheus/api/api_client.rb', line 132

def security_group_rules
  Morpheus::SecurityGroupRulesInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#security_groupsObject



128
129
130
# File 'lib/morpheus/api/api_client.rb', line 128

def security_groups
  Morpheus::SecurityGroupsInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#serversObject



76
77
78
# File 'lib/morpheus/api/api_client.rb', line 76

def servers
  Morpheus::ServersInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#set_ssl_verification_enabled(val) ⇒ Object



29
30
31
# File 'lib/morpheus/api/api_client.rb', line 29

def set_ssl_verification_enabled(val)
  @verify_ssl = !!val
end

#setupObject



176
177
178
# File 'lib/morpheus/api/api_client.rb', line 176

def setup
  Morpheus::SetupInterface.new(@base_url)
end

#ssl_verification_enabled?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/morpheus/api/api_client.rb', line 25

def ssl_verification_enabled?
  @verify_ssl
end

#task_setsObject



104
105
106
# File 'lib/morpheus/api/api_client.rb', line 104

def task_sets
  Morpheus::TaskSetsInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#tasksObject



100
101
102
# File 'lib/morpheus/api/api_client.rb', line 100

def tasks
  Morpheus::TasksInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#usersObject



140
141
142
# File 'lib/morpheus/api/api_client.rb', line 140

def users
  Morpheus::UsersInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#virtual_imagesObject



108
109
110
# File 'lib/morpheus/api/api_client.rb', line 108

def virtual_images
  Morpheus::VirtualImagesInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end

#whoamiObject



60
61
62
# File 'lib/morpheus/api/api_client.rb', line 60

def whoami
  Morpheus::WhoamiInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
end