Developer Interfaces

csv_to_static_groups has 3 objects that can be used to manage static groups or parse csvs into groups within your own scripts.

Additionally, the main function of the script can be used to leverage all of the logic within another script.

Please browse the example scripts.

StaticGroup

class csv_to_static_groups.StaticGroup(conn, name, entity_type, members=[], uuid=None)[source]

Bases: object

Object that helps create/update/remove a static group in Turbonomic

Parameters
  • conn (VMTConnection) – VMTConnection instance to target Turbonomic Server.

  • name (str) – Name of Static Group.

  • members (list, optional) – List of desired member uuids/names

  • entity_type (str) – Type of entities in group (VirtualMachine, PhysicalMachine, etc).

  • uuid (str, optional) – UUID of group if already exists. If not provided, retrieval will be attempted before operations that require it.

add(lookup_names=False, case_sensitive=True, dryrun=False)[source]

Adds the group to the Turbonomic server.

Parameters
  • lookup_names (bool, optional) – If True uuids will be collected from the Turbonomic server that match the entity names in self.members

  • dryrun (bool, optional) – If True, will not commit changes to the Turbonomic server

Returns

vmtconnect response object

add_entities(members, lookup_names=False, case_sensitive=True, dryrun=False)[source]

Adds specified members to the current group membership

Parameters
  • members (list) – List of member uuids/names to add/remove.

  • lookup_names (bool, optional) – If True uuids will be collected from the Turbonomic server that match the entity names in self.members

  • case_sensitive (bool, optional) – If False and lookup_names is True, names will be matched without case sensitivity.

Returns

vmtconnect response object

add_or_update(**kwargs)[source]

Helper function to update group if it already exists or add it if it does not.

Parameters
  • dryrun (bool, optional) – If True, will not commit changes to the Turbonomic server

  • **kwargs – Keyword arguments for self.update()

Returns

vmtconnect response object

exists()[source]

Checks if group already exists in target environment.

Returns

True if group exists or False if group does not exist

get_current_members()[source]

Get list of member entities that currently belong to the group.

Returns

vmtconnect response object

remove(dryrun=False)[source]

Deletes the group from the Turbonomic server.

Parameters

dryrun (bool, optional) – If True, will not commit changes to the Turbonomic server

Returns

vmtconnect response object

remove_entities(members, lookup_names=False, case_sensitive=True, dryrun=False)[source]

Removes specified members from the current group membership

Parameters
  • members (list) – List of member uuids/names to add/remove.

  • lookup_names (bool, optional) – If True uuids will be collected from the Turbonomic server that match the entity names in self.members

  • case_sensitive (bool, optional) – If False and lookup_names is True, names will be matched without case sensitivity.

Returns

vmtconnect response object

update(allow_add=True, allow_remove=True, lookup_names=False, case_sensitive=True, dryrun=False)[source]

Adds/Removes members on the static group on the Turbonomic server.

Parameters
  • allow_add (bool, optional) – If True, current and new members are allowed to be added

  • allow_remove (bool, optional) – If True, current members are allowed to be removed.

  • lookup_names (bool, optional) – If True uuids will be collected from the Turbonomic server that match the entity names in self.members

  • case_sensitive (bool, optional) – If False and lookup_names is True, names will be matched without case sensitivity.

  • dryrun (bool, optional) – If True, no changes are committed to the Turbonomic server

Returns

vmtconnect response object

Exceptions

exception csv_to_static_groups.StaticGroupError[source]

Base StaticGroup Exception.

exception csv_to_static_groups.GroupAlreadyExistsError[source]

Raised when attempting to add a group that already exists.

exception csv_to_static_groups.MissingUUIDError[source]

Base StaticGroup Missing UUID Exception.

exception csv_to_static_groups.NoMatchingGroupError[source]

Raised when attempting to update/remove a group that does not exist.

exception csv_to_static_groups.DuplicateMatchingGroupError[source]

Raised when attempting to update/remove a group where mutliple groups share the same name.

exception csv_to_static_groups.LookupNameError[source]

Base StaticGroup Lookup Name Exception.

exception csv_to_static_groups.NameMatchError[source]

Raised if an entity can’t be found by name.

exception csv_to_static_groups.MultipleMatchingNamesError[source]

Raised if an entity name is found more than once in the target server.

CSVGroupParser

class csv_to_static_groups.CSVGroupParser(entity_type_header, entity_name_header, group_delimiter='_', group_prefix='')[source]

Bases: object

Parses a CSV and returns groupings based on headers

Parameters
  • entity_type_header (str) – Header for the column that contains the entity types.

  • entity_name_header (str) – Header for the column that contains the entity names.

  • group_delimiter (str) – String to separate group column values.

  • group_prefix (str) – String to prepend group name.

parse(csv_file, group_headers=[])[source]

Create unique groups from additional columns in the csv

Parameters
  • csv_file (str) – Path to csv file

  • group_headers (list, optional) – List of headers to group from in order. By default all headers in the csv are used in left to right order.

Returns

List of dictionaries:

{
 "name": ""
 "entity_type": ""
 "members": []
}

Exceptions

exception csv_to_static_groups.CSVGroupParserError[source]

Base CSVGroupParser Exception.

exception csv_to_static_groups.MissingHeaderError[source]

Raised if a specified header is missing.

GroupUpdateUtility

class csv_to_static_groups.GroupUpdateUtility(conn)[source]

Bases: object

Utility Object to simplify common group update tasks

get_entity_index(entity_types, key='displayName', values=[], case_sensitive=True)[source]

Creates an index of entities based on a group key.

Parameters
  • entity_types (list) – List of entity_types,

  • key (str, optional) – Key to index on.

  • values (list, optional) – Value keys to include in values. If empty, all values are included.

  • case_sensitive (bool, optional) – Group entities with/without case sensitivity

Returns

Dictionary:

{
    "entity type": {"entity_key": [{values}, {values}]}
}

get_group_diff(group_uuid, utd_members, key='uuid')[source]

Calculates uuids to add and remove to match current group with “utd”.

Parameters
  • group_uuid (str) – Target group uuid.

  • utd_members (list) – List of desired up to date uuids.

  • key (str, optional) – Key to compare members by.

Returns

Dictionary:

{
    "add": ["uuid", "uuid"],
    "remove": ["uuid", "uuid"]
}

get_group_index(key='displayName', values=['uuid'])[source]

Creates an index of group values based on a group key.

Parameters
  • key (str, optional) – Key to index on,

  • values (list, optional) – Value keys to include in values. If empty, all values are included.

Returns

Dictionary:

{
    "groupName": [{values}, {values}]
}

main

csv_to_static_groups.main(conn, csv_file, entity_type_header='Entity Type', entity_name_header='Entity Name', group_headers=[], no_add=False, no_remove=False, delete=False, case_sensitive=True, group_delimiter='_', dryrun=False)[source]

Parses groups from CSV and adds/updates/deletes groups. Efficiently collects group and entity uuids to minimize api requests.

Parameters
  • conn (VMTConnection) – VMTConnection instance to target Turbonomic Server

  • csv_file (str) – Path to Target CSV

  • entity_type_header (str, optional) – CSV header for column that contains entity types.

  • entity_name_header (str, optional) – CSV header for column that contains entity names.

  • group_headers (list, optional) – List of CSV headers to group members by in order. If empty list, all headers except entity_type_header, and entity_name_header are used from left to right.

  • no_add (bool, optional) – If True, adding current entities to group is disabled.

  • no_remove (bool, optional) – If True, removing current entities from a group is disabled

  • delete (bool, optional) – If True, groups matching names from csv are deleted

  • case_sensitive (bool, optional) – If True, entities will be matched with case-sensitivity

  • dryrun (bool, optional) – If True, changes are not committed to the target Turbonomic server.

Returns

Dictionary with change events and totals for each change category

e.g.

{"Change Category A": {
     "total": int
     "events":[
         {"group name": str,
          "message": str}
        ]
    }}

Global Variables

Logging/Output

LOGGER (logging.logger)
  • Set to your logging.logger to include log entries

  • Default: None

QUIET (bool)
  • Allows ouput to sysout

  • Default: True

TRACE (bool)
  • Outputs trace to LOGGER

  • Default: True

WARN (bool):
  • Allow warnings in sysout

  • Default: True

Summary Names

Change categories available to main’s return dictionary.

  • TRK_DELETE = "Deleted"

  • TRK_ERROR = "Errors"

  • TRK_MISS_ENTITY = "Missing Entities"

  • TRK_ADD = "Added"

  • TRK_UPDATE = "Updated"

  • TRK_SKIP = "Skipped"

GroupParser Fields

Default CSV Headers

  • ENTITY_TYPE_HEADER = "Entity Type"

  • ENTITY_NAME_HEADER = "Entity Name"

  • GROUP_DELIMITER = "_"