Class: Org

Inherits:
Object
  • Object
show all
Defined in:
lib/satops/operator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(org) ⇒ Org

Returns a new instance of Org.



814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
# File 'lib/satops/operator.rb', line 814

def initialize(org)
  @id=org['id']
  @name=org['name']
  @active_users=org['active_users'] # Number of active users in the organization.
  @systems=org['systems'] # Number of systems in the organization.
  # API doesn't return trusts info wigh getDetails
  # @trusts=org['trusts'] # Number of trusted organizations.
  @users=org['users']
  @system_groups=org['system_groups'] # Number of system groups in the organization. (optional)
  @activation_keys=org['activation_keys'] # Number of activation keys in the organization. (optional)
  @kickstart_profiles=org['kickstart_profiles'] # Number of kickstart profiles in the organization. (optional)
  @configuration_channels=org['configuration_channels'] # Number of configuration channels in the organization. (optional)
  @system_entitlements=org['system_entitlements']
  @software_entitlements=org['software_entitlements']
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



793
794
795
# File 'lib/satops/operator.rb', line 793

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



793
794
795
# File 'lib/satops/operator.rb', line 793

def name
  @name
end

Class Method Details

.reader(sat, id) ⇒ Object



795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
# File 'lib/satops/operator.rb', line 795

def self.reader(sat, id)
  org={}
  org.merge!(sat.org.getDetails(id))
  org.merge!({'users'=>sat.org.listUsers(id)})
  if Orgs.entitlements
    org.merge!({'system_entitlements'=>sat.org.listSystemEntitlementsForOrg(id)})

    # Filter out empty software entitlements
    software_entitlements=sat.org.listSoftwareEntitlementsForOrg(id)
    if software_entitlements
      software_entitlements.delete_if do |entitlement|
        entitlement['allocated'] == 0 && entitlement['allocated_flex'] == 0
      end
      org.merge!({'software_entitlements'=>software_entitlements})
    end
  end
  org
end

Instance Method Details

#create(sat) ⇒ Object



830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
# File 'lib/satops/operator.rb', line 830

def create(sat)
  # Create org from the first user with admin privileges
  # Never handle default org (id=1)
  if @id != 1 && @active_users >= 1
    admin=get_admin
    if admin
      # Try to find that Org
      org=sat.org.getDetails(@name)

      unless org
        # Create Org if doesn't exit
        org=sat.org.create(@name, admin['login'], admin['login'], 'Mr.', admin['name'].split(',')[1], admin['name'].split(',')[0], admin['email'], false)
      end

      # Entitlements option activated
      if Orgs.entitlements
        unless org
          # case org already exist!
          org=sat.org.getDetails(@name)
        end

        if org
          # Systems Entitlements
          @system_entitlements.each do |system_entitlement|
            sat.org.setSystemEntitlements(org['id'], system_entitlement['label'], system_entitlement['allocated'])
          end

          # Software Entitlements
          @software_entitlements.each do |software_entitlement|
            sat.org.setSoftwareEntitlements(org['id'], software_entitlement['label'], software_entitlement['allocated'])
            sat.org.setSoftwareFlexEntitlements(org['id'], software_entitlement['label'], software_entitlement['allocated_flex'])
          end
        end
      end
    end
  end
end

#delete(sat) ⇒ Object



868
869
870
# File 'lib/satops/operator.rb', line 868

def delete(sat)
  sat.org.delete(@id) unless @id == 1
end

#get_adminObject



872
873
874
875
876
# File 'lib/satops/operator.rb', line 872

def get_admin
@users.each do |user|
  return user if user['is_org_admin']
  end
end

#update(sat) ⇒ Object



878
879
880
# File 'lib/satops/operator.rb', line 878

def update(sat)
  self.create(sat)
end