Class: VNMSH
- Inherits:
-
Object
- Object
- VNMSH
- Defined in:
- lib/vnmsh.rb
Overview
SpecTools::VNMSH
Represents a CLI session to VNMSH
Defined Under Namespace
Classes: CommandError, ConnectError, EnvironmentError, NotConnectedError
Class Attribute Summary collapse
-
.default_session ⇒ Object
The default session to use to execute VNMSH commands.
Instance Attribute Summary collapse
-
#current_landscape ⇒ Object
readonly
The currently connected landscape.
-
#reconnect_retries ⇒ Object
The number of reconncects performed before a command is considered unsuccessful.
-
#session_id ⇒ Object
readonly
The ID of the connected session.
Class Method Summary collapse
-
.get_session(arg) ⇒ Object
Take a parameter check to see if either the session was explictly passed, or if SpecTools::VNMSH#default_session is set.
Instance Method Summary collapse
-
#connect(ss = nil, landscape = nil) ⇒ Object
Connect to the SpectroSERVER If successful, returns a Landscape object indicating what landscape we connected to.
-
#connected? ⇒ Boolean
Returns true if the session is currently connceted to a SpectroSERVER.
-
#create_alarm(severity, cause, model, replace = false) ⇒ Object
Execute
create alarm. -
#create_association(relation, left_model, right_model) ⇒ Object
Execute
create association. -
#create_event(model, evcode, text = '') ⇒ Object
Execute
create event. -
#create_model(mtype, attrs = nil, landscape = nil) ⇒ Object
Execute
create modelwithout the IP option. -
#destroy_alarm(alarm, landscape = nil) ⇒ Object
Execute
destroy alarm. -
#destroy_association(relation, left_model, right_model) ⇒ Object
Execute
destroy association. -
#destroy_model(model) ⇒ Object
Execute
destroy model. -
#disconnect ⇒ Object
Disconnect from the SS.
-
#discover_device(ip, comm = nil, timeout = nil, retries = nil, sdm = nil, landscape = nil) ⇒ Object
Execute
create modelwith the IP option. -
#exec_cmd(cmd) ⇒ Object
Execute a VNMSH command.
-
#initialize(specroot = nil) ⇒ VNMSH
constructor
Create a new VNMSH session.
-
#seek(specattr, value = nil, substring = false, nocase = false, landscape = nil) ⇒ Object
Execute
seek. -
#show_alarms(type = :standard, mh_or_lh = nil, probcause = false) ⇒ Object
Execute the
show alarmscommand. -
#show_associations(mh) ⇒ Object
Execute
show associations. -
#show_attributes(type, mh_or_mth, filter = nil, enumerate = false) ⇒ Object
Execute
show attributes. -
#show_children(model, relation = nil) ⇒ Object
Execute
show children. -
#show_devices(landscape = nil) ⇒ Object
Execute
show devices. -
#show_enumerations(type = :all, mtype_landscape_attr = nil, landscape = nil) ⇒ Object
Execute
show enumerations. -
#show_events(type = :all, mh_or_lh = nil, limit = 2000, evformat = false) ⇒ Object
Execute
show events. -
#show_inheritance(mtype, landscape = nil) ⇒ Object
Execute
show inheritance. -
#show_invalid_mh_or_lh?(result) ⇒ Boolean
Check to see if the show response returned invalid model or landscape handle.
-
#show_landscapes ⇒ Object
Execute
show landscapes. -
#show_models(filter = nil) ⇒ Object
Execute the
show modelscommand. -
#show_parents(model, relation = nil) ⇒ Object
Execute
show parents. -
#show_relations(landscape = nil) ⇒ Object
Execute
show relations. -
#show_rules(relation, landscape = nil) ⇒ Object
Execute
show rules. -
#show_types(filter = nil) ⇒ Object
Execute
show types. -
#show_watch(model) ⇒ Object
Execute
show watch. -
#update_alarm(alarm, action, val = nil, replace = false) ⇒ Object
Execute
update alarm. -
#update_model(model, attrs) ⇒ Object
Execute
update model.
Constructor Details
#initialize(specroot = nil) ⇒ VNMSH
Create a new VNMSH session. specroot is accessed from the SPECROOT environement variable, if no specroot is passed.
894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 |
# File 'lib/vnmsh.rb', line 894 def initialize(specroot = nil) @vnmshdir = '/vnmsh/' vnmshcommands = ['ack','connect','create','destroy','disconnect','seek','show','update'] if specroot.nil? @specroot = ENV['SPECROOT'] else @specroot = specroot end vnmshcommands.each do |vnmshcommand| command = @specroot + @vnmshdir + vnmshcommand unless File.exists?(command) raise EnvironmentError, "Command #{command} is not available" end end @session_id = rand(20000) @connected = false @reconnect_retries = 3 end |
Class Attribute Details
.default_session ⇒ Object
The default session to use to execute VNMSH commands.
889 890 891 |
# File 'lib/vnmsh.rb', line 889 def default_session @default_session end |
Instance Attribute Details
#current_landscape ⇒ Object (readonly)
The currently connected landscape.
883 884 885 |
# File 'lib/vnmsh.rb', line 883 def current_landscape @current_landscape end |
#reconnect_retries ⇒ Object
The number of reconncects performed before a command is considered unsuccessful.
885 886 887 |
# File 'lib/vnmsh.rb', line 885 def reconnect_retries @reconnect_retries end |
#session_id ⇒ Object (readonly)
The ID of the connected session.
881 882 883 |
# File 'lib/vnmsh.rb', line 881 def session_id @session_id end |
Class Method Details
.get_session(arg) ⇒ Object
Take a parameter check to see if either the session was explictly passed, or if SpecTools::VNMSH#default_session is set. Returns a valid VNMSH object if successful. Raises ArgumentError if no valid VNMSH session is found.
917 918 919 920 921 922 923 924 925 |
# File 'lib/vnmsh.rb', line 917 def self.get_session(arg) if arg.instance_of? VNMSH return arg elsif VNMSH::default_session.instance_of? VNMSH return VNMSH::default_session else raise ArgumentError, 'You must pass a valid session or set SpecTools::VNMSH.default_session to a valid session' end end |
Instance Method Details
#connect(ss = nil, landscape = nil) ⇒ Object
Connect to the SpectroSERVER If successful, returns a Landscape object indicating what landscape we connected to. Returns a ConnectError if it fails
931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 |
# File 'lib/vnmsh.rb', line 931 def connect(ss = nil, landscape = nil) connectcmd = @specroot + '/vnmsh/connect ' unless ss.nil? connectcmd = connectcmd + ss end connectcmd = connectcmd + ' 2>&1' output = StringIO.new(`#{connectcmd}`) result = output.readline if result =~ /^connect: successful (.*)/ @current_landscape = Landscape.new() @current_landscape.ss = $1 output.readline =~ /current landscape is (0x\d+)/ @current_landscape.handle = $1 @connected = true return @current_landscape elsif result =~ /^connect: already connected to/ return @current_landscape else raise ConnectError, result end end |
#connected? ⇒ Boolean
Returns true if the session is currently connceted to a SpectroSERVER.
1004 1005 1006 |
# File 'lib/vnmsh.rb', line 1004 def connected? return @connected end |
#create_alarm(severity, cause, model, replace = false) ⇒ Object
Execute create alarm.
-
severityis the alarm severity. Allowable options are: -
CRITICAL
-
MAJOR
-
MINOR
-
SUPPRESSED
-
MAINTENANCE
-
INITIAL
-
causeis the probable cause code. -
modelis the model to assert the alarm on. -
modelcan be a Model object or a model handle. -
If
replaceis true, will replace an existing alarm on the model.
Returns the created Alarm object if sucessful, otherwise raises a CommandError.
1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 |
# File 'lib/vnmsh.rb', line 1791 def create_alarm(severity,cause,model,replace = false) createcmd = 'create alarm ' createcmd += '-nr ' if replace if severity =~ /CRITICAL/i || severity =~ /MAJOR/i || severity =~ /MINOR/i || severity =~ /SUPPRESSED/i || severity =~ /MAINTENANCE/i || severity =~ /INITIAL/i createcmd += "sev=#{severity} " else raise ArgumentError, 'Severity must be CRITICAL, MAJOR, MINOR, SUPPRESSED, MAINTENANCE, or INITIAL' end if cause.instance_of?(Alarm) createcmd += "cause=#{cause.causeid} " elsif cause.kind_of?(String) createcmd += "cause=#{cause} " else raise ArgumentError, 'You must pass a valid Probable Cause code' end createcmd += 'mh='+get_handle(model,Model) output = exec_cmd(createcmd).readlines if output.first =~ /^ID/ return Alarm.parse(output.last) else raise CommandError, output.last end end |
#create_association(relation, left_model, right_model) ⇒ Object
Execute create association.
relation can be a Relation object or a relation name. left_model and right_model can be a Model object or a model handle.
1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 |
# File 'lib/vnmsh.rb', line 1751 def create_association(relation,left_model,right_model) createcmd = 'create association ' createcmd += ' rel=' + get_relation(relation) createcmd += ' lmh=' createcmd += get_handle(left_model,Model) createcmd += ' rmh=' createcmd += get_handle(right_model,Model) output = exec_cmd(createcmd) result = output.readlines.last if result =~ /create association: successful/ if relation.kind_of? String rel = Relation.new(rel) end if left_model.kind_of? String left_model = Model.new(left_model) end if right_model.kind_of? String right_model = Model.new(right_model) end return Association.new(left_model,right_model,relation) else raise CommandError, result end end |
#create_event(model, evcode, text = '') ⇒ Object
Execute create event.
model can be a Model or a model handle. evcode is a valid event code. text is the event text.
Returns true if the event was created, otherwise returns a CommandError.
1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 |
# File 'lib/vnmsh.rb', line 1829 def create_event(model,evcode,text='') createcmd = 'create event type=' if evcode.instance_of?(Event) createcmd += evcode.type createcmd += ' text=\"' + evcode. + '\"' elsif evcode.kind_of?(String) && evcode.hex? createcmd += evcode createcmd += ' text=\"' + text + '\"' else raise ArgumentError, 'You must pass a valid Event Code' end createcmd += ' mh=' + get_handle(model,Model) output = exec_cmd((createcmd)) if $?.exitstatus > 0 raise CommandError, output.readlines.first else return true end end |
#create_model(mtype, attrs = nil, landscape = nil) ⇒ Object
Execute create model without the IP option. mtype may either be a valid MType object, or a model type handle. attrs is an array of Attr objects that you want to be set on the model when it is created. landscape is the landscape you wish to create the model on. landscape may be a Landscape object or a landscape handle.
1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 |
# File 'lib/vnmsh.rb', line 1654 def create_model(mtype,attrs=nil,landscape=nil) createcmd = 'create model mth=' createcmd += get_handle(mtype,MType) createcmd += (attrs) if attrs createcmd += ' lh=' + get_handle(landscape,Landscape) if landscape output = exec_cmd((createcmd)) result = output.readlines.last if result =~ /created model handle\s+=\s+(0x[0-f]+)/ model = Model.new model.handle = $1 model.attrs = attrs if mtype.instance_of?(MType) model.type = mtype else model.type = MType.new(mtype) end return model else raise CommandError, result end end |
#destroy_alarm(alarm, landscape = nil) ⇒ Object
Execute destroy alarm
alarm can be an Alarm or an alarm ID.
If landscape is set, will detroy the alarm on the specified landscape. landscape can be a Landscape object or a valid landscape handle.
Returns true if the destroy succeeded, otherwise CommandError is raised.
1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 |
# File 'lib/vnmsh.rb', line 1604 def destroy_alarm(alarm,landscape=nil) destroycmd = 'destroy alarm -n aid=' + get_id(alarm,Alarm) destroycmd += ' lh=' + get_handle(landscape,Landscape) if landscape output = exec_cmd(destroycmd) result = output.readlines.last if result =~ /destroy alarm: successful/ return true else raise CommandError, result end end |
#destroy_association(relation, left_model, right_model) ⇒ Object
Execute destroy association.
Returns true if the destroy succeeded, otherwise CommandError is raised.
1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 |
# File 'lib/vnmsh.rb', line 1579 def destroy_association(relation,left_model,right_model) destroycmd = 'destroy association -n ' destroycmd += ' rel=' + get_relation(relation) destroycmd += ' lmh=' + get_handle(left_model,Model) destroycmd += ' rmh=' + get_handle(right_model,Model) output = exec_cmd(destroycmd) result = output.readlines.last if result =~ /destroy association: successful/ return true else raise CommandError, result end end |
#destroy_model(model) ⇒ Object
Execute destroy model.
model can either be a Model or a model handle
Returns true if the destroy succeeded, otherwise CommandError is raised.
1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 |
# File 'lib/vnmsh.rb', line 1564 def destroy_model(model) destroycmd = 'destroy model -n mh=' + get_handle(model,Model) output = exec_cmd(destroycmd) result = output.readlines.last if result =~ /destroy model: successful/ return true else raise CommandError, result end end |
#disconnect ⇒ Object
Disconnect from the SS. Returns true if the command succeeds, otherwise returns the error string of the disconnect. Either way, session will be marked as disconnected.
956 957 958 959 960 961 962 963 964 965 966 967 |
# File 'lib/vnmsh.rb', line 956 def disconnect disconnectcmd = @specroot + '/vnmsh/disconnect 2>&1' output = StringIO.new(`#{disconnectcmd}`) @connected = false @current_landscape = nil result = output.readline if result =~ /^disconnect: successful/ return true else return result end end |
#discover_device(ip, comm = nil, timeout = nil, retries = nil, sdm = nil, landscape = nil) ⇒ Object
Execute create model with the IP option.
Options:
-
ip- Required. The device’s IP address. -
comm- Optional. The community string. -
timeout- Optional. The device’s timeout. -
retries- Optional. The number of times to attempt to contact the device. -
sdm- Optional. The address of the Secure Domain Connector. -
landscape- Optional. The landscape to create the device on.
If creation is sucessful, returns a new Model with the handle filled in. otherwise, raises a CommandError.
1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 |
# File 'lib/vnmsh.rb', line 1629 def discover_device(ip,comm=nil,timeout=nil,retries=nil,sdm=nil,landscape=nil) createcmd = 'create model ip=' + ip createcmd += ' sec_dom=' + sdm if sdm createcmd += ' comm=' + comm if comm createcmd += ' to=' + timeout if timeout createcmd += ' tc=' + retries if retries createcmd += ' lh=' + get_handle(landscape,Landscape) if landscape output = exec_cmd(createcmd) result = output.readlines.last if result =~ /created model handle\s+=\s+(0x[0-f]+)/ model = Model.new model.handle = $1 return model else raise CommandError, result end end |
#exec_cmd(cmd) ⇒ Object
Execute a VNMSH command. Returns a StringIO object with the command’s output. Raises a NotConnectedError if the command exceeds reconnect_retries.
973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 |
# File 'lib/vnmsh.rb', line 973 def exec_cmd(cmd) @retries = 0 unless self.connected? raise NotConnectedError end cmd = @specroot + '/vnmsh/' + cmd + ' 2>&1' ENV['CLIMNAMEWIDTH'] = 1024.to_s ENV['CLISESSID'] = self.session_id.to_s begin output = `#{cmd}` if $?.exitstatus > 0 && StringIO.new(output).readline =~ /Please connect first/ raise NotConnectedError else return StringIO.new(output) end rescue NotConnectedError @retries = @retries + 1 unless @retries > self.reconnect_retries self.disconnect self.connect retry else raise end end end |
#seek(specattr, value = nil, substring = false, nocase = false, landscape = nil) ⇒ Object
Execute seek.
specattr may be an Attr object or an attribute ID. If specattr is an Attr and has the value attribute set, value does not have to be set. However, you can override the Attr object’s value in the search by providing your own value.
If specattr.value is nil, or of specattr is simply an attribute ID, value must be set.
If substring is true, a partial string match is performed.
If nocase is true, case is ignored.
Returns a StringIO with the command’s ouput.
1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 |
# File 'lib/vnmsh.rb', line 1140 def seek(specattr,value=nil,substring=false,nocase=false,landscape=nil) seekcmd = 'seek' seekcmd += ' -s' if substring seekcmd += ' -i' if nocase seekcmd += ' attr=' + get_id(specattr,Attr) if specattr.kind_of?(Attr) value = specattr.value unless value end raise ArgumentError, 'When seeking by attribute, must pass in a SpecTools::Attr with a valid value, or an explict attribute value' unless value seekcmd += ',val="' + value + '"' seekcmd += ' lh=' + get_handle(landscape,Landscape) if landscape output = exec_cmd(seekcmd) result = output.readline if result =~ /^MHandle\s+/ return output else raise CommandError, result end end |
#show_alarms(type = :standard, mh_or_lh = nil, probcause = false) ⇒ Object
Execute the show alarms command.
Available show types:
-
:standard- Retrieves the standard list of alarms. -
:all- Retrieves all alarms, including MAINTENANCE. -
:model- Retrieves standard alarms for a given model. -
If set,
mh_or_lhmust be a valid Model or model handle. -
:model- Identical to :model, except returns all alarms. -
:landscape- Retrieves standards alarms for a given landscape. -
If set,
mh_or_lhmust be a valid Landscape or landscape handle.
Setting probcause to true will include the Probable Cause information in the message attribute of each Alarm.
Returns a StringIO with the command’s ouput.
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 |
# File 'lib/vnmsh.rb', line 1036 def show_alarms(type=:standard,mh_or_lh=nil,probcause=false) valid_types = [ :standard, :model, :model_all, :landscape, :landscape_all, :all ] showcmd = 'show alarms ' valid_type = false valid_types.each do |v_type| valid_type = v_type || valid_type end raise ArgumentError, 'Valid show types are :standard, :all, :model, :model_all, :landscape, or :landscape_all' unless valid_type if type == :all || type == :model_all || type == :landscape_all showcmd = showcmd + ' -a ' end showcmd = showcmd + ' -x ' if probcause if type == :model_all || type == :model showcmd += ' mh=' showcmd = showcmd + get_handle(mh_or_lh,Model) end if type == :landscape_all || type == :landscape showcmd += ' lh=' showcmd = showcmd + get_handle(mh_or_lh,Landscape) end output = exec_cmd(showcmd) result = output.readline show_invalid_mh_or_lh?(result) if result =~ /^ID\s+/ return output end end |
#show_associations(mh) ⇒ Object
Execute show associations.
mh can be either a Model, or a model handle.
Returns a StringIO with the command’s ouput.
1253 1254 1255 1256 1257 1258 1259 1260 1261 |
# File 'lib/vnmsh.rb', line 1253 def show_associations(mh) showcmd = 'show associations ' + mh output = self.exec_cmd(showcmd) result = output.readline show_invalid_mh_or_lh?(result) if result =~ /^LMHandle\s+/ return output end end |
#show_attributes(type, mh_or_mth, filter = nil, enumerate = false) ⇒ Object
Execute show attributes
Available types:
-
:model - Get attributes for a given model.
-
When set, mh_or_mth must be a Model or a model handle.
-
If
enumerateis set, values will be automatically enumerated. -
:mtype - get attributes for a given model type.
-
When set, mh_or_mth must be a MType or a model type handle.
-
enumerateis ignored.
Filter options.
-
:id- returns the specific attribute. -
Only valid for the
:modeltype. -
Takes an Attr or an attribute ID.
-
Returns all instances for a list attribute.
-
Example:
show_attributes(:model,{:id,'0x10000'}) -
:instance= returns a specific instance of an attribute. -
Only valid for the
:modeltype. -
Takes a 2 element array.
-
The first element must be an Attr or an attribute id.
-
The second element must be an instance identifier.
-
-
Example:
show_attributes(:model,{:instance,['0x10000','192.168.1.1']}) -
:range- returns attributes whose ID in in the specified range. -
Valid for both
:modeland:mtypetypes. -
:range can take a single range string, or an array of Model handles or Models.
-
Example:
show_attributes(:mtype,{:range,['0x10000','0x1000a]) -
Example:
show_attributes(:model,{:range,'0x10000-0x1000a'}) -
:name- returns attributes whose name contains the specified string. -
Valid for both
:modeland:mtype. -
Example:
show_attributes(:mtype{:name,'Condition'}) -
:flag- returns attributes that have the specified flag set. -
Only valid for the
:mtypetype. -
Example:
show_attributes(:mtype,{:flag,'G'}) -
:lanscape- returns attributes in the specified landscape. -
Only valid for the
:mtypetype. -
landscape can be a Landscape object or a landscape handle.
-
Example:
show_attributes(:mtype,{:landscape,'0x400000'})
1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 |
# File 'lib/vnmsh.rb', line 1489 def show_attributes(type,mh_or_mth,filter=nil,enumerate=false) showcmd = 'show attributes ' if type == :model showcmd += ' -e ' if enumerate if filter filter.keys.each do |option| case option when :id showcmd += ' attr=' + get_id(filter[option],Attr) when :instance if filter[option].kind_of?(Attr) instance = filter[option].instance attrid = filter[option].id else instance = filter[option][1] attrid = filter[option][0] end raise ArgumentError, 'instance is not an instance identifier' unless instance =~ /^\d+(\.\d+)*$/ showcmd += ' attr=' + get_id(attrid,Attr) + ',iid=' + instance when :name showcmd += ' attrname=' + filter[option] when :range showcmd += ' attrr=' showcmd += filter[option] if filter[option].kind_of?(String) showcmd += get_id(filter[option][0],Attr) + '-' + get_id(filter[option][1],Attr) if filter[option].kind_of?(Array) end end end showcmd += ' mh=' + get_handle(mh_or_mth,Model) elsif type == :mtype showcmd += ' mth=' + get_handle(mh_or_mth,MType) if filter filter.keys.each do |option| case option when :range showcmd += ' attrr=' showcmd += filter[option] if filter[option].kind_of?(String) showcmd += get_id(filter[option][0],Attr) + '-' + get_id(filter[option][1],Attr) if filter[option].kind_of?(Array) when :name showcmd += ' attrname=' + filter[option] when :flag showcmd += ' flags=' + filter[option] when :landscape showcmd += ' lh=' + get_handle(filter[option],Landscape) end end end else raise ArgumentError, 'Valid types are :model or :mtype' end output = self.exec_cmd(showcmd) result = output.readline show_invalid_mh_or_lh?(result) if result =~ /^Id\s+/ return output elsif result =~ /invalid model type handle/ raise CommandError, result elsif result =~ /non list attribute/ raise CommandError, result elsif result =~ /invalid attribute/ raise CommandError,result elsif result =~ /invalid instance/ raise CommandError,result end end |
#show_children(model, relation = nil) ⇒ Object
Execute show children
model can be a Model or a model handle. If relation is set to a Relation or a relation name, only parents with the given relation will be retrieved.
Returns a StringIO with the command’s ouput.
1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 |
# File 'lib/vnmsh.rb', line 1294 def show_children(model,relation=nil) showcmd = 'show children ' showcmd += ' rel=' + get_relation(relation) if relation showcmd += ' mh=' + get_handle(model,Model) output = self.exec_cmd(showcmd) result = output.readline show_invalid_mh_or_lh?(result) if result =~ /^MHandle\s+/ return output elsif result =~ /invalid relation/ raise CommandError, result end end |
#show_devices(landscape = nil) ⇒ Object
Execute show devices
If landscape is set, only devices for the given landscape are gathered.
Returns a StringIO with the command’s ouput.
1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 |
# File 'lib/vnmsh.rb', line 1170 def show_devices(landscape = nil) showcmd = 'show devices ' showcmd += ' lh=' + get_handle(landscape,Landscape) if landscape output = self.exec_cmd(showcmd) result = output.readline show_invalid_mh_or_lh?(result) if result =~ /MHandle\s+/ return output end end |
#show_enumerations(type = :all, mtype_landscape_attr = nil, landscape = nil) ⇒ Object
Execute show enumerations
Available types are:
-
:mtype - enumerations by model type.
-
When set,
mtype_landscape_attrmust be a valid MType or a model type handle. -
May also specify an optional
landscape, which can be either a Landscape or a landscape handle. -
:landscape - all enumerations for a specific landscape.
-
When set,
mtype_landscape_attrmust be a valid Landscape or landscape handle. -
:attr - enumerations for a spceific attribute.
-
When set,
mtype_landscape_attrmust be an Attr or an attribute id.
Returns a StringIO with the command’s ouput.
1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 |
# File 'lib/vnmsh.rb', line 1399 def show_enumerations(type=:all,mtype_landscape_attr=nil,landscape=nil) showcmd = 'show enumerations ' case type when :mtype showcmd += ' mth=' + get_handle(mtype_landscape_attr,MType) showcmd += ' lh=' + get_handle(landscape,Landscape) if landscape when :landscape showcmd += ' lh=' + get_handle(mtype_landscape_attr,Landscape) when :attr showcmd += ' attr=' + get_id(mtype_landscape_attr,Attr) end output = self.exec_cmd(showcmd) result = output.readline show_invalid_mh_or_lh?(result) if result =~ /Id\s+/ return output elsif result =~ /invalid attribute/ raise CommandError, result elsif result =~ /invalid model type handle/ raise CommandError, result end end |
#show_events(type = :all, mh_or_lh = nil, limit = 2000, evformat = false) ⇒ Object
Execute show events
Available types:
-
:all- Retrieve all events. -
:model- Retrieve all events for a given model. -
If set, mh_or_lh must be a valid Model or a model handle.
-
:landscape- Retrieve all events for a given landscape. -
If set, mh_or_lh must be a valid Landscape or a landscape handle.
Options:
-
limit- Set the maximum number of events to retrieve. -
Default is 2000, Setting to :all is equivalent to setting to 10000
-
evformat- If set to true, populate the Events with the event message.
Returns a StringIO with the command’s ouput.
1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 |
# File 'lib/vnmsh.rb', line 1322 def show_events(type=:all,mh_or_lh=nil,limit=2000,evformat=false) showcmd = 'show events ' if limit == :all showcmd += ' -a ' elsif limit != 2000 && limit showcmd += ' -n ' + limit.to_s end if evformat showcmd += ' -x ' end if type == :model showcmd += ' mh=' + get_handle(mh_or_lh,Model) end if type == :landscape showcmd += ' lh=' + get_handle(mh_or_lh,Landscape) end output = self.exec_cmd(showcmd) result = output.readline show_invalid_mh_or_lh?(result) if result =~ /^Date\s+/ return output end end |
#show_inheritance(mtype, landscape = nil) ⇒ Object
Execute show inheritance
mtype can be an MType or a model type handle. If landscape is set, only gethers inheritance for the given landscape.
Returns a StringIO with the command’s ouput.
1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 |
# File 'lib/vnmsh.rb', line 1353 def show_inheritance(mtype,landscape = nil) showcmd = 'show inheritance mth=' + get_handle(mtype,MType) showcmd += ' lh=' + get_handle(landscape,Landscape) if landscape output = self.exec_cmd(showcmd) result = output.readline show_invalid_mh_or_lh?(result) if result =~ /^Handle\s+/ return output elsif result =~ /invalid model type handle/ raise CommandError, result end end |
#show_invalid_mh_or_lh?(result) ⇒ Boolean
Check to see if the show response returned invalid model or landscape handle.
1009 1010 1011 1012 1013 1014 1015 1016 1017 |
# File 'lib/vnmsh.rb', line 1009 def show_invalid_mh_or_lh?(result) if result =~ /invalid model handle/ raise CommandError, result elsif result =~ /invalid landscape handle/ raise CommandError, result elsif result =~ /no current model defined/ raise CommandError, result end end |
#show_landscapes ⇒ Object
Execute show landscapes
Returns a StringIO with the command’s ouput.
1441 1442 1443 1444 1445 1446 1447 1448 |
# File 'lib/vnmsh.rb', line 1441 def show_landscapes showcmd = 'show landscapes' output = self.exec_cmd(showcmd) result = output.readline if result =~ /SSName/ return output end end |
#show_models(filter = nil) ⇒ Object
Execute the show models command.
If no filter is passed, returns all model listings for the connected Landscape.
Filter options:
-
:range- filters on a range of models. -
Range can either be a single string, an Array of handles, or an Array of Models.
-
Example:
show_models({:range,'0x400000-0x500000'}) -
Example:
show_models(:range,['0x400000','0x500000']}) -
:name- filters on the model’s name (partials accepted) -
Example:
show_models{:name,'VNM'}) -
:landscape- filters on the given Landscape. -
Example:
show_models({:landscape,'0x400000'}) -
:mtype- Returns all models of the specified type. -
Type can either be an MType object, or a model type handle.
-
Examples:
-
show_models(:mtype, '0x13d0018') -
show_models(:mtype, MType.new('0x13d0018'))
-
Returns a StringIO with the command’s ouput.
1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 |
# File 'lib/vnmsh.rb', line 1094 def show_models(filter=nil) showcmd = 'show models ' if filter filter.keys.each do |option| case option when :range showcmd += ' mhr=' showcmd += filter[option] if filter[option].kind_of?(String) showcmd += get_handle(filter[option][0],Model) + '-' + get_handle(filter[option][1],Model) if filter[option].kind_of?(Array) when :type showcmd += ' mth=' + get_handle(filter[option],MType) when :name showcmd += ' mname="' + filter[option] + '"' when :landscape showcmd += ' lh=' + get_handle(filter[option],Landscape) else raise ArgumentError, 'Valid filter options are :range, :name, :type, or :landscape' end end end output = self.exec_cmd(showcmd) result = output.readline show_invalid_mh_or_lh?(result) if result =~ /MHandle\s+/ return output end end |
#show_parents(model, relation = nil) ⇒ Object
Execute show parents.
model can be a Model or a model handle. If relation is set to a Relation or a relation name, only parents with the given relation will be retrieved.
Returns a StringIO with the command’s ouput.
1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 |
# File 'lib/vnmsh.rb', line 1271 def show_parents(model,relation=nil) showcmd = 'show parents ' showcmd += ' rel=' + get_relation(relation) if relation showcmd += ' mh=' + get_handle(model,Model) output = self.exec_cmd(showcmd) result = output.readline show_invalid_mh_or_lh?(result) if result =~ /^MHandle\s+/ return output elsif result =~ /invalid relation/ raise CommandError, result end end |
#show_relations(landscape = nil) ⇒ Object
Execute show relations
If landscape is set to a Landscape or a ladnscape handle, shows relations for the given landscape.
Returns a StringIO with the command’s ouput.
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 |
# File 'lib/vnmsh.rb', line 1237 def show_relations(landscape=nil) showcmd = 'show relations ' showcmd += ' lh=' + get_handle(landscape,Landscape) if landscape output = self.exec_cmd(showcmd) result = output.readline show_invalid_mh_or_lh?(result) if result =~ /Name\s+/ return output end end |
#show_rules(relation, landscape = nil) ⇒ Object
Execute show rules
relation can be wither a Relation or a relation name. If lanscape is set to a Landscape or a landscape handle, will only show rules for the given landscape.
Returns a StringIO with the command’s ouput.
1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 |
# File 'lib/vnmsh.rb', line 1373 def show_rules(relation,landscape = nil) showcmd = 'show rules rel=' + get_relation(relation) showcmd += ' lh=' + get_handle(landscape,Landscape) if landscape output = self.exec_cmd(showcmd) result = output.readline show_invalid_mh_or_lh?(result) if result =~ /^LMTHandle\s+/ return output elsif result =~ /invalid relation/ raise CommandError, result end end |
#show_types(filter = nil) ⇒ Object
Execute show types
filter is a hash of filter types and thier values.
If no filter is passed, returns all model type listings for the connected Landscape. Filter options:
-
:flag- filters on the provided flag -
Example:
show_types({:flag,:unique}) -
:range- filters on a range of model types -
Range can either be a single string, an Array of handles, or an Array of MTypes.
-
Example:
show_types({:range,'0x400000-0x500000'}) -
Example:
show_types(:range,['0x400000','0x500000']}) -
:name- filters on the model type’s name (partials accepted) -
Example:
show_types({:name,'VNM'}) -
:landscape- filters on the given Landscape. -
Example:
show_types({:landscape,'0x400000'})
Returns a StringIO with the command’s ouput.
1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 |
# File 'lib/vnmsh.rb', line 1201 def show_types(filter=nil) showcmd = 'show types ' if filter filter.keys.each do |option| case option when :range showcmd += ' mthr=' showcmd += filter[option] if filter[option].kind_of?(String) showcmd += get_handle(filter[option][0],MType) + '-' + get_handle(filter[option][1],MType) if filter[option].kind_of?(Array) when :name showcmd += ' mtname="' + filter[option] + '"' when :flag showcmd += ' flags=' + filter[option] when :landscape showcmd += ' lh=' + get_handle(filter[option],Landscape) else raise ArgumentError, 'Valid filter options are :range, :name, :flag, or :landscape' end end end output = self.exec_cmd(showcmd) result = output.readline show_invalid_mh_or_lh?(result) if result =~ /Handle\s+/ return output end end |
#show_watch(model) ⇒ Object
Execute show watch
model can either be a Model or a model handle.
Returns a StringIO with the command’s ouput.
1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 |
# File 'lib/vnmsh.rb', line 1427 def show_watch(model) showcmd = 'show watch ' showcmd += ' mh=' + get_handle(model,Model) output = self.exec_cmd(showcmd) result = output.readline show_invalid_mh_or_lh?(result) if result =~ /^Watch_Id\s+/ return output end end |
#update_alarm(alarm, action, val = nil, replace = false) ⇒ Object
Execute update alarm. alarm can be an Alarm object or an alarm id. action is the field that will be updated. Valid actions are:
-
:assign -
:ticket -
:url -
:ack -
:status
action may also be a Hash of alarm attributes to set. If action is a single attribute, value must be set. replace will replace the existing value, as opposed to just appending. replace is only valid when updating :ticket and status.
1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 |
# File 'lib/vnmsh.rb', line 1711 def update_alarm(alarm,action,val=nil,replace=false) if action.kind_of?(Symbol) && val == nil raise ArgumentError, 'When updating an individual alarm attribute, you must pass a value' elsif action.kind_of?(Hash) && replace == true raise ArgumentError, 'Field replacement may only be done by updating a single alarm attribute' end unless action.kind_of?(Hash) || action.kind_of?(Symbol) raise ArgnumentError, 'Valid actions may be a single Symbol or a Hash' end updatecmd = 'update alarm aid=' if alarm.instance_of?(Alarm) updatecmd += alarm.id else updatecmd += alarm end if action.kind_of?(Symbol) updatecmd += ' -r ' if replace updatecmd += process_alarm_action(action,val) end if action.kind_of?(Hash) action.keys.each do |key| updatecmd += process_alarm_action(key,action[key]) end end result = exec_cmd((updatecmd)) if $?.exitstatus == 0 return true else raise CommandError, result end end |
#update_model(model, attrs) ⇒ Object
Execute update model. model can be a Model object or a model handle. attrs is an array of Attr objects to update.
Returns true if the update succeeded, or raises a CommandError.
1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 |
# File 'lib/vnmsh.rb', line 1682 def update_model(model,attrs) updatecmd = 'update mh=' updatecmd += get_handle(model,Model) updatecmd += (attrs) output = exec_cmd((updatecmd)) result = output.readlines.first if result =~ /^Id/ return true else raise CommandError, result end end |