Module: Legion::Extensions::ServiceNow::Cmdb::Instance::Runners::Instance
Instance Method Summary
collapse
-
#create_ci(class_name:, name: nil, ip_address: nil, os: nil) ⇒ Object
-
#create_relationship(class_name:, sys_id:, target_id:, relationship_type:) ⇒ Object
-
#delete_ci(class_name:, sys_id:) ⇒ Object
-
#get_ci(class_name:, sys_id:) ⇒ Object
-
#get_relationships(class_name:, sys_id:) ⇒ Object
-
#list_cis(class_name:, sysparm_limit: 100, sysparm_offset: 0, sysparm_query: nil) ⇒ Object
-
#update_ci(class_name:, sys_id:, name: nil, ip_address: nil, os: nil, location: nil) ⇒ Object
#connection, #fetch_oauth2_token
Instance Method Details
#create_ci(class_name:, name: nil, ip_address: nil, os: nil) ⇒ Object
19
20
21
22
23
24
25
26
|
# File 'lib/legion/extensions/service_now/cmdb/instance/runners/instance.rb', line 19
def create_ci(class_name:, name: nil, ip_address: nil, os: nil, **)
body = {}
body[:name] = name if name
body[:ip_address] = ip_address if ip_address
body[:os] = os if os
resp = connection(**).post("/api/now/cmdb/instance/#{class_name}", body)
{ record: resp.body['result']['record'] }
end
|
#create_relationship(class_name:, sys_id:, target_id:, relationship_type:) ⇒ Object
53
54
55
56
57
|
# File 'lib/legion/extensions/service_now/cmdb/instance/runners/instance.rb', line 53
def create_relationship(class_name:, sys_id:, target_id:, relationship_type:, **)
body = { target_id: target_id, relationship_type: relationship_type }
resp = connection(**).post("/api/now/cmdb/instance/#{class_name}/#{sys_id}/relationships", body)
{ relationship: resp.body['result'] }
end
|
#delete_ci(class_name:, sys_id:) ⇒ Object
43
44
45
46
|
# File 'lib/legion/extensions/service_now/cmdb/instance/runners/instance.rb', line 43
def delete_ci(class_name:, sys_id:, **)
resp = connection(**).delete("/api/now/cmdb/instance/#{class_name}/#{sys_id}")
{ deleted: resp.status == 204, sys_id: sys_id }
end
|
#get_ci(class_name:, sys_id:) ⇒ Object
28
29
30
31
|
# File 'lib/legion/extensions/service_now/cmdb/instance/runners/instance.rb', line 28
def get_ci(class_name:, sys_id:, **)
resp = connection(**).get("/api/now/cmdb/instance/#{class_name}/#{sys_id}")
{ record: resp.body['result']['record'] }
end
|
#get_relationships(class_name:, sys_id:) ⇒ Object
48
49
50
51
|
# File 'lib/legion/extensions/service_now/cmdb/instance/runners/instance.rb', line 48
def get_relationships(class_name:, sys_id:, **)
resp = connection(**).get("/api/now/cmdb/instance/#{class_name}/#{sys_id}/relationships")
{ relationships: resp.body['result'] }
end
|
#list_cis(class_name:, sysparm_limit: 100, sysparm_offset: 0, sysparm_query: nil) ⇒ Object
12
13
14
15
16
17
|
# File 'lib/legion/extensions/service_now/cmdb/instance/runners/instance.rb', line 12
def list_cis(class_name:, sysparm_limit: 100, sysparm_offset: 0, sysparm_query: nil, **)
params = { sysparm_limit: sysparm_limit, sysparm_offset: sysparm_offset }
params[:sysparm_query] = sysparm_query if sysparm_query
resp = connection(**).get("/api/now/cmdb/instance/#{class_name}", params)
{ records: resp.body['result']['records'] }
end
|
#update_ci(class_name:, sys_id:, name: nil, ip_address: nil, os: nil, location: nil) ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'lib/legion/extensions/service_now/cmdb/instance/runners/instance.rb', line 33
def update_ci(class_name:, sys_id:, name: nil, ip_address: nil, os: nil, location: nil, **)
body = {}
body[:name] = name if name
body[:ip_address] = ip_address if ip_address
body[:os] = os if os
body[:location] = location if location
resp = connection(**).patch("/api/now/cmdb/instance/#{class_name}/#{sys_id}", body)
{ record: resp.body['result']['record'] }
end
|