Class: NexposeSCCM::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/nexpose_sccm/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, collection_id = nil, member_count = 0) ⇒ Collection

Returns a new instance of Collection.



6
7
8
9
10
11
12
# File 'lib/nexpose_sccm/collection.rb', line 6

def initialize(name, collection_id=nil, member_count=0)
  @name = name
  @collection_id = collection_id
  @member_count = member_count
  @current_members = Set.new
  @members = Set.new
end

Instance Attribute Details

#collection_idObject (readonly)

Returns the value of attribute collection_id.



3
4
5
# File 'lib/nexpose_sccm/collection.rb', line 3

def collection_id
  @collection_id
end

#current_membersObject

Returns the value of attribute current_members.



4
5
6
# File 'lib/nexpose_sccm/collection.rb', line 4

def current_members
  @current_members
end

#member_countObject (readonly)

Returns the value of attribute member_count.



3
4
5
# File 'lib/nexpose_sccm/collection.rb', line 3

def member_count
  @member_count
end

#membersObject

Returns the value of attribute members.



4
5
6
# File 'lib/nexpose_sccm/collection.rb', line 4

def members
  @members
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/nexpose_sccm/collection.rb', line 3

def name
  @name
end

Instance Method Details

#save(conn) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/nexpose_sccm/collection.rb', line 14

def save(conn)
  if @collection_id.nil?
    NexposeSCCM.logger.info("Creating collection #{@name} prior to populating")
    Powershell.run(conn.conn, :create_collection, conn.location, @name)

    @collection_id = conn.get_collection_id_by_name(@name)
  end

  #Devices to be added
  NexposeSCCM.logger.debug("Adding #{(@members - @current_members).length} devices to #{@name} collection")
  (@members - @current_members).each do |member|
    Powershell.run(conn.conn,
                   :add_device_to_collection,
                   conn.location,
                   @collection_id,
                   member.resource_id)
  end
  #Devices to be removed
  NexposeSCCM.logger.debug("Removing #{(@current_members - @members).length} devices from #{@name} collection")
  (@current_members - @members).each do |member|
    Powershell.run(conn.conn,
                   :remove_device_from_collection,
                   conn.location,
                   @collection_id,
                   member.resource_id)
  end
end