usd 0.2.3 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +45 -22
  3. data/bin/rusdc +37 -7
  4. data/change_log.md +121 -1
  5. data/lib/usd.rb +70 -0
  6. data/usd.gemspec +2 -2
  7. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 321fb82b164595bcb7c2ff73cb7e9f1ed9fe6306b9517c1c236ae30aaa713aaa
4
- data.tar.gz: ea63b6a5116370391d19c4b2c6d9d82768fb0fd9af709dd9a971829fd9a3db74
3
+ metadata.gz: 01c14a85c19914e885ffd003e8b4584ab7f89a15305866abade4ea4888625940
4
+ data.tar.gz: e89f3b47d89b9040077400049e91aa0700f4c68d41b19c6cf7fde7a97f8e46c8
5
5
  SHA512:
6
- metadata.gz: 28255500c9fcee00e8d62361f8ec06a12e4617f653f8c4aa255655d7fd37a76b429440922511d4af9288fd67670c7a5346eceb358514ddaf087bcb73e07a157e
7
- data.tar.gz: a726a7585b18c684ce71153b2c964100cd3b52ce62f1d9b0b78581e9b591947951b04a5b6990afbe12daa4ef7c088f6dd17ef99fd0a199b32ce4792d8a15ac6b
6
+ metadata.gz: 5857ce4ebc1a8b24b59a1ce22e63cdaa9384724401d6aae189a3345c952ce74e22332b2a0a25ec3cf2bc3e3f059f298ca9455e391028f20675cd2069adeb4f3e
7
+ data.tar.gz: 97a5207333d77ece64e71b7883f8198bdd8fad5f47f772d72d6f438aaebb3e95ff6179bdbfd81d07574a033181a50642a2ede5f155aa6e62e1453e0170bc3770
data/README.md CHANGED
@@ -21,6 +21,15 @@ yum group install "Development Tools"
21
21
  yum install ruby-devel
22
22
  ```
23
23
 
24
+ # documentation
25
+
26
+ - see [https://github.com/ogaida/usd/wiki](https://github.com/ogaida/usd/wiki)
27
+ - if you are looking for dependencies in between the objects, objectnames or relational objects, then have a look at [techdocs.broadcom.com](https://techdocs.broadcom.com/content/broadcom/techdocs/us/en/ca-enterprise-software/business-management/ca-service-management/14-1/reference/ca-service-desk-manager-reference-commands/objects-and-attributes.html)
28
+
29
+ ## bash-completion
30
+
31
+ see [https://github.com/ogaida/usd/wiki/bash-completion](https://github.com/ogaida/usd/wiki/bash-completion)
32
+
24
33
  # external tools
25
34
 
26
35
  If you use the `rusdc find` command with `--format mlr` option then you need `mlr`.
@@ -32,28 +41,31 @@ Place the `mlr`-binary in a path, which is in your PATH-Environment. Download-Ur
32
41
  # functions from the commandline-tool `rusdc`
33
42
 
34
43
  ```
35
- rusdc
36
- Commands:
37
- rusdc chg_add_nr <co> <ci> # add a CI to a changeorder
38
- rusdc chg_list_nr <co> # list all CIs of one changeorder
39
- rusdc create # pipe json-data to create object
40
- rusdc field_names <object-type> # list all fields of an object including its format
41
- rusdc find <object-type> [where-clause] [fields, comma separated] [options] # finds each object which meets the wc-condition
42
- rusdc get <object-type> <common_name> # shows one object
43
- rusdc get_attachment_of_ci <ci_name> <filename> # download an attachment of a CI and print it out on stdout
44
- rusdc get_attachment_of_co <co_name> <filename> # download an attachment of a changeorder and print it out on stdout
45
- rusdc help [COMMAND] # Describe available commands or one specific command
46
- rusdc in_list_child_ins <in> # list all child-incidents of one incident
47
- rusdc list_attachments_of_ci <ci_name> # list all attachments of a CI
48
- rusdc list_attachments_of_co <co_name> # list all attachments of a changeorder
49
- rusdc nr_add_child <nr-name> <child-name> # add one child CI to another CI
50
- rusdc nr_changes <nr> [inactive-too] # list all open changeorders of one CI
51
- rusdc nr_childs <ci-name> # lists all childs CIs of a specific CI
52
- rusdc nr_incidents <nr> [inactive-too] # lists all incident of a specific CI
53
- rusdc nr_parents <ci-name> # lists all parent CIs of a specific CI
54
- rusdc update # pipe json-data to update object
55
- rusdc update_attr <obj> <common_name> <key> <value> # updates a direct (not referenced) attribute of one object.
56
- rusdc update_ref_attr <obj> <common_name> <key> <value> # updates a referenced attribute of one object.
44
+ rusdc chg_add_nr <co> <ci> # add a CI to a changeorder
45
+ rusdc chg_list_nr <co> # list all CIs of one changeorder
46
+ rusdc create # pipe json-data to create object
47
+ rusdc field_names <object-type> [wc] # list all fields of an object including its format
48
+ rusdc find <object-type> [where-clause] [fields, comma separated] [options] # finds each object which meets the wc-condition
49
+ rusdc get <object-type> <common_name|id> # shows one object by name or id
50
+ rusdc get_all_attachments_of_co <co_name> # get all attachments of a changeorder and save all th...
51
+ rusdc get_attachment_of_ci <ci_name> <filename> # download an attachment of a CI and print it out on s...
52
+ rusdc get_attachment_of_co <co_name> <filename> # download an attachment of a changeorder and print it...
53
+ rusdc help [COMMAND] # Describe available commands or one specific command
54
+ rusdc in_add_2_chg <changeorder> <incident> # add incident to changeorder
55
+ rusdc in_list_child_ins <in> # list all child-incidents of one incident
56
+ rusdc list_attachments_of_ci <ci_name> # list all attachments of a CI
57
+ rusdc list_attachments_of_co <co_name> # list all attachments of a changeorder
58
+ rusdc nr_add_child <nr-name> <child-name> # add one child CI to another CI
59
+ rusdc nr_add_org <nr> <org> # add an Organisation to a ConfigurationItem
60
+ rusdc nr_changes <nr> [inactive-too] # list all open changeorders of one CI
61
+ rusdc nr_childs <ci-name> # lists all childs CIs of a specific CI
62
+ rusdc nr_incidents <nr> [inactive-too] # lists all incident of a specific CI
63
+ rusdc nr_parents <ci-name> # lists all parent CIs of a specific CI
64
+ rusdc update # pipe json-data to update object
65
+ rusdc update_attr <obj> <common_name|wc> <key> <value> # updates a direct (not referenced) attribute of one o...
66
+ rusdc update_attr_by_id <obj> <id> <key> <value> # updates a plain attribute of one object by id, does ...
67
+ rusdc update_ref_attr <obj> <common_name> <key> <value> # updates a referenced attribute of one object.
68
+ rusdc update_ref_attr_by_id <obj> <id> <key> <value_id> # updates a referenced attribute of one object_id by v...
57
69
  ```
58
70
 
59
71
  # environment-variables
@@ -81,3 +93,14 @@ then
81
93
  export usdpass
82
94
  fi
83
95
  ```
96
+
97
+ # example - find records
98
+
99
+ ```bash
100
+ $ rusdc find nr "name like 'foo%'" name,description --format mlr
101
+ name description
102
+ foo1 foo QS
103
+ foo2 foo TEST
104
+ ```
105
+
106
+ more examples under [find examples-Wikipage](https://github.com/ogaida/usd/wiki/find-examples) or in the [change_log](https://github.com/ogaida/usd/blob/master/change_log.md)
data/bin/rusdc CHANGED
@@ -89,6 +89,7 @@ class Rusdc < Thor
89
89
  option :nice_time, :type => :boolean, :default => true,:banner => "[true|false]"
90
90
  option :debug, :type => :boolean, :default => false,:banner => "[true|false]"
91
91
  def find(object, wc="", fields="@COMMON_NAME")
92
+ exitcode=0
92
93
  unless (fields =~ /^[\w\_,@]+$/)
93
94
  puts "fields-problem: there must be only letters, numbers, comma, the @-sign or underscore, nothing else!"
94
95
  else
@@ -96,6 +97,7 @@ class Rusdc < Thor
96
97
  mlr_array = []
97
98
  con.debug = options[:debug]
98
99
  e = con.search(object,{'fields' => fields,"wc" => wc})
100
+ exitcode=1 if e.count == 0
99
101
  fields_array=fields.split(/,/)
100
102
  e.each do |elem|
101
103
  # init all requested keys with empty strings, better for mlr format and needed for fields-order
@@ -105,7 +107,7 @@ class Rusdc < Thor
105
107
  elem.keys.each do |elem_key|
106
108
  if options[:nice_time]
107
109
  if elem_key =~ /(date|last_mod|warranty_start|warranty_end|time_stamp)$/
108
- elem[elem_key]=Time.at(elem[elem_key]).to_s
110
+ elem[elem_key]=Time.at(elem[elem_key]).to_s if elem[elem_key] != "" # not empty
109
111
  end
110
112
  end
111
113
  if fields_array.include?(elem_key)
@@ -125,9 +127,11 @@ class Rusdc < Thor
125
127
  case options[:format]
126
128
  when "json"
127
129
  puts mlr
130
+ exit exitcode
128
131
  when "yaml"
129
132
  # keys not sorted, maybe a todo
130
133
  puts e.to_yaml
134
+ exit exitcode
131
135
  when "mlr"
132
136
  # hierfuer muss mlr verfuegbar sein
133
137
  file = Tempfile.new('json')
@@ -136,8 +140,10 @@ class Rusdc < Thor
136
140
  file.close
137
141
  puts `#{cmd}`
138
142
  file.unlink
143
+ exit exitcode
139
144
  else
140
145
  puts "das Format #{options[:format]} ist nicht hinterlegt. Es gibt nur json, yaml oder mlr."
146
+ exit 2
141
147
  end
142
148
  end # fields check
143
149
  end
@@ -166,7 +172,7 @@ class Rusdc < Thor
166
172
  chg_id=loadcon.request("/caisd-rest/chg/COMMON_NAME-#{coname}")["chg"]["@id"]
167
173
  att_nr = loadcon.search("lrel_attachments_changes",{'fields' => "attmnt","wc" => "chg = #{chg_id}"})
168
174
  att_nr.each do |att|
169
- attmnt = loadcon.request("/caisd-rest/attmnt/COMMON_NAME-#{att["attmnt"]["@COMMON_NAME"]}")["attmnt"]
175
+ attmnt = loadcon.request("/caisd-rest/attmnt/#{att["attmnt"]["@id"]}")["attmnt"]
170
176
  filename = attmnt["orig_file_name"]
171
177
  puts "save #{filename}"
172
178
  f = File.open(filename, 'w')
@@ -180,7 +186,7 @@ class Rusdc < Thor
180
186
  def get_attachment_of_ci(ciname, filename)
181
187
  att_nr = loadcon.search("lrel_attachments_nr",{'fields' => "attmnt","wc" => "nr.name = '#{ciname}'"})
182
188
  att_nr.each do |att|
183
- attmnt = loadcon.request("/caisd-rest/attmnt/COMMON_NAME-#{att["attmnt"]["@COMMON_NAME"]}")["attmnt"]
189
+ attmnt = loadcon.request("/caisd-rest/attmnt/#{att["attmnt"]["@id"]}")["attmnt"]
184
190
  if attmnt["orig_file_name"] == filename
185
191
  puts loadcon.request("/caisd-rest/attmnt/#{attmnt["@id"]}/file-resource",{:unchanged => true})
186
192
  end
@@ -192,7 +198,7 @@ class Rusdc < Thor
192
198
  chg_id=loadcon.request("/caisd-rest/chg/COMMON_NAME-#{coname}")["chg"]["@id"]
193
199
  att_nr = loadcon.search("lrel_attachments_changes",{'fields' => "attmnt","wc" => "chg = #{chg_id}"})
194
200
  att_nr.each do |att|
195
- attmnt = loadcon.request("/caisd-rest/attmnt/COMMON_NAME-#{att["attmnt"]["@COMMON_NAME"]}")["attmnt"]
201
+ attmnt = loadcon.request("/caisd-rest/attmnt/#{att["attmnt"]["@id"]}")["attmnt"]
196
202
  if attmnt["orig_file_name"] == filename
197
203
  puts loadcon.request("/caisd-rest/attmnt/#{attmnt["@id"]}/file-resource",{:unchanged => true})
198
204
  end
@@ -213,7 +219,7 @@ class Rusdc < Thor
213
219
  def list_attachments_of_ci(ciname)
214
220
  att_nr = loadcon.search("lrel_attachments_nr",{'fields' => "attmnt","wc" => "nr.name = '#{ciname}'"})
215
221
  att_nr.each do |att|
216
- puts loadcon.request("/caisd-rest/attmnt/COMMON_NAME-#{att["attmnt"]["@COMMON_NAME"]}")["attmnt"]["orig_file_name"]
222
+ puts loadcon.request("/caisd-rest/attmnt/#{att["attmnt"]["@id"]}")["attmnt"]["orig_file_name"]
217
223
  end
218
224
  end
219
225
 
@@ -222,7 +228,7 @@ class Rusdc < Thor
222
228
  chg_id=loadcon.request("/caisd-rest/chg/COMMON_NAME-#{coname}")["chg"]["@id"]
223
229
  att_nr = loadcon.search("lrel_attachments_changes",{'fields' => "attmnt","wc" => "chg = #{chg_id}"})
224
230
  att_nr.each do |att|
225
- puts loadcon.request("/caisd-rest/attmnt/COMMON_NAME-#{att["attmnt"]["@COMMON_NAME"]}")["attmnt"]["orig_file_name"]
231
+ puts loadcon.request("/caisd-rest/attmnt/#{att["attmnt"]["@id"]}")["attmnt"]["orig_file_name"]
226
232
  end
227
233
  end
228
234
 
@@ -244,6 +250,24 @@ class Rusdc < Thor
244
250
  puts loadcon.create({:type => "json", :data => json})
245
251
  end
246
252
 
253
+ desc "nr_add_org <nr> <org>", "add an Organisation to a ConfigurationItem"
254
+ def nr_add_org(nr, org)
255
+ template = ERB.new <<-EOF
256
+ {
257
+ "lrel_oenv_orgref": {
258
+ "nr": {
259
+ "@id": "<%= uid_nr %>"
260
+ },
261
+ "org": {
262
+ "@id": "<%= uid_org %>"
263
+ }
264
+ }
265
+ }
266
+ EOF
267
+ json = template.result_with_hash(:uid_org => loadcon.request("/caisd-rest/org/COMMON_NAME-#{org}")["org"]["@id"], :uid_nr => loadcon.request("/caisd-rest/nr/COMMON_NAME-#{nr}")["nr"]["@id"])
268
+ puts loadcon.create({:type => "json", :data => json})
269
+ end
270
+
247
271
  desc "nr_changes <nr> [inactive-too]", "list all open changeorders of one CI"
248
272
  option :inactive_too, :type => :boolean, :default => false
249
273
  def nr_changes(nr)
@@ -377,7 +401,13 @@ class Rusdc < Thor
377
401
  :k => k,
378
402
  :v => v
379
403
  })
380
- puts loadcon.update({:type => "json", :data => json})
404
+ data = loadcon.update({:type => "json", :data => json})
405
+ if data.class == RestClient::BadRequest
406
+ puts "direkte Ausführung bekommt einen BadRequest, versuche Update über IDs. #{Usd::CN["cnt"]}"
407
+ #find(obj, wc="obj", fields="@COMMON_NAME")
408
+ else
409
+ puts data
410
+ end
381
411
  end
382
412
 
383
413
  desc "update_ref_attr_by_id <obj> <id> <key> <value_id>", "updates a referenced attribute of one object_id by value-id"
@@ -1,4 +1,124 @@
1
- # changelog
1
+ # rusdc changelog
2
+
3
+ ## 0.3
4
+
5
+ - some common_name resolution
6
+
7
+ ```ruby
8
+ class Usd
9
+ CN={
10
+ "chg" => "chg_ref_num",
11
+ "cnt" => "combo_name",
12
+ "arcpur_rule" => "name",
13
+ "ca_tou" => "name",
14
+ "cost_cntr" => "name",
15
+ "country" => "name",
16
+ "dept" => "name",
17
+ "gl_code" => "name",
18
+ "job_func" => "name",
19
+ "loc" => "name",
20
+ "nr" => "name",
21
+ "opsys" => "name",
22
+ "org" => "name",
23
+ "tab" => "name",
24
+ "auto_close" => "sym",
25
+ "aty" => "sym",
26
+ "act_type_assoc" => "sym",
27
+ "ca_cmpny" => "sym",
28
+ "closure_code" => "sym",
29
+ "cmth" => "sym",
30
+ "symptom_code" => "sym",
31
+ "state" => "sym",
32
+ "crt" => "sym",
33
+ "ctab" => "sym",
34
+ "ctp" => "sym",
35
+ "dcon_typ" => "sym",
36
+ "dlgsrvr" => "sym",
37
+ "dmn" => "sym",
38
+ "doc_rep" => "sym",
39
+ "fmgrp" => "sym",
40
+ "ical_alarm" => "sym",
41
+ "ical_event_template" => "sym",
42
+ "imp" => "sym",
43
+ "intfc" => "sym",
44
+ "kwrd" => "sym",
45
+ "mfrmod" => "sym",
46
+ "mgsstat" => "sym",
47
+ "nrf" => "sym",
48
+ "options" => "sym",
49
+ "outage_type" => "sym",
50
+ "perscnt" => "sym",
51
+ "position" => "sym",
52
+ "pr_trans" => "sym",
53
+ "prod" => "sym",
54
+ "quick_tpl_types" => "sym",
55
+ "rc" => "sym",
56
+ "resocode" => "sym",
57
+ "resomethod" => "sym",
58
+ "response" => "sym",
59
+ "rrf" => "sym",
60
+ "rss" => "sym",
61
+ "seq" => "sym",
62
+ "sev" => "sym",
63
+ "site" => "sym",
64
+ "slatpl" => "sym",
65
+ "special_handling" => "sym",
66
+ "svc_contract" => "sym",
67
+ "typecnt" => "sym",
68
+ "tz" => "sym",
69
+ "tspan" => "sym",
70
+ "transition_type" => "sym",
71
+ "urg" => "sym",
72
+ "vpt" => "sym",
73
+ "wrkshft" => "sym",
74
+ "cr" => "ref_num",
75
+ "in" => "ref_num",
76
+ "pr" => "ref_num"
77
+ }
78
+ end
79
+ ```
80
+
81
+ ## 0.2.5.3
82
+
83
+ - neu function : `rusdc nr_add_org <nr> <org> # add an Organisation to a ConfigurationItem`
84
+
85
+ #### fixes:
86
+
87
+ - rusdc - line 110: more robust when querying date fields
88
+
89
+ ## 0.2.4.2
90
+
91
+ the same fixes as in 0.2.4.1 for:
92
+
93
+ ```
94
+ rusdc list_attachments_of_ci <ci_name>
95
+ rusdc list_attachments_of_co <co_name>
96
+ ```
97
+
98
+ ## 0.2.4.1
99
+
100
+ ### fixes
101
+
102
+ - `rusdc get_attachment_of_ci` : attachment with spaces in path could not be downloaded
103
+
104
+ ## 0.2.4
105
+
106
+ - find function has exitcode > 0 if no records has been found
107
+
108
+ ```
109
+ $ rusdc find nr "name = 'not_here'" || echo 'i am not here, please create me'
110
+ []
111
+ i am not here, please create me
112
+ $ rusdc find cnt "last_name = 'Gaida'" && echo 'i am here, you may update me'
113
+ [{
114
+ "@COMMON_NAME": "Gaida, Oliver "
115
+ }]
116
+ i am here, you may update me
117
+ ```
118
+
119
+ ### fixes
120
+
121
+ - `rusdc get_all_attachments_of_co` : attachment with spaces in path could not be downloaded
2
122
 
3
123
  ## 0.2.3
4
124
 
data/lib/usd.rb CHANGED
@@ -10,6 +10,76 @@ require 'tempfile'
10
10
 
11
11
  class Usd
12
12
 
13
+ CN={
14
+ "chg" => "chg_ref_num",
15
+ "cnt" => "combo_name",
16
+ "arcpur_rule" => "name",
17
+ "ca_tou" => "name",
18
+ "cost_cntr" => "name",
19
+ "country" => "name",
20
+ "dept" => "name",
21
+ "gl_code" => "name",
22
+ "job_func" => "name",
23
+ "loc" => "name",
24
+ "nr" => "name",
25
+ "opsys" => "name",
26
+ "org" => "name",
27
+ "tab" => "name",
28
+ "auto_close" => "sym",
29
+ "aty" => "sym",
30
+ "act_type_assoc" => "sym",
31
+ "ca_cmpny" => "sym",
32
+ "closure_code" => "sym",
33
+ "cmth" => "sym",
34
+ "symptom_code" => "sym",
35
+ "state" => "sym",
36
+ "crt" => "sym",
37
+ "ctab" => "sym",
38
+ "ctp" => "sym",
39
+ "dcon_typ" => "sym",
40
+ "dlgsrvr" => "sym",
41
+ "dmn" => "sym",
42
+ "doc_rep" => "sym",
43
+ "fmgrp" => "sym",
44
+ "ical_alarm" => "sym",
45
+ "ical_event_template" => "sym",
46
+ "imp" => "sym",
47
+ "intfc" => "sym",
48
+ "kwrd" => "sym",
49
+ "mfrmod" => "sym",
50
+ "mgsstat" => "sym",
51
+ "nrf" => "sym",
52
+ "options" => "sym",
53
+ "outage_type" => "sym",
54
+ "perscnt" => "sym",
55
+ "position" => "sym",
56
+ "pr_trans" => "sym",
57
+ "prod" => "sym",
58
+ "quick_tpl_types" => "sym",
59
+ "rc" => "sym",
60
+ "resocode" => "sym",
61
+ "resomethod" => "sym",
62
+ "response" => "sym",
63
+ "rrf" => "sym",
64
+ "rss" => "sym",
65
+ "seq" => "sym",
66
+ "sev" => "sym",
67
+ "site" => "sym",
68
+ "slatpl" => "sym",
69
+ "special_handling" => "sym",
70
+ "svc_contract" => "sym",
71
+ "typecnt" => "sym",
72
+ "tz" => "sym",
73
+ "tspan" => "sym",
74
+ "transition_type" => "sym",
75
+ "urg" => "sym",
76
+ "vpt" => "sym",
77
+ "wrkshft" => "sym",
78
+ "cr" => "ref_num",
79
+ "in" => "ref_num",
80
+ "pr" => "ref_num"
81
+ }
82
+
13
83
  RestClient.proxy = ""
14
84
 
15
85
  attr_reader :base_url, :user, :access_key, :expiration_date, :debug
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'usd'
3
- spec.version = '0.2.3'
4
- spec.date = '2019-12-06'
3
+ spec.version = '0.3'
4
+ spec.date = '2020-08-31'
5
5
  spec.summary = "SDM REST-API-Calls"
6
6
  spec.description = "a Ruby class and a commandlinetool for SDM REST-API-Calls"
7
7
  spec.authors = ["Oliver Gaida"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oliver Gaida
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-06 00:00:00.000000000 Z
11
+ date: 2020-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor