diff --git a/.gitignore b/.gitignore index e7ac8c4..fb37c1b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,9 @@ .idea *.pyc -itop-cli.cfg +python-itop-api.cfg MANIFEST dist build Makefile -python_itop_api.egg-info \ No newline at end of file +python_itop_api.egg-info +pylint.bat diff --git a/LICENSE b/LICENSE index a967bbc..6478fb4 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2015, Guillaume Philippon +Copyright (c) 2015-2016, Guillaume Philippon and Julien Nauroy Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/MANIFEST.in b/MANIFEST.in index 26797ed..15abecf 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1 @@ -include itop-cli.cfg.example \ No newline at end of file +include python-itop-api.cfg.example \ No newline at end of file diff --git a/README.md b/README.md index 82355b4..162145b 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,10 @@ # python-itop-api -API python pour iTop via l'interface REST +Python API to interface iTop to various other tools. +Three command-line scripts are currently provided: itop-cli, vcenter2itop and itop2centreon ## itop-cli -itop-cli is a CLI (command line interface) to iTop REST interface. We can use it to list the content -of iTop classes with the command +itop-cli is a generic CLI (command line interface) to the iTop REST interface. +You can use it to list the contents of iTop classes with the command user@machine> itop-cli --classes server rack @@ -11,40 +12,61 @@ You can also search some specific instance with option --find user@machine> itop-cli --classes server --find host.domain.com -You can have a look of more option with command --help +You can have a look at the options with the --help command user@machine> itop-cli --help - usage: itop-cli [-h] [--hostname HOSTNAME] [--username USERNAME] - [--password PASSWORD] [--config CONFIG_FILE] - [--classes [ITOP-CLASS [ITOP-CLASS ...]]] - [--find INSTANCE [INSTANCE ...]] [--delete INSTANCE INSTANCE] - [--organization ORGANIZATION] [--import URI] [--format FORMAT] - - python CLI for iTop REST api - - optional arguments: - -h, --help show this help message and exit - - itop: - --hostname HOSTNAME hostname of iTop server - --username USERNAME username for iTop authentication - --password PASSWORD password for iTop authentication - - cli: - --config CONFIG_FILE configuration file CLI must use (default = ./itop- - cli.cfg) - --classes [ITOP-CLASS [ITOP-CLASS ...]] - iTop classes to use - --find INSTANCE [INSTANCE ...] - Find and display information about a given class - instance givenits name or ID - --delete INSTANCE INSTANCE - Delete an instance given its class name and instance - ID - --organization ORGANIZATION - iTop organization to use - - import: - --import URI URI of file to import - --format FORMAT Format of file you want import + usage: itop-cli [-h] [--hostname HOSTNAME] [--username USERNAME] + [--password PASSWORD] [--organization ORGANIZATION-NAME] + [--virtualhost VIRTUAL-HOSTNAME] [--config CONFIG_FILE] + [--classes [ITOP-CLASS [ITOP-CLASS ...]]] + [--find INSTANCE [INSTANCE ...]] [--delete] [--import-uri URI] + [--import-stdin] [--format FORMAT] [--save] + [--prevent-duplicates] + + python CLI for iTop REST api + + optional arguments: + -h, --help show this help message and exit + + itop: + --hostname HOSTNAME hostname of iTop server + --username USERNAME username for iTop authentication + --password PASSWORD password for iTop authentication + --organization ORGANIZATION-NAME + iTop organization to use + --virtualhost VIRTUAL-HOSTNAME + Itop's virtual host name for VMs + + cli: + --config CONFIG_FILE configuration file CLI must use (default = ./itop- + cli.cfg) + --classes [ITOP-CLASS [ITOP-CLASS ...]] + iTop classes to use + --find INSTANCE [INSTANCE ...] + Find and display information about a given class + instance givenits name or ID + --delete Delete all instances previously loaded + --save Save the instances loaded through import + --prevent-duplicates Check if objects with the same name already exist + before savingand don't save in this case + + import: + --import-uri URI URI of file to import + --import-stdin import data from STDIN + --format FORMAT Format of file you want import + + +## vcenter2itop +vcenter2itop focuses on extracting data from a VMWare VCenter cluster and importing it into iTop. +It synchronises Farms, Servers, Hypervisors and VirtualMachines present in a VCenter as well as Brands, Models, OS Families and Versions. +It has a dependency on the pyVmomi module. + +All parameters are set into the common python-itop-api.cfg script. vcenter2itop is then simply runs this way: + + user@machine> vcenter2itop + +# itop2centreon +itop2centreon is an attempt at synchronizing iTop with the Centreon monitoring system through its CLAPI (command-line API) interface. +For now, it synchronizes the list of machines (Servers and VMs) and contacts. +It can serve as a kickstart script for your own synchronization mechanism. diff --git a/itop-cli.cfg.example b/itop-cli.cfg.example deleted file mode 100644 index 717cadf..0000000 --- a/itop-cli.cfg.example +++ /dev/null @@ -1,21 +0,0 @@ -# This is an example configuration file. copy or rename it to 'itop-cli.cfg' and edit the values. -# At least hostname, username and password will have to be changed. -# Make sure to leave 'form' as an allowed login type within Itop's configuration. -[main] -hostname: itop.example.com -username: demouser -password: demopass -protocol: https -base_uri: / -api_version: 1.0 -api_suffix: /webservices/rest.php -# If you set this value to true, the api will only pretend deleting objects. -# Useful only for debugging purposes -simulate_deletes: False -# If you set this value to true, the api will check if an object with the same name already exists before saving. -# Checks can take some time because the itop rest api is slow -prevent_duplicates: False -# Default organization when adding servers or VMs -organization: -# Default virtualhost when adding VMs -virtualhost: \ No newline at end of file diff --git a/itop2centreon.py b/itop2centreon.py new file mode 100755 index 0000000..343c5b0 --- /dev/null +++ b/itop2centreon.py @@ -0,0 +1,205 @@ +#!/usr/bin/env python +# -*- coding: utf8 -*-fr +# pylint: disable=invalid-name +""" +itop2centreon is a basic CLI interface to export itop data into centreon +""" + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + +from itopapi import ItopapiController, ItopapiConfig, UnsupportedImportFormat +from itopcli import load_configuration_cli, ItopcliConfig, NeedMoreArgs +from itopapi.model import * +import subprocess + + +def csv_to_dict(csv): + lines = csv.splitlines() + headers = lines.pop(0).split(';') + dict = [] + for line in lines: + dict_line = {} + for i, val in enumerate(line.split(';')): + dict_line[headers[i]] = val.decode('utf-8') + dict.append(dict_line) + return dict + + +def run_clapi_list_command(object): + out, err = subprocess.Popen([ItopapiConfig.centreon_clapi_path, + '-u', ItopapiConfig.centreon_username, + '-p', ItopapiConfig.centreon_password, + '-o', object, + '-a', 'show'], + stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate() + return csv_to_dict(out) + + +def run_clapi_action_command(obj, action, values): + out, err = subprocess.Popen([ItopapiConfig.centreon_clapi_path, + '-u', ItopapiConfig.centreon_username, + '-p', ItopapiConfig.centreon_password, + '-o', obj, + '-a', action, + '-v', ';'.join(str(x.encode('utf-8')) for x in values)], + stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate() + if out == "": + return True + else: + print "Error running action command:" + print out + exit(0) + + +def main(): + """ + Main function + """ + + ###################################### + # Load Itop & Centreon configuration # + ###################################### + try: + load_configuration_cli() + except NeedMoreArgs as e: + print "Error: {}".format(e.message) + exit(1) + + + #################### + # Some value check # + #################### + if ItopapiConfig.username is None\ + or ItopapiConfig.password is None: + print "Error: Itop Username/Password missing" + exit(1) + if ItopapiConfig.centreon_username is None\ + or ItopapiConfig.centreon_password is None\ + or ItopapiConfig.centreon_clapi_path is None: + print "Error: Centreon Username/Password/Path missing" + exit(1) + + controller = ItopapiController() + + + ##################### + # Synchronize Teams # + ##################### + print "Synchronizing Itop teams / Centreon contact groups..." + centreon_contact_groups = run_clapi_list_command("CG") + itop_teams = ItopapiTeam.find_all() + for team in itop_teams: + group_exists = False + for contact_group in centreon_contact_groups: + if team.name == contact_group['name']: group_exists = True + if not group_exists: + print u"adding team {0} as a contact group".format(team.friendlyname.format('utf-8')) + run_clapi_action_command('CG', 'add', [team.name, team.name + ' (from Itop)']) + + ################################### + # Cleanup Centreon Contact Groups # + ################################### + print "Cleaning up Centreon contact groups..." + all_contact_group_names = map(lambda s: s.name, itop_teams) + for contact_group in centreon_contact_groups: + if contact_group['name'] not in all_contact_group_names and contact_group['name'] != 'Supervisors': + print u"deleting contact group {0} as is is not defined in itop".format(contact_group['name'].format('utf-8')) + run_clapi_action_command('CG', 'DEL', [contact_group['name']]) + + ####################### + # Synchronize Persons # + ####################### + print "Synchronizing Itop persons / Centreon contacts..." + centreon_contacts = run_clapi_list_command("contact") + # Can't get persons from teams since their email is not listed in team.persons_list + itop_persons = ItopapiPerson.find_all() + for person in itop_persons: + # All persons should have an email + if person.email is None or '@' not in person.email: + continue + + contact_alias = person.email.split('@')[0] + contact_exists = False + for contact in centreon_contacts: + if person.email == contact['email']: contact_exists = True + if not contact_exists: + print u"adding person {0} as a contact".format(person.friendlyname.format('utf-8')) + run_clapi_action_command('contact', 'add', [person.friendlyname, contact_alias, person.email, '', '0', '1', 'en_US', 'ldap']) + # In all cases, add the contact to the contacts list and set various parameters + for team in person.team_list: + run_clapi_action_command('CG', 'addcontact', [team.team_name, contact_alias]) + run_clapi_action_command('contact', 'setParam', [contact_alias, 'enable_notifications', '1']) + run_clapi_action_command('contact', 'setParam', [contact_alias, 'hostnotifcmd', 'host-notify-by-email']) + run_clapi_action_command('contact', 'setParam', [contact_alias, 'hostnotifopt', 'd,u,r']) + run_clapi_action_command('contact', 'setParam', [contact_alias, 'svcnotifcmd', 'service-notify-by-email']) + run_clapi_action_command('contact', 'setParam', [contact_alias, 'servicenotifopt', 'w,u,c,r,f']) + + ############################# + # Cleanup Centreon Contacts # + ############################# + print "Cleaning up Centreon contacts..." + all_contact_aliases = map(lambda s: '' if s.email is None else s.email.split('@')[0], itop_persons) + for contact in centreon_contacts: + if contact['alias'] not in all_contact_aliases and contact['alias'] != 'admin': + print u"deleting contact {0} as is is not defined in itop".format(contact['alias'].format('utf-8')) + run_clapi_action_command('contact', 'DEL', [contact['alias']]) + + def sync_servers(servers, centreon_hosts): + for server in servers: + if server.managementip is None or server.managementip == '': + continue + server_exists = False + for host in centreon_hosts: + if server.name == host['name']: server_exists = True + if server.status != 'production': + if server_exists: + # Remove servers no longer in production + print u"removing {0} as a host as its status is {1}".format(server.name.format('utf-8'), server.status) + run_clapi_action_command('HOST', 'DEL', [server.name]) + continue + + if not server_exists: + print u"adding {0} as a host".format(server.name.format('utf-8')) + run_clapi_action_command('HOST', 'ADD', [server.name, server.description, server.managementip, + 'generic-host', 'central', '']) + + # Set the server parameters + run_clapi_action_command('HOST', 'setParam', [server.name, 'check_period', '24x7']) + # Set the contacts + for contact in server.contacts_list: + if type(contact) is ItopapiTeam: + run_clapi_action_command('HOST', 'addContactGroup', [server.name, contact.contact_name]) + else: + run_clapi_action_command('HOST', 'addContact', [server.name, contact.contact_id_friendlyname]) + + ####################### + # Synchronize Servers # + ####################### + print "Synchronizing Itop servers / Centreon hosts..." + centreon_hosts = run_clapi_list_command("HOST") + itop_servers = ItopapiServer.find_all() + sync_servers(itop_servers, centreon_hosts) + + ############################### + # Synchronize VirtualMachines # + ############################### + print "Synchronizing Itop VMs / Centreon hosts..." + itop_vms = ItopapiVirtualMachine.find_all() + sync_servers(itop_vms, centreon_hosts) + + ########################## + # Cleanup Centreon Hosts # + ########################## + print "Cleaning up Centreon hosts..." + all_servers_names = map(lambda s: s.name, itop_servers + itop_vms) + for host in centreon_hosts: + if host['name'] not in all_servers_names: + print u"deleting host {0} as is is not defined in itop".format(host['name'].format('utf-8')) + run_clapi_action_command('HOST', 'DEL', [host['name']]) + + return 0 + + +if __name__ == "__main__": + main() diff --git a/itopapi/controller/ItopapiController.py b/itopapi/controller/ItopapiController.py index 1d84612..ab414b6 100644 --- a/itopapi/controller/ItopapiController.py +++ b/itopapi/controller/ItopapiController.py @@ -114,9 +114,9 @@ def load_one(self, itop_class, id_instance): if id_instance.isdigit(): instance = model.find(id_instance) else: - instance = model.find(model.find_by_name(id_instance)) + instance = model.find_by_name(id_instance) if instance is not None: - self.data.extend(instance) + self.data.append(instance) def delete(self): """ diff --git a/itopapi/itopapiconfig.py b/itopapi/itopapiconfig.py index d1ca712..315bf2f 100644 --- a/itopapi/itopapiconfig.py +++ b/itopapi/itopapiconfig.py @@ -8,6 +8,7 @@ __authors__ = ['Julien Nauroy '] import ConfigParser +import json class ItopapiConfig(object): @@ -31,6 +32,22 @@ class ItopapiConfig(object): simulate_deletes = False # Prevent duplicate names when adding new items prevent_duplicates = False + """ + Centreon variables + """ + centreon_username = None + centreon_password = None + centreon_clapi_path = None + """ + VCenter variables + """ + vcenter_host = None + vcenter_port = None + vcenter_username = None + vcenter_password = None + vcenter_cluster_sync_mode = [] + vcenter_host_sync_mode = [] + vcenter_vm_sync_mode = [] @staticmethod def read_config(config_file): @@ -90,3 +107,53 @@ def read_config(config_file): ItopapiConfig.prevent_duplicates = True except ConfigParser.NoOptionError: pass + + try: + ItopapiConfig.centreon_username = config_parser.get('centreon', 'username') + except ConfigParser.NoOptionError: + pass + try: + ItopapiConfig.centreon_password = config_parser.get('centreon', 'password') + except ConfigParser.NoOptionError: + pass + try: + ItopapiConfig.centreon_clapi_path = config_parser.get('centreon', 'clapi_path') + except ConfigParser.NoOptionError: + pass + + try: + ItopapiConfig.vcenter_host = config_parser.get('vcenter', 'host') + except ConfigParser.NoOptionError: + pass + try: + ItopapiConfig.vcenter_port = config_parser.get('vcenter', 'port') + except ConfigParser.NoOptionError: + pass + try: + ItopapiConfig.vcenter_username = config_parser.get('vcenter', 'username') + except ConfigParser.NoOptionError: + pass + try: + ItopapiConfig.vcenter_password = config_parser.get('vcenter', 'password') + except ConfigParser.NoOptionError: + pass + try: + unsecure = config_parser.get('vcenter', 'unsecure') + ItopapiConfig.vcenter_unsecure = (unsecure.lower() == "true" or unsecure == "1") + except ConfigParser.NoOptionError: + pass + try: + host_cluster_mode = json.loads(config_parser.get('vcenter', 'cluster_sync_mode')) + ItopapiConfig.vcenter_cluster_sync_mode = host_cluster_mode + except ConfigParser.NoOptionError: + pass + try: + host_sync_mode = json.loads(config_parser.get('vcenter', 'host_sync_mode')) + ItopapiConfig.vcenter_host_sync_mode = host_sync_mode + except ConfigParser.NoOptionError: + pass + try: + vm_sync_mode = json.loads(config_parser.get('vcenter', 'vm_sync_mode')) + ItopapiConfig.vcenter_vm_sync_mode = vm_sync_mode + except ConfigParser.NoOptionError: + pass diff --git a/itopapi/model/__init__.py b/itopapi/model/__init__.py index 5d7df78..28daf0e 100644 --- a/itopapi/model/__init__.py +++ b/itopapi/model/__init__.py @@ -5,17 +5,90 @@ """ __version__ = '1.0' -__authors__ = ['Guillaume Philippon '] +__authors__ = ['Guillaume Philippon ', 'Julien Nauroy '] from itopapi.model.prototype import ItopapiPrototype, ItopapiUnimplementedMethod +from itopapi.model.organization import ItopapiOrganization +from itopapi.model.location import ItopapiLocation +from itopapi.model.contact import ItopapiContact +from itopapi.model.person import ItopapiPerson +from itopapi.model.team import ItopapiTeam +from itopapi.model.functionalCI import ItopapiFunctionalCI +from itopapi.model.physicalDevice import ItopapiPhysicalDevice from itopapi.model.rack import ItopapiRack +from itopapi.model.enclosure import ItopapiEnclosure +from itopapi.model.connectableCI import ItopapiConnectableCI +from itopapi.model.datacenterDevice import ItopapiDatacenterDevice from itopapi.model.server import ItopapiServer -from itopapi.model.os import ItopapiOSFamily -from itopapi.model.vlan import ItopapiVLAN -from itopapi.model.subnet import ItopapiSubnet -from itopapi.model.physicalInterface import ItopapiPhysicalInterface -from itopapi.model.virtualMachine import ItopapiVirtualMachine +from itopapi.model.sanSwitch import ItopapiSANSwitch +from itopapi.model.tapeLibrary import ItopapiTapeLibrary +from itopapi.model.storageSystem import ItopapiStorageSystem +from itopapi.model.applicationSolution import ItopapiApplicationSolution +from itopapi.model.businessProcess import ItopapiBusinessProcess +from itopapi.model.softwareInstance import ItopapiSoftwareInstance +from itopapi.model.dbserver import ItopapiDBServer +from itopapi.model.webServer import ItopapiWebServer +from itopapi.model.pcSoftware import ItopapiPCSoftware +from itopapi.model.middleware import ItopapiMiddleware +from itopapi.model.otherSoftware import ItopapiOtherSoftware +from itopapi.model.middlewareInstance import ItopapiMiddlewareInstance +from itopapi.model.databaseSchema import ItopapiDatabaseSchema from itopapi.model.webServer import ItopapiWebServer from itopapi.model.webApplication import ItopapiWebApplication +from itopapi.model.virtualDevice import ItopapiVirtualDevice +from itopapi.model.virtualMachine import ItopapiVirtualMachine +from itopapi.model.virtualHost import ItopapiVirtualHost +from itopapi.model.hypervisor import ItopapiHypervisor +from itopapi.model.farm import ItopapiFarm +from itopapi.model.licence import ItopapiLicence +from itopapi.model.osLicence import ItopapiOSLicence +from itopapi.model.softwareLicence import ItopapiSoftwareLicence +from itopapi.model.typology import ItopapiTypology +from itopapi.model.osFamily import ItopapiOSFamily +from itopapi.model.osVersion import ItopapiOSVersion +from itopapi.model.contactType import ItopapiContactType +from itopapi.model.contractType import ItopapiContractType +from itopapi.model.documentType import ItopapiDocumentType +from itopapi.model.brand import ItopapiBrand +from itopapi.model.iosVersion import ItopapiIOSVersion +from itopapi.model.model import ItopapiModel +from itopapi.model.networkDeviceType import ItopapiNetworkDeviceType +from itopapi.model.nas import ItopapiNAS +from itopapi.model.networkInterface import ItopapiNetworkInterface +from itopapi.model.ipInterface import ItopapiIPInterface +from itopapi.model.physicalInterface import ItopapiPhysicalInterface +from itopapi.model.logicalInterface import ItopapiLogicalInterface +from itopapi.model.fiberChannelInterface import ItopapiFiberChannelInterface +from itopapi.model.powerConnection import ItopapiPowerConnection +from itopapi.model.powerSource import ItopapiPowerSource +from itopapi.model.pdu import ItopapiPDU from itopapi.model.service import ItopapiService -from itopapi.model.applicationSolution import ItopapiApplicationSolution +from itopapi.model.serviceFamily import ItopapiServiceFamily +from itopapi.model.vlan import ItopapiVLAN +from itopapi.model.subnet import ItopapiSubnet +from itopapi.model.tape import ItopapiTape +from itopapi.model.patch import ItopapiPatch +from itopapi.model.osPatch import ItopapiOSPatch +from itopapi.model.softwarePatch import ItopapiSoftwarePatch +from itopapi.model.incident import ItopapiIncident + +# TODO partial list of missing classes, with no particular order and along with their inheritance hierarchy : +# Document +# DocumentFile +# DocumentNote +# DocumentWeb +# Group +# Contract +# CustomerContract +# ProviderContract +# ServiceSubcategory +# SLA +# SLT +# DeliveryModel +# Contract +# CustomerContract +# ProviderContract +# NASFileSystem +# LogicalVolume + +# Peripheral, MobilePhone, Printer, PC, Phone, IPPhone, Tablet, TapeLibrary, SANSwitchNAS diff --git a/itopapi/model/applicationSolution.py b/itopapi/model/applicationSolution.py index a4ede64..07c975a 100644 --- a/itopapi/model/applicationSolution.py +++ b/itopapi/model/applicationSolution.py @@ -1,26 +1,33 @@ # -*- coding: utf8 -*-fr # pylint: disable=invalid-name """ -ItopapiApplicationSolution is a abstraction of Application Solution representation on iTop +ItopapiApplicationSolution is an abstraction of Application Solution representation on iTop """ from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.functionalCI import ItopapiFunctionalCI +from itopapi.model.features.hasOrganization import HasOrganization + __version__ = '1.0' __authors__ = ['Julien Nauroy '] -""" TODO not completed and tested yet, created as a dependency of TiopapiRack """ -class ItopapiApplicationSolution(ItopapiPrototype): + +class ItopapiApplicationSolution(ItopapiFunctionalCI, HasOrganization): # Configuration specific to itop itop = { # Name of the class in Itop 'name': 'ApplicationSolution', # Define which fields to save when creating or updating from the python API - 'save': ['name', 'status', 'business_criticity', 'move2production', 'description'], + 'save': ['name', 'status', 'business_criticity', 'move2production', 'description', 'redundancy'], 'foreign_keys': [ - {'id': 'org_id', 'name': 'organization_name', 'table': 'Organization'}, - ] + HasOrganization.foreign_key, + ], + 'list_types': { + 'functionalcis_list': 'functionalci_id_finalclass_recall', + 'contacts_list': 'contact_id_finalclass_recall' + }, } @staticmethod @@ -34,32 +41,26 @@ def find_by_name(name): @staticmethod def find_all(): - """ Retrieve all instance of OSFamily """ + """ Retrieve all instance of ApplicationSolution """ return ItopapiPrototype.find_all(ItopapiApplicationSolution) """ - ItopapiApplicationSolution is a object that represent an Application Solution from iTop + ItopapiApplicationSolution is an object that represents an Application Solution from iTop """ def __init__(self, data=None): super(ItopapiApplicationSolution, self).__init__(data) ################################## # Properties # ################################## - self.org_id = None - # Application Solution's organization id. Call findOrganization to get the full information or just use - # org_id_friendlyname and organization_name - self.org_id_friendlyname = None - # Application Solution's organization friendly name. Not sure the difference with organization_name - self.organization_name = None - # Application Solution's organization name - self.status = None # Application Solution's status. Values within [inactive, active] - self.business_criticity = None + self.status = None # Application Solution's business criticity. Values within [high, medium, low] - self.move2production = None + self.business_criticity = None # Application Solution's move to production date - self.description = None + self.move2production = None # Application Solution's description, as a free text + self.description = None + self.redundancy = None ################################## # Lists # ################################## @@ -71,4 +72,8 @@ def __init__(self, data=None): self.businessprocess_list = None self.services_list = None self.contacts_list = None - self.providercontracts_list = None \ No newline at end of file + self.providercontracts_list = None + + +# Register as a subclass of FunctionalCI +ItopapiFunctionalCI.register(ItopapiApplicationSolution) diff --git a/itopapi/model/brand.py b/itopapi/model/brand.py new file mode 100644 index 0000000..96422a2 --- /dev/null +++ b/itopapi/model/brand.py @@ -0,0 +1,50 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiBrand is an abstraction of Brand representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.typology import ItopapiTypology + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiBrand(ItopapiTypology): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'Brand', + # Define which fields to save when creating or updating from the python API + 'save': ['name'], + 'foreign_keys': [] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of Brand with the given key or criteria """ + return ItopapiPrototype.find(ItopapiBrand, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiBrand, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of Brand """ + return ItopapiPrototype.find_all(ItopapiBrand) + + """ + ItopapiBrand is an object that represents a Brand from iTop + """ + def __init__(self, data=None): + super(ItopapiBrand, self).__init__(data) + + # Physical devices using this brand + self.physicaldevices_list = None + + +# Register as a subclass of Typology +ItopapiTypology.register(ItopapiBrand) diff --git a/itopapi/model/businessProcess.py b/itopapi/model/businessProcess.py new file mode 100644 index 0000000..d0def04 --- /dev/null +++ b/itopapi/model/businessProcess.py @@ -0,0 +1,77 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=invalid-name +""" +ItopapiBusinessProcess is an abstraction of Business Process representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.functionalCI import ItopapiFunctionalCI +from itopapi.model.features.hasOrganization import HasOrganization + + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiBusinessProcess(ItopapiFunctionalCI, HasOrganization): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'BusinessProcess', + # Define which fields to save when creating or updating from the python API + 'save': ['name', 'status', 'business_criticity', 'move2production', 'description'], + 'foreign_keys': [ + HasOrganization.foreign_key, + ], + 'list_types': { + 'contacts_list': 'contact_id_finalclass_recall' + }, + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of BusinessProcess with the given key or criteria """ + return ItopapiPrototype.find(ItopapiBusinessProcess, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiBusinessProcess, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of BusinessProcess """ + return ItopapiPrototype.find_all(ItopapiBusinessProcess) + + """ + ItopapiBusinessProcess is an object that represents an Business Process from iTop + """ + def __init__(self, data=None): + super(ItopapiBusinessProcess, self).__init__(data) + ################################## + # Properties # + ################################## + # Business Process's status. Values within [inactive, active] + self.status = None + # Business Process's business criticity. Values within [high, medium, low] + self.business_criticity = None + # Business Process's move to production date + self.move2production = None + # Business Process's description, as a free text + self.description = None + ################################## + # Lists # + ################################## + # One with an s, one without. Because why not? + self.applicationsolution_list = None + self.applicationsolutions_list = None + self.documents_list = None + self.softwares_list = None + self.tickets_list = None + self.services_list = None + self.contacts_list = None + self.providercontracts_list = None + + +# Register as a subclass of FunctionalCI +ItopapiFunctionalCI.register(ItopapiBusinessProcess) diff --git a/itopapi/model/connectableCI.py b/itopapi/model/connectableCI.py new file mode 100644 index 0000000..f4770e5 --- /dev/null +++ b/itopapi/model/connectableCI.py @@ -0,0 +1,47 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiConnectableCI is an abstraction of Connectable CI representation on iTop +""" + +from abc import ABCMeta +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.physicalDevice import ItopapiPhysicalDevice + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiConnectableCI(ItopapiPhysicalDevice): + __metaclass__ = ABCMeta + + # Configuration specific to itop + itop = { + 'name': 'ConnectableCI', + 'save': [], + 'foreign_keys': [] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of Connectable CI with the given key or criteria """ + return ItopapiPrototype.find(ItopapiConnectableCI, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiConnectableCI, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of Connectable CI """ + return ItopapiPrototype.find_all(ItopapiConnectableCI) + + """ + ItopapiConnectableCI is an object that represents a Connectable CI from iTop + """ + def __init__(self, data=None): + super(ItopapiConnectableCI, self).__init__(data) + + +# Register as a subclass of PhysicalDevice +ItopapiPhysicalDevice.register(ItopapiConnectableCI) \ No newline at end of file diff --git a/itopapi/model/contact.py b/itopapi/model/contact.py new file mode 100644 index 0000000..54acff7 --- /dev/null +++ b/itopapi/model/contact.py @@ -0,0 +1,43 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiContact is an abstraction of Contact representation on iTop +It serves as a base class for Person and Team +""" + +from abc import ABCMeta +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiContact(ItopapiPrototype): + __metaclass__ = ABCMeta + + # Configuration specific to itop + itop = { + 'name': 'Contact', + 'save': [], + 'foreign_keys': [] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of Contact with the given key or criteria """ + return ItopapiPrototype.find(ItopapiContact, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiContact, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of Contact """ + return ItopapiPrototype.find_all(ItopapiContact) + + """ + ItopapiContact is an object that represents a Contact from iTop + """ + def __init__(self, data=None): + super(ItopapiContact, self).__init__(data) diff --git a/itopapi/model/contactType.py b/itopapi/model/contactType.py new file mode 100644 index 0000000..9df7054 --- /dev/null +++ b/itopapi/model/contactType.py @@ -0,0 +1,47 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiContactType is an abstraction of ContactType representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.typology import ItopapiTypology + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiContactType(ItopapiTypology): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'ContactType', + # Define which fields to save when creating or updating from the python API + 'save': ['name'], + 'foreign_keys': [] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of ContactType with the given key or criteria """ + return ItopapiPrototype.find(ItopapiContactType, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiContactType, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of ContactType """ + return ItopapiPrototype.find_all(ItopapiContactType) + + """ + ItopapiContactType is an object that represents an ContactType from iTop + """ + def __init__(self, data=None): + super(ItopapiContactType, self).__init__(data) + + +# Register as a subclass of Typology +ItopapiTypology.register(ItopapiContactType) diff --git a/itopapi/model/contractType.py b/itopapi/model/contractType.py new file mode 100644 index 0000000..8f4069f --- /dev/null +++ b/itopapi/model/contractType.py @@ -0,0 +1,47 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiContractType is an abstraction of ContractType representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.typology import ItopapiTypology + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiContractType(ItopapiTypology): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'ContractType', + # Define which fields to save when creating or updating from the python API + 'save': ['name'], + 'foreign_keys': [] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of ContractType with the given key or criteria """ + return ItopapiPrototype.find(ItopapiContractType, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiContractType, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of ContractType """ + return ItopapiPrototype.find_all(ItopapiContractType) + + """ + ItopapiContractType is an object that represents an ContractType from iTop + """ + def __init__(self, data=None): + super(ItopapiContractType, self).__init__(data) + + +# Register as a subclass of Typology +ItopapiTypology.register(ItopapiContractType) diff --git a/itopapi/model/databaseSchema.py b/itopapi/model/databaseSchema.py new file mode 100644 index 0000000..ac228c2 --- /dev/null +++ b/itopapi/model/databaseSchema.py @@ -0,0 +1,76 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=invalid-name +""" +ItopapiDatabaseSchema is an abstraction of Database Schema representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.functionalCI import ItopapiFunctionalCI +from itopapi.model.features.hasOrganization import HasOrganization +from itopapi.model.features.hasDBServer import HasDBServer + + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiDatabaseSchema(ItopapiFunctionalCI, HasOrganization, HasDBServer): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'DatabaseSchema', + # Define which fields to save when creating or updating from the python API + 'save': ['name', 'business_criticity', 'move2production', 'description'], + 'foreign_keys': [ + HasOrganization.foreign_key, + HasDBServer.foreign_key, + ], + 'list_types': { + 'contacts_list': 'contact_id_finalclass_recall' + }, + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of DatabaseSchema with the given key or criteria """ + return ItopapiPrototype.find(ItopapiDatabaseSchema, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiDatabaseSchema, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of DatabaseSchema """ + return ItopapiPrototype.find_all(ItopapiDatabaseSchema) + + """ + ItopapiDatabaseSchema is an object that represents an Database Schema from iTop + """ + def __init__(self, data=None): + super(ItopapiDatabaseSchema, self).__init__(data) + ################################## + # Properties # + ################################## + # Database Schema's business criticity. Values within [high, medium, low] + self.business_criticity = None + # Database Schema's move to production date + self.move2production = None + # Database Schema's description, as a free text + self.description = None + ################################## + # Lists # + ################################## + # One with an s, one without. Because why not? + self.applicationsolution_list = None + self.documents_list = None + self.softwares_list = None + self.tickets_list = None + self.services_list = None + self.contacts_list = None + self.providercontracts_list = None + + +# Register as a subclass of FunctionalCI +ItopapiFunctionalCI.register(ItopapiDatabaseSchema) diff --git a/itopapi/model/datacenterDevice.py b/itopapi/model/datacenterDevice.py new file mode 100644 index 0000000..77d7686 --- /dev/null +++ b/itopapi/model/datacenterDevice.py @@ -0,0 +1,47 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiDatacenterDevice is an abstraction of Datacenter Device representation on iTop +""" + +from abc import ABCMeta +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.connectableCI import ItopapiConnectableCI + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiDatacenterDevice(ItopapiConnectableCI): + __metaclass__ = ABCMeta + + # Configuration specific to itop + itop = { + 'name': 'DatacenterDevice', + 'save': [], + 'foreign_keys': [] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of Datacenter Device with the given key or criteria """ + return ItopapiPrototype.find(ItopapiDatacenterDevice, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiDatacenterDevice, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of Datacenter Device """ + return ItopapiPrototype.find_all(ItopapiDatacenterDevice) + + """ + ItopapiDatacenterDevice is an object that represents a Datacenter Device from iTop + """ + def __init__(self, data=None): + super(ItopapiDatacenterDevice, self).__init__(data) + + +# Register as a subclass of ConnectableCI +ItopapiConnectableCI.register(ItopapiDatacenterDevice) \ No newline at end of file diff --git a/itopapi/model/dbserver.py b/itopapi/model/dbserver.py new file mode 100644 index 0000000..9b2709f --- /dev/null +++ b/itopapi/model/dbserver.py @@ -0,0 +1,60 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +ItopapiDBServer is an abstraction of DBServer representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.softwareInstance import ItopapiSoftwareInstance +from itopapi.model.features.hasOrganization import HasOrganization +from itopapi.model.features.hasSoftware import HasSoftware +from itopapi.model.features.hasSoftwareLicence import HasSoftwareLicence +from itopapi.model.features.hasSystem import HasSystem + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiDBServer(ItopapiSoftwareInstance, HasOrganization, HasSoftware, HasSoftwareLicence, HasSystem): + """ + ItopapiDBServer is an object that represents a DBServer from iTop + It has the same attributes as ItopapiOtherSoftware + """ + + """ Configuration specific to itop """ + itop = { + # Name of the class in Itop + 'name': 'DBServer', + # Define which fields to save when creating or updating from the python API + 'save': ['move2production', 'description', 'status', 'name', 'business_criticity', 'path'], + 'foreign_keys': [ + HasOrganization.foreign_key, + HasSoftware.foreign_key, + HasSoftwareLicence.foreign_key, + HasSystem.foreign_key, + ], + 'list_types': { + 'contacts_list': 'contact_id_finalclass_recall' + }, + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of DBServer with the given key or criteria """ + return ItopapiPrototype.find(ItopapiDBServer, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiDBServer, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of Rack """ + return ItopapiPrototype.find_all(ItopapiDBServer) + + def __init__(self, data=None): + super(ItopapiDBServer, self).__init__(data) + + +# Register as a subclass of SoftwareInstance +ItopapiSoftwareInstance.register(ItopapiDBServer) diff --git a/itopapi/model/deliveryModel.py b/itopapi/model/deliveryModel.py new file mode 100644 index 0000000..38356c4 --- /dev/null +++ b/itopapi/model/deliveryModel.py @@ -0,0 +1,55 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=invalid-name +""" +ItopapiDeliveryModel is an abstraction of Organization representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.features.hasOrganization import HasOrganization + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + +class ItopapiDeliveryModel(ItopapiPrototype, HasOrganization): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'DeliveryModel', + # Define which fields to save when creating or updating from the python API + 'save': ['name', 'description'], + 'foreign_keys': [ + HasOrganization.foreign_key, + ], + 'list_types': { + 'contacts_list': 'contact_id_finalclass_recall' + }, + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of ApplicationSolution with the given key or criteria """ + return ItopapiPrototype.find(ItopapiDeliveryModel, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiDeliveryModel, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of OSFamily """ + return ItopapiPrototype.find_all(ItopapiDeliveryModel) + + """ + ItopapiDeliveryModel is an object that represents an Application Solution from iTop + """ + def __init__(self, data=None): + super(ItopapiDeliveryModel, self).__init__(data) + + self.description = None + + ################################## + # Lists # + ################################## + self.customers_list = [] + self.contacts_list = [] diff --git a/itopapi/model/documentType.py b/itopapi/model/documentType.py new file mode 100644 index 0000000..7e555b4 --- /dev/null +++ b/itopapi/model/documentType.py @@ -0,0 +1,47 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiDocumentType is an abstraction of DocumentType representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.typology import ItopapiTypology + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiDocumentType(ItopapiTypology): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'DocumentType', + # Define which fields to save when creating or updating from the python API + 'save': ['name'], + 'foreign_keys': [] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of DocumentType with the given key or criteria """ + return ItopapiPrototype.find(ItopapiDocumentType, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiDocumentType, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of DocumentType """ + return ItopapiPrototype.find_all(ItopapiDocumentType) + + """ + ItopapiDocumentType is an object that represents an DocumentType from iTop + """ + def __init__(self, data=None): + super(ItopapiDocumentType, self).__init__(data) + + +# Register as a subclass of Typology +ItopapiTypology.register(ItopapiDocumentType) diff --git a/itopapi/model/enclosure.py b/itopapi/model/enclosure.py new file mode 100644 index 0000000..8d34baf --- /dev/null +++ b/itopapi/model/enclosure.py @@ -0,0 +1,71 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiEnclosure is an abstraction of Enclosure representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.features.hasOrganization import HasOrganization +from itopapi.model.features.hasLocation import HasLocation +from itopapi.model.features.hasBrand import HasBrand +from itopapi.model.features.hasModel import HasModel +from itopapi.model.features.hasRack import HasRack + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiEnclosure(ItopapiPrototype, HasOrganization, HasLocation, HasBrand, HasModel, HasRack): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'Enclosure', + # Define which fields to save when creating or updating from the python API + 'save': ['name', 'status', 'business_criticity', 'nb_u', 'serialnumber', 'asset_number', + 'move2production', 'purchase_date', 'end_of_warranty', 'description'], + 'foreign_keys': [ + HasOrganization.foreign_key, + HasLocation.foreign_key, + HasBrand.foreign_key, + HasModel.foreign_key, + HasRack.foreign_key, + ], + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of Enclosure with the given key or criteria """ + return ItopapiPrototype.find(ItopapiEnclosure, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiEnclosure, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of Enclosure """ + return ItopapiPrototype.find_all(ItopapiEnclosure) + + """ + ItopapiEnclosure is an object that represents an Enclosure from iTop + """ + def __init__(self, data=None): + super(ItopapiEnclosure, self).__init__(data) + # Enclosure's status. Values within [implementation, obsolete, production, stock] + self.status = None + # Enclosure's business criticity. Values within [high, medium, low] + self.business_criticity = None + # Rack units + self.nb_u = None + # Serial number + self.serialnumber = None + # Asset number + self.asset_number = None + # Server's move to production date + self.move2production = None + # Server's purchase date + self.purchase_date = None + # Server's end of warranty date + self.end_of_warranty = None + self.description = None diff --git a/itopapi/model/farm.py b/itopapi/model/farm.py new file mode 100644 index 0000000..dce0a58 --- /dev/null +++ b/itopapi/model/farm.py @@ -0,0 +1,72 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiFarm is an abstraction of a virtual servers farm representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.virtualHost import ItopapiVirtualHost +from itopapi.model.features.hasOrganization import HasOrganization + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiFarm(ItopapiVirtualHost, HasOrganization): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'Farm', + # Define which fields to save when creating or updating from the python API + 'save': ['name', 'status', 'business_criticity', 'move2production', 'description'], + 'foreign_keys': [ + HasOrganization.foreign_key, + ], + 'list_types': { + 'contacts_list': 'contact_id_finalclass_recall' + }, + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of Farm with the given key or criteria """ + return ItopapiPrototype.find(ItopapiFarm, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiFarm, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of Farm """ + return ItopapiPrototype.find_all(ItopapiFarm) + + """ + ItopapiFarm is an object that represents a Farm from iTop + """ + def __init__(self, data=None): + super(ItopapiFarm, self).__init__(data) + # Farm's status. Values within [inactive, active] + self.status = None + # Farm's business criticity. Values within [high, medium, low] + self.business_criticity = None + # Farm's move to production date + self.move2production = None + # Farm's description, as a free text + self.description = None + ################################## + # Lists # + ################################## + self.documents_list = None + self.softwares_list = None + self.applicationsolution_list = None + self.tickets_list = None + self.services_list = None + self.logicalvolumes_list = None + self.hypervisor_list = None + self.virtualmachine_list = None + + +# Register as a subclass of VirtualHost +ItopapiVirtualHost.register(ItopapiFarm) diff --git a/itopapi/model/features/__init__.py b/itopapi/model/features/__init__.py new file mode 100644 index 0000000..8e342ea --- /dev/null +++ b/itopapi/model/features/__init__.py @@ -0,0 +1,40 @@ +# -*- coding: utf8 -*-fr + +""" +Import all class needed +""" + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + +from itopapi.model.features.hasOrganization import HasOrganization +from itopapi.model.features.hasOrganization2 import HasOrganization2 +from itopapi.model.features.hasLocation import HasLocation +from itopapi.model.features.hasBrand import HasBrand +from itopapi.model.features.hasModel import HasModel +from itopapi.model.features.hasOSFamily import HasOSFamily +from itopapi.model.features.hasOSVersion import HasOSVersion +from itopapi.model.features.hasOSLicence import HasOSLicence +from itopapi.model.features.hasVirtualHost import HasVirtualHost +from itopapi.model.features.hasRack import HasRack +from itopapi.model.features.hasEnclosure import HasEnclosure +from itopapi.model.features.hasServer import HasServer +from itopapi.model.features.hasFarm import HasFarm +from itopapi.model.features.hasWebServer import HasWebServer +from itopapi.model.features.hasParentOrganization import HasParentOrganization +from itopapi.model.features.hasDeliveryModel import HasDeliveryModel +from itopapi.model.features.hasSoftware import HasSoftware +from itopapi.model.features.hasSoftwareLicence import HasSoftwareLicence +from itopapi.model.features.hasTeam import HasTeam +from itopapi.model.features.hasAgent import HasAgent +from itopapi.model.features.hasManager import HasManager +from itopapi.model.features.hasMiddleware import HasMiddleware +from itopapi.model.features.hasDBServer import HasDBServer +from itopapi.model.features.hasVirtualMachine import HasVirtualMachine +from itopapi.model.features.hasDatacenterDevice import HasDatacenterDevice +from itopapi.model.features.hasPowerStart import HasPowerStart +from itopapi.model.features.hasSystem import HasSystem +from itopapi.model.features.hasTapeLibrary import HasTapeLibrary +from itopapi.model.features.hasServiceFamily import HasServiceFamily +from itopapi.model.features.hasConnectableCI import HasConnectableCI +from itopapi.model.features.hasVLAN import HasVLAN diff --git a/itopapi/model/features/hasAgent.py b/itopapi/model/features/hasAgent.py new file mode 100644 index 0000000..06591e1 --- /dev/null +++ b/itopapi/model/features/hasAgent.py @@ -0,0 +1,45 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasAgent is a mixin representing the agent attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasAgent(object): + """ + HasAgent represents the Agent attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'agent_id', 'name': 'agent_name', 'table': 'Person'} + + def __init__(self): + super(HasAgent, self).__init__() + + # Object's agent id. Call find_agent to get the full information or just use agent_name + self.agent_id = None + # Object's agent id's friendly name. Not sure the difference with agent_name + self.agent_id_friendlyname = None + # Object's agent name + self.agent_name = None + + def find_agent(self): + """ + Retrieve the ItopapiAgent related to this instance + """ + if self.agent_id is not None: + return ItopapiPrototype.get_itop_class('Person').find(self.agent_id) + return None + + def set_agent(self, agent): + """ + Set the ItopapiPerson parameters + """ + self.agent_id = agent.instance_id + self.agent_id_friendlyname = agent.friendlyname + self.agent_name = agent.name diff --git a/itopapi/model/features/hasBrand.py b/itopapi/model/features/hasBrand.py new file mode 100644 index 0000000..1543b7d --- /dev/null +++ b/itopapi/model/features/hasBrand.py @@ -0,0 +1,46 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasBrand is a mixin representing the brand attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasBrand(object): + """ + HasBrand represents the Brand attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'brand_id', 'name': 'brand_name', 'table': 'Brand'} + + def __init__(self): + super(HasBrand, self).__init__() + + # Object's brand id. Call find_brand to get the full information or just use + # brand_id_friendlyname and brand_name + self.brand_id = None + # Object's brand id's friendly name. Not sure the difference with brand_name + self.brand_id_friendlyname = None + # Object's brand name + self.brand_name = None + + def find_brand(self): + """ + Retrieve the ItopapiBrand related to this instance + """ + if self.brand_id is not None: + return ItopapiPrototype.get_itop_class('Brand').find(self.brand_id) + return None + + def set_brand(self, brand): + """ + Set the ItopapiBrand parameters + """ + self.brand_id = brand.instance_id + self.brand_id_friendlyname = brand.friendlyname + self.brand_name = brand.name diff --git a/itopapi/model/features/hasConnectableCI.py b/itopapi/model/features/hasConnectableCI.py new file mode 100644 index 0000000..817d716 --- /dev/null +++ b/itopapi/model/features/hasConnectableCI.py @@ -0,0 +1,45 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasConnectableCI is a mixin representing the ConnectableCI attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasConnectableCI(object): + """ + HasConnectableCI represents the ConnectableCI attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'connectableci_id', 'name': 'connectableci_name', 'table': 'Person'} + + def __init__(self): + super(HasConnectableCI, self).__init__() + + # Object's connectableci id. Call find_connectableci to get the full information or just use connectableci_name + self.connectableci_id = None + # Object's connectableci id's friendly name. Not sure the difference with connectableci_name + self.connectableci_id_friendlyname = None + # Object's connectableci name + self.connectableci_name = None + + def find_connectableci(self): + """ + Retrieve the ItopapiConnectableCI related to this instance + """ + if self.connectableci_id is not None: + return ItopapiPrototype.get_itop_class('Person').find(self.connectableci_id) + return None + + def set_connectableci(self, connectableci): + """ + Set the ItopapiPerson parameters + """ + self.connectableci_id = connectableci.instance_id + self.connectableci_id_friendlyname = connectableci.friendlyname + self.connectableci_name = connectableci.name diff --git a/itopapi/model/features/hasDBServer.py b/itopapi/model/features/hasDBServer.py new file mode 100644 index 0000000..7b8b57b --- /dev/null +++ b/itopapi/model/features/hasDBServer.py @@ -0,0 +1,46 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasDBServer is a mixin representing the dbserver attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasDBServer(object): + """ + HasDBServer represents the DBServer attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'dbserver_id', 'name': 'dbserver_name', 'table': 'DBServer'} + + def __init__(self): + super(HasDBServer, self).__init__() + + # Object's dbserver id. Call find_dbserver to get the full information or just use + # dbserver_id_friendlyname and dbserver_name + self.dbserver_id = None + # Object's dbserver id's friendly name. Not sure the difference with dbserver_name + self.dbserver_id_friendlyname = None + # Object's dbserver name + self.dbserver_name = None + + def find_dbserver(self): + """ + Retrieve the ItopapiDBServer related to this instance + """ + if self.dbserver_id is not None: + return ItopapiPrototype.get_itop_class('DBServer').find(self.dbserver_id) + return None + + def set_dbserver(self, dbserver): + """ + Set the ItopapiDBServer parameters + """ + self.dbserver_id = dbserver.instance_id + self.dbserver_id_friendlyname = dbserver.friendlyname + self.dbserver_name = dbserver.name diff --git a/itopapi/model/features/hasDatacenterDevice.py b/itopapi/model/features/hasDatacenterDevice.py new file mode 100644 index 0000000..b006c94 --- /dev/null +++ b/itopapi/model/features/hasDatacenterDevice.py @@ -0,0 +1,46 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasDatacenterDevice is a mixin representing the datacenterdevice attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasDatacenterDevice(object): + """ + HasDatacenterDevice represents the DatacenterDevice attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'datacenterdevice_id', 'name': 'datacenterdevice_name', 'table': 'DatacenterDevice'} + + def __init__(self): + super(HasDatacenterDevice, self).__init__() + + # Object's datacenterdevice id. Call find_datacenterdevice to get the full information or just use + # datacenterdevice_id_friendlyname and datacenterdevice_name + self.datacenterdevice_id = None + # Object's datacenterdevice id's friendly name. Not sure the difference with datacenterdevice_name + self.datacenterdevice_id_friendlyname = None + # Object's datacenterdevice name + self.datacenterdevice_name = None + + def find_datacenterdevice(self): + """ + Retrieve the ItopapiDatacenterDevice related to this instance + """ + if self.datacenterdevice_id is not None: + return ItopapiPrototype.get_itop_class('DatacenterDevice').find(self.datacenterdevice_id) + return None + + def set_datacenterdevice(self, datacenterdevice): + """ + Set the ItopapiDatacenterDevice parameters + """ + self.datacenterdevice_id = datacenterdevice.instance_id + self.datacenterdevice_id_friendlyname = datacenterdevice.friendlyname + self.datacenterdevice_name = datacenterdevice.name diff --git a/itopapi/model/features/hasDeliveryModel.py b/itopapi/model/features/hasDeliveryModel.py new file mode 100644 index 0000000..edfe63d --- /dev/null +++ b/itopapi/model/features/hasDeliveryModel.py @@ -0,0 +1,46 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasDeliveryModel is a mixin representing the deliverymodel attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasDeliveryModel(object): + """ + HasDeliveryModel represents the DeliveryModel attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'deliverymodel_id', 'name': 'deliverymodel_name', 'table': 'DeliveryModel'} + + def __init__(self): + super(HasDeliveryModel, self).__init__() + + # Object's deliverymodel id. Call find_deliverymodel to get the full information or just use + # deliverymodel_id_friendlyname and deliverymodel_name + self.deliverymodel_id = None + # Object's deliverymodel id's friendly name. Not sure the difference with deliverymodel_name + self.deliverymodel_id_friendlyname = None + # Object's deliverymodel name + self.deliverymodel_name = None + + def find_deliverymodel(self): + """ + Retrieve the ItopapiDeliveryModel related to this instance + """ + if self.deliverymodel_id is not None: + return ItopapiPrototype.get_itop_class('DeliveryModel').find(self.deliverymodel_id) + return None + + def set_deliverymodel(self, deliverymodel): + """ + Set the ItopapiDeliveryModel parameters + """ + self.deliverymodel_id = deliverymodel.instance_id + self.deliverymodel_id_friendlyname = deliverymodel.friendlyname + self.deliverymodel_name = deliverymodel.name diff --git a/itopapi/model/features/hasEnclosure.py b/itopapi/model/features/hasEnclosure.py new file mode 100644 index 0000000..74bf83b --- /dev/null +++ b/itopapi/model/features/hasEnclosure.py @@ -0,0 +1,46 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasEnclosure is a mixin representing the enclosure attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasEnclosure(object): + """ + HasEnclosure represents the Enclosure attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'enclosure_id', 'name': 'enclosure_name', 'table': 'Enclosure'} + + def __init__(self): + super(HasEnclosure, self).__init__() + + # Object's enclosure id. Call find_enclosure to get the full information or just use + # enclosure_id_friendlyname and enclosure_name + self.enclosure_id = None + # Object's enclosure id's friendly name. Not sure the difference with enclosure_name + self.enclosure_id_friendlyname = None + # Object's enclosure name + self.enclosure_name = None + + def find_enclosure(self): + """ + Retrieve the ItopapiEnclosure related to this instance + """ + if self.enclosure_id is not None: + return ItopapiPrototype.get_itop_class('Enclosure').find(self.enclosure_id) + return None + + def set_enclosure(self, enclosure): + """ + Set the ItopapiEnclosure parameters + """ + self.enclosure_id = enclosure.instance_id + self.enclosure_id_friendlyname = enclosure.friendlyname + self.enclosure_name = enclosure.name diff --git a/itopapi/model/features/hasFarm.py b/itopapi/model/features/hasFarm.py new file mode 100644 index 0000000..a558d1e --- /dev/null +++ b/itopapi/model/features/hasFarm.py @@ -0,0 +1,46 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasFarm is a mixin representing the farm attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasFarm(object): + """ + HasFarm represents the Farm attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'farm_id', 'name': 'farm_name', 'table': 'Farm'} + + def __init__(self): + super(HasFarm, self).__init__() + + # Object's farm id. Call find_farm to get the full information or just use + # farm_id_friendlyname and farm_name + self.farm_id = None + # Object's farm id's friendly name. Not sure the difference with farm_name + self.farm_id_friendlyname = None + # Object's farm name + self.farm_name = None + + def find_farm(self): + """ + Retrieve the ItopapiFarm related to this instance + """ + if self.farm_id is not None: + return ItopapiPrototype.get_itop_class('Farm').find(self.farm_id) + return None + + def set_farm(self, farm): + """ + Set the ItopapiFarm parameters + """ + self.farm_id = farm.instance_id + self.farm_id_friendlyname = farm.friendlyname + self.farm_name = farm.name diff --git a/itopapi/model/features/hasIOSVersion.py b/itopapi/model/features/hasIOSVersion.py new file mode 100644 index 0000000..2487427 --- /dev/null +++ b/itopapi/model/features/hasIOSVersion.py @@ -0,0 +1,45 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasIOSVersion is a mixin representing the iosversion attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasIOSVersion(object): + """ + HasIOSVersion represents the IOSVersion attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'iosversion_id', 'name': 'iosversion_name', 'table': 'IOSVersion'} + + def __init__(self): + super(HasIOSVersion, self).__init__() + + # Object's iosversion id. Call find_iosversion to get the full information or just use iosversion_name + self.iosversion_id = None + # Object's iosversion id's friendly name. Not sure the difference with iosversion_name + self.iosversion_id_friendlyname = None + # Object's iosversion name + self.iosversion_name = None + + def find_iosversion(self): + """ + Retrieve the ItopapiIOSVersion related to this instance + """ + if self.iosversion_id is not None: + return ItopapiPrototype.get_itop_class('Person').find(self.iosversion_id) + return None + + def set_iosversion(self, iosversion): + """ + Set the ItopapiPerson parameters + """ + self.iosversion_id = iosversion.instance_id + self.iosversion_id_friendlyname = iosversion.friendlyname + self.iosversion_name = iosversion.name diff --git a/itopapi/model/features/hasLocation.py b/itopapi/model/features/hasLocation.py new file mode 100644 index 0000000..72995c8 --- /dev/null +++ b/itopapi/model/features/hasLocation.py @@ -0,0 +1,46 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasLocation is a mixin representing the location attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasLocation(object): + """ + HasLocation represents the Location attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'location_id', 'name': 'location_name', 'table': 'Location'} + + def __init__(self): + super(HasLocation, self).__init__() + + # Object's location id. Call find_location to get the full information or just use + # location_id_friendlyname and location_name + self.location_id = None + # Object's location id's friendly name. Not sure the difference with location_name + self.location_id_friendlyname = None + # Object's location name + self.location_name = None + + def find_location(self): + """ + Retrieve the ItopapiLocation related to this instance + """ + if self.location_id is not None: + return ItopapiPrototype.get_itop_class('Location').find(self.location_id) + return None + + def set_location(self, location): + """ + Set the ItopapiLocation parameters + """ + self.location_id = location.instance_id + self.location_id_friendlyname = location.friendlyname + self.location_name = location.name diff --git a/itopapi/model/features/hasManager.py b/itopapi/model/features/hasManager.py new file mode 100644 index 0000000..c9de785 --- /dev/null +++ b/itopapi/model/features/hasManager.py @@ -0,0 +1,45 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasManager is a mixin representing the manager attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasManager(object): + """ + HasManager represents the Manager attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'manager_id', 'name': 'manager_name', 'table': 'Person'} + + def __init__(self): + super(HasManager, self).__init__() + + # Object's manager id. Call find_manager to get the full information or just use manager_name + self.manager_id = None + # Object's manager id's friendly name. Not sure the difference with manager_name + self.manager_id_friendlyname = None + # Object's manager name + self.manager_name = None + + def find_manager(self): + """ + Retrieve the ItopapiManager related to this instance + """ + if self.manager_id is not None: + return ItopapiPrototype.get_itop_class('Person').find(self.manager_id) + return None + + def set_manager(self, manager): + """ + Set the ItopapiPerson parameters + """ + self.manager_id = manager.instance_id + self.manager_id_friendlyname = manager.friendlyname + self.manager_name = manager.name diff --git a/itopapi/model/features/hasMiddleware.py b/itopapi/model/features/hasMiddleware.py new file mode 100644 index 0000000..e1e1a54 --- /dev/null +++ b/itopapi/model/features/hasMiddleware.py @@ -0,0 +1,46 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasMiddleware is a mixin representing the middleware attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasMiddleware(object): + """ + HasMiddleware represents the Middleware attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'middleware_id', 'name': 'middleware_name', 'table': 'Middleware'} + + def __init__(self): + super(HasMiddleware, self).__init__() + + # Object's middleware id. Call find_middleware to get the full information or just use + # middleware_id_friendlyname and middleware_name + self.middleware_id = None + # Object's middleware id's friendly name. Not sure the difference with middleware_name + self.middleware_id_friendlyname = None + # Object's middleware name + self.middleware_name = None + + def find_middleware(self): + """ + Retrieve the ItopapiMiddleware related to this instance + """ + if self.middleware_id is not None: + return ItopapiPrototype.get_itop_class('Middleware').find(self.middleware_id) + return None + + def set_middleware(self, middleware): + """ + Set the ItopapiMiddleware parameters + """ + self.middleware_id = middleware.instance_id + self.middleware_id_friendlyname = middleware.friendlyname + self.middleware_name = middleware.name diff --git a/itopapi/model/features/hasModel.py b/itopapi/model/features/hasModel.py new file mode 100644 index 0000000..14551d5 --- /dev/null +++ b/itopapi/model/features/hasModel.py @@ -0,0 +1,46 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasModel is a mixin representing the model attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasModel(object): + """ + HasModel represents the Model attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'model_id', 'name': 'model_name', 'table': 'Model'} + + def __init__(self): + super(HasModel, self).__init__() + + # Object's model id. Call find_model to get the full information or just use + # model_id_friendlyname and model_name + self.model_id = None + # Object's model id's friendly name. Not sure the difference with model_name + self.model_id_friendlyname = None + # Object's model name + self.model_name = None + + def find_model(self): + """ + Retrieve the ItopapiModel related to this instance + """ + if self.model_id is not None: + return ItopapiPrototype.get_itop_class('Model').find(self.location_id) + return None + + def set_model(self, model): + """ + Set the ItopapiModel parameters + """ + self.model_id = model.instance_id + self.model_id_friendlyname = model.friendlyname + self.model_name = model.name diff --git a/itopapi/model/features/hasNetworkDeviceType.py b/itopapi/model/features/hasNetworkDeviceType.py new file mode 100644 index 0000000..393317b --- /dev/null +++ b/itopapi/model/features/hasNetworkDeviceType.py @@ -0,0 +1,46 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasNetworkDeviceType is a mixin representing the NetworkDeviceType attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasNetworkDeviceType(object): + """ + HasNetworkDeviceType represents the NetworkDeviceType attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'networkdevicetype_id', 'name': 'networkdevicetype_name', 'table': 'NetworkDeviceType'} + + def __init__(self): + super(HasNetworkDeviceType, self).__init__() + + # Object's NetworkDeviceType id. Call find_NetworkDeviceType to get the full information or just use + # networkdevicetype_id_friendlyname and networkdevicetype_name + self.networkdevicetype_id = None + # Object's NetworkDeviceType id's friendly name. Not sure the difference with networkdevicetype_name + self.networkdevicetype_id_friendlyname = None + # Object's NetworkDeviceType name + self.networkdevicetype_name = None + + def find_NetworkDeviceType(self): + """ + Retrieve the ItopapiNetworkDeviceType related to this instance + """ + if self.networkdevicetype_id is not None: + return ItopapiPrototype.get_itop_class('NetworkDeviceType').find(self.networkdevicetype_id) + return None + + def set_NetworkDeviceType(self, NetworkDeviceType): + """ + Set the ItopapiNetworkDeviceType parameters + """ + self.networkdevicetype_id = NetworkDeviceType.instance_id + self.networkdevicetype_id_friendlyname = NetworkDeviceType.friendlyname + self.networkdevicetype_name = NetworkDeviceType.name diff --git a/itopapi/model/features/hasOSFamily.py b/itopapi/model/features/hasOSFamily.py new file mode 100644 index 0000000..875b3d2 --- /dev/null +++ b/itopapi/model/features/hasOSFamily.py @@ -0,0 +1,46 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasOSFamily is a mixin representing the osfamily attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasOSFamily(object): + """ + HasOSFamily represents the OSFamily attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'osfamily_id', 'name': 'osfamily_name', 'table': 'OSFamily'} + + def __init__(self): + super(HasOSFamily, self).__init__() + + # Object's osfamily id. Call find_osfamily to get the full information or just use + # osfamily_id_friendlyname and osfamily_name + self.osfamily_id = None + # Object's osfamily id's friendly name. Not sure the difference with osfamily_name + self.osfamily_id_friendlyname = None + # Object's osfamily name + self.osfamily_name = None + + def find_osfamily(self): + """ + Retrieve the ItopapiOSFamily related to this instance + """ + if self.osfamily_id is not None: + return ItopapiPrototype.get_itop_class('OSFamily').find(self.osfamily_id) + return None + + def set_osfamily(self, osfamily): + """ + Set the ItopapiFamily parameters + """ + self.osfamily_id = osfamily.instance_id + self.osfamily_id_friendlyname = osfamily.friendlyname + self.osfamily_name = osfamily.name diff --git a/itopapi/model/features/hasOSLicence.py b/itopapi/model/features/hasOSLicence.py new file mode 100644 index 0000000..358891c --- /dev/null +++ b/itopapi/model/features/hasOSLicence.py @@ -0,0 +1,46 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasOSLicence is a mixin representing the oslicence attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasOSLicence(object): + """ + HasOSLicence represents the OSLicence attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'oslicence_id', 'name': 'oslicence_name', 'table': 'OSLicence'} + + def __init__(self): + super(HasOSLicence, self).__init__() + + # Object's oslicence id. Call find_oslicence to get the full information or just use + # oslicence_id_friendlyname and oslicence_name + self.oslicence_id = None + # Object's oslicence id's friendly name. Not sure the difference with oslicence_name + self.oslicence_id_friendlyname = None + # Object's oslicence name + self.oslicence_name = None + + def find_oslicence(self): + """ + Retrieve the ItopapiOSLicence related to this instance + """ + if self.oslicence_id is not None: + return ItopapiPrototype.get_itop_class('OSLicence').find(self.oslicence_id) + return None + + def set_oslicence(self, oslicence): + """ + Set the ItopapiOSlicence parameters + """ + self.oslicence_id = oslicence.instance_id + self.oslicence_id_friendlyname = oslicence.friendlyname + self.oslicence_name = oslicence.name diff --git a/itopapi/model/features/hasOSVersion.py b/itopapi/model/features/hasOSVersion.py new file mode 100644 index 0000000..eb5b277 --- /dev/null +++ b/itopapi/model/features/hasOSVersion.py @@ -0,0 +1,46 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasOSVersion is a mixin representing the osversion attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasOSVersion(object): + """ + HasOSVersion represents the OSVersion attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'osversion_id', 'name': 'osversion_name', 'table': 'OSVersion'} + + def __init__(self): + super(HasOSVersion, self).__init__() + + # Object's osversion id. Call find_osversion to get the full information or just use + # osversion_id_friendlyname and osversion_name + self.osversion_id = None + # Object's osversion id's friendly name. Not sure the difference with osversion_name + self.osversion_id_friendlyname = None + # Object's osversion name + self.osversion_name = None + + def find_osversion(self): + """ + Retrieve the ItopapiOSVersion related to this instance + """ + if self.osversion_id is not None: + return ItopapiPrototype.get_itop_class('OSVersion').find(self.osversion_id) + return None + + def set_osversion(self, osversion): + """ + Set the ItopapiOSVersion parameters + """ + self.osversion_id = osversion.instance_id + self.osversion_id_friendlyname = osversion.friendlyname + self.osversion_name = osversion.name diff --git a/itopapi/model/features/hasOrganization.py b/itopapi/model/features/hasOrganization.py new file mode 100644 index 0000000..7bd3764 --- /dev/null +++ b/itopapi/model/features/hasOrganization.py @@ -0,0 +1,46 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasOrganization is a mixin representing the organization attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasOrganization(object): + """ + HasOrganization represents the organization attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'org_id', 'name': 'organization_name', 'table': 'Organization'} + + def __init__(self): + super(HasOrganization, self).__init__() + + # Object's organization id. Call find_organization to get the full information or just use + # org_id_friendlyname and organization_name + self.org_id = None + # Object's organization friendly name. Not sure the difference with organization_name + self.org_id_friendlyname = None + # Object's organization name + self.organization_name = None + + def find_organization(self): + """ + Retrieve the ItopapiOrganization related to this instance + """ + if self.org_id is not None: + return ItopapiPrototype.get_itop_class('Organization').find(self.org_id) + return None + + def set_organization(self, organization): + """ + Set the ItopapiOrganization parameters + """ + self.org_id = organization.instance_id + self.org_id_friendlyname = organization.friendlyname + self.organization_name = organization.name diff --git a/itopapi/model/features/hasOrganization2.py b/itopapi/model/features/hasOrganization2.py new file mode 100644 index 0000000..7090175 --- /dev/null +++ b/itopapi/model/features/hasOrganization2.py @@ -0,0 +1,49 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasOrganization2 is a mixin representing the organization attached to some of the objects. +It is only used by ItopaiVLAN which has org_name instead of organization_name +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasOrganization2(object): + """ + HasOrganization2 represents the Organization attached to some top-level objects. + It is nearly a duplicate of HasOrganization with org_name instead of organization_name + because of iTop's poor naming conventions. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'org_id', 'name': 'org_name', 'table': 'Organization'} + + def __init__(self): + super(HasOrganization2, self).__init__() + + # Object's organization id. Call find_organization to get the full information or just use + # org_id_friendlyname and organization_name + self.org_id = None + # Object's organization friendly name. Not sure the difference with organization_name + self.org_id_friendlyname = None + # Object's organization name + self.org_name = None + + def find_organization(self): + """ + Retrieve the ItopapiOrganization related to this instance + """ + if self.org_id is not None: + return ItopapiPrototype.get_itop_class('Organization').find(self.org_id) + return None + + def set_organization(self, organization): + """ + Set the ItopapiOrganization parameters + """ + self.org_id = organization.instance_id + self.org_id_friendlyname = organization.friendlyname + self.org_name = organization.name diff --git a/itopapi/model/features/hasParentOrganization.py b/itopapi/model/features/hasParentOrganization.py new file mode 100644 index 0000000..5583665 --- /dev/null +++ b/itopapi/model/features/hasParentOrganization.py @@ -0,0 +1,46 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasParentOrganization is a mixin representing the parent organization attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasParentOrganization(object): + """ + HasParentOrganization represents the ParentOrganization attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'parent_id', 'name': 'parent_name', 'table': 'Organization'} + + def __init__(self): + super(HasParentOrganization, self).__init__() + + # Object's parent id. Call find_parent to get the full information or just use + # parent_id_friendlyname and parent_name + self.parent_id = None + # Object's parent id's friendly name. Not sure the difference with parent_name + self.parent_id_friendlyname = None + # Object's parent name + self.parent_name = None + + def find_parent(self): + """ + Retrieve the ItopapiOrganization related to this instance + """ + if self.parent_id is not None: + return ItopapiPrototype.get_itop_class('Organization').find(self.parent_id) + return None + + def set_parent(self, parent): + """ + Set the ItopapiOrganization parameters + """ + self.parent_id = parent.instance_id + self.parent_id_friendlyname = parent.friendlyname + self.parent_name = parent.name diff --git a/itopapi/model/features/hasPowerA.py b/itopapi/model/features/hasPowerA.py new file mode 100644 index 0000000..fcd163f --- /dev/null +++ b/itopapi/model/features/hasPowerA.py @@ -0,0 +1,45 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasPowerA is a mixin representing the powerA attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasPowerA(object): + """ + HasPowerA represents the Power attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'powerA_id', 'name': 'powerA_name', 'table': 'Power'} + + def __init__(self): + super(HasPowerA, self).__init__() + + # Object's powerA id. Call find_powerA to get the full information or just use powerA_name + self.powerA_id = None + # Object's powerA id's friendly name. Not sure the difference with powerA_name + self.powerA_id_friendlyname = None + # Object's powerA name + self.powerA_name = None + + def find_powerA(self): + """ + Retrieve the ItopapiAgent related to this instance + """ + if self.powerA_id is not None: + return ItopapiPrototype.get_itop_class('Person').find(self.powerA_id) + return None + + def set_powerA(self, powerA): + """ + Set the ItopapiPerson parameters + """ + self.powerA_id = powerA.instance_id + self.powerA_id_friendlyname = powerA.friendlyname + self.powerA_name = powerA.name diff --git a/itopapi/model/features/hasPowerB.py b/itopapi/model/features/hasPowerB.py new file mode 100644 index 0000000..92e1763 --- /dev/null +++ b/itopapi/model/features/hasPowerB.py @@ -0,0 +1,45 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasPowerB is a mixin representing the powerB attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasPowerB(object): + """ + HasPowerB represents the Power attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'powerB_id', 'name': 'powerB_name', 'table': 'Power'} + + def __init__(self): + super(HasPowerB, self).__init__() + + # Object's powerB id. Call find_powerB to get the full information or just use powerB_name + self.powerB_id = None + # Object's powerB id's friendly name. Not sure the difference with powerB_name + self.powerB_id_friendlyname = None + # Object's powerB name + self.powerB_name = None + + def find_powerB(self): + """ + Retrieve the ItopapiAgent related to this instance + """ + if self.powerB_id is not None: + return ItopapiPrototype.get_itop_class('Person').find(self.powerB_id) + return None + + def set_powerB(self, powerB): + """ + Set the ItopapiPerson parameters + """ + self.powerB_id = powerB.instance_id + self.powerB_id_friendlyname = powerB.friendlyname + self.powerB_name = powerB.name diff --git a/itopapi/model/features/hasPowerStart.py b/itopapi/model/features/hasPowerStart.py new file mode 100644 index 0000000..fb1adcd --- /dev/null +++ b/itopapi/model/features/hasPowerStart.py @@ -0,0 +1,45 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasPowerStart is a mixin representing the powerstart attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasPowerStart(object): + """ + HasPowerStart represents the PowerConnection attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'powerstart_id', 'name': 'powerstart_name', 'table': 'PowerConnection'} + + def __init__(self): + super(HasPowerStart, self).__init__() + + # Object's powerstart id. Call find_powerstart to get the full information or just use powerstart_name + self.powerstart_id = None + # Object's powerstart id's friendly name. Not sure the difference with powerstart_name + self.powerstart_id_friendlyname = None + # Object's powerstart name + self.powerstart_name = None + + def find_powerstart(self): + """ + Retrieve the ItopapiPowerStart related to this instance + """ + if self.powerstart_id is not None: + return ItopapiPrototype.get_itop_class('Person').find(self.powerstart_id) + return None + + def set_powerstart(self, powerstart): + """ + Set the ItopapiPerson parameters + """ + self.powerstart_id = powerstart.instance_id + self.powerstart_id_friendlyname = powerstart.friendlyname + self.powerstart_name = powerstart.name diff --git a/itopapi/model/features/hasRack.py b/itopapi/model/features/hasRack.py new file mode 100644 index 0000000..d0f1238 --- /dev/null +++ b/itopapi/model/features/hasRack.py @@ -0,0 +1,46 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasRack is a mixin representing the rack attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasRack(object): + """ + HasRack represents the Rack attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'rack_id', 'name': 'rack_name', 'table': 'Rack'} + + def __init__(self): + super(HasRack, self).__init__() + + # Object's rack id. Call find_rack to get the full information or just use + # rack_id_friendlyname and rack_name + self.rack_id = None + # Object's rack id's friendly name. Not sure the difference with rack_name + self.rack_id_friendlyname = None + # Object's rack name + self.rack_name = None + + def find_rack(self): + """ + Retrieve the ItopapiRack related to this instance + """ + if self.rack_id is not None: + return ItopapiPrototype.get_itop_class('Rack').find(self.rack_id) + return None + + def set_rack(self, rack): + """ + Set the ItopapiRack parameters + """ + self.rack_id = rack.instance_id + self.rack_id_friendlyname = rack.friendlyname + self.rack_name = rack.name diff --git a/itopapi/model/features/hasServer.py b/itopapi/model/features/hasServer.py new file mode 100644 index 0000000..4a9f7c4 --- /dev/null +++ b/itopapi/model/features/hasServer.py @@ -0,0 +1,46 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasServer is a mixin representing the server attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasServer(object): + """ + HasServer represents the Server attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'server_id', 'name': 'server_name', 'table': 'Server'} + + def __init__(self): + super(HasServer, self).__init__() + + # Object's server id. Call find_server to get the full information or just use + # server_id_friendlyname and server_name + self.server_id = None + # Object's server id's friendly name. Not sure the difference with server_name + self.server_id_friendlyname = None + # Object's server name + self.server_name = None + + def find_server(self): + """ + Retrieve the ItopapiServer related to this instance + """ + if self.server_id is not None: + return ItopapiPrototype.get_itop_class('Server').find(self.server_id) + return None + + def set_server(self, server): + """ + Set the ItopapiServer parameters + """ + self.server_id = server.instance_id + self.server_id_friendlyname = server.friendlyname + self.server_name = server.name diff --git a/itopapi/model/features/hasServiceFamily.py b/itopapi/model/features/hasServiceFamily.py new file mode 100644 index 0000000..051103b --- /dev/null +++ b/itopapi/model/features/hasServiceFamily.py @@ -0,0 +1,46 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasServiceFamily is a mixin representing the ServiceFamily attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasServiceFamily(object): + """ + HasServiceFamily represents the ServiceFamily attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'servicefamily_id', 'name': 'servicefamily_name', 'table': 'ServiceFamily'} + + def __init__(self): + super(HasServiceFamily, self).__init__() + + # Object's ServiceFamily id. Call find_servicefamily to get the full information or just use + # servicefamily_id_friendlyname and servicefamily_name + self.servicefamily_id = None + # Object's ServiceFamily id's friendly name. Not sure the difference with servicefamily_name + self.servicefamily_id_friendlyname = None + # Object's ServiceFamily name + self.servicefamily_name = None + + def find_servicefamily(self): + """ + Retrieve the ItopapiServiceFamily related to this instance + """ + if self.servicefamily_id is not None: + return ItopapiPrototype.get_itop_class('ServiceFamily').find(self.servicefamily_id) + return None + + def set_servicefamily(self, servicefamily): + """ + Set the ItopapiServiceFamily parameters + """ + self.servicefamily_id = servicefamily.instance_id + self.servicefamily_id_friendlyname = servicefamily.friendlyname + self.servicefamily_name = servicefamily.name diff --git a/itopapi/model/features/hasSoftware.py b/itopapi/model/features/hasSoftware.py new file mode 100644 index 0000000..248b2e6 --- /dev/null +++ b/itopapi/model/features/hasSoftware.py @@ -0,0 +1,46 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasSoftware is a mixin representing the software attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasSoftware(object): + """ + HasSoftware represents the Software attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'software_id', 'name': 'software_name', 'table': 'Software'} + + def __init__(self): + super(HasSoftware, self).__init__() + + # Object's software id. Call find_software to get the full information or just use + # software_id_friendlyname and software_name + self.software_id = None + # Object's software id's friendly name. Not sure the difference with software_name + self.software_id_friendlyname = None + # Object's software name + self.software_name = None + + def find_software(self): + """ + Retrieve the ItopapiSoftware related to this instance + """ + if self.software_id is not None: + return ItopapiPrototype.get_itop_class('Software').find(self.software_id) + return None + + def set_software(self, software): + """ + Set the ItopapiServer parameters + """ + self.software_id = software.instance_id + self.software_id_friendlyname = software.friendlyname + self.software_name = software.name diff --git a/itopapi/model/features/hasSoftwareLicence.py b/itopapi/model/features/hasSoftwareLicence.py new file mode 100644 index 0000000..edf88ba --- /dev/null +++ b/itopapi/model/features/hasSoftwareLicence.py @@ -0,0 +1,46 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasSoftwareLicence is a mixin representing the softwarelicence attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasSoftwareLicence(object): + """ + HasSoftwareLicence represents the SoftwareLicence attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'softwarelicence_id', 'name': 'softwarelicence_name', 'table': 'SoftwareLicence'} + + def __init__(self): + super(HasSoftwareLicence, self).__init__() + + # Object's softwarelicence id. Call find_softwarelicence to get the full information or just use + # softwarelicence_id_friendlyname and softwarelicence_name + self.softwarelicence_id = None + # Object's softwarelicence id's friendly name. Not sure the difference with softwarelicence_name + self.softwarelicence_id_friendlyname = None + # Object's softwarelicence name + self.softwarelicence_name = None + + def find_softwarelicence(self): + """ + Retrieve the ItopapiSoftwareLicence related to this instance + """ + if self.softwarelicence_id is not None: + return ItopapiPrototype.get_itop_class('SoftwareLicence').find(self.softwarelicence_id) + return None + + def set_softwarelicence(self, softwarelicence): + """ + Set the ItopapiSoftwareLicence parameters + """ + self.softwarelicence_id = softwarelicence.instance_id + self.softwarelicence_id_friendlyname = softwarelicence.friendlyname + self.softwarelicence_name = softwarelicence.name diff --git a/itopapi/model/features/hasSystem.py b/itopapi/model/features/hasSystem.py new file mode 100644 index 0000000..3dbfe60 --- /dev/null +++ b/itopapi/model/features/hasSystem.py @@ -0,0 +1,45 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasSystem is a mixin representing the FunctionalCI attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasSystem(object): + """ + HasSystem represents the System attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'system_id', 'name': 'system_name', 'table': 'FunctionalCI'} + + def __init__(self): + super(HasSystem, self).__init__() + + # Object's system id. Call find_system to get the full information or just use system_name + self.system_id = None + # Object's system id's friendly name. Not sure the difference with system_name + self.system_id_friendlyname = None + # Object's system name + self.system_name = None + + def find_system(self): + """ + Retrieve the Itopapisystem related to this instance + """ + if self.system_id is not None: + return ItopapiPrototype.get_itop_class('Person').find(self.system_id) + return None + + def set_system(self, system): + """ + Set the ItopapiPerson parameters + """ + self.system_id = system.instance_id + self.system_id_friendlyname = system.friendlyname + self.system_name = system.name diff --git a/itopapi/model/features/hasTapeLibrary.py b/itopapi/model/features/hasTapeLibrary.py new file mode 100644 index 0000000..8109f53 --- /dev/null +++ b/itopapi/model/features/hasTapeLibrary.py @@ -0,0 +1,45 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasTapeLibrary is a mixin representing the tapelibrary attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasTapeLibrary(object): + """ + HasTapeLibrary represents the TapeLibrary attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'tapelibrary_id', 'name': 'tapelibrary_name', 'table': 'TapeLibrary'} + + def __init__(self): + super(HasTapeLibrary, self).__init__() + + # Object's tapelibrary id. Call find_tapelibrary to get the full information or just use tapelibrary_name + self.tapelibrary_id = None + # Object's tapelibrary id's friendly name. Not sure the difference with tapelibrary_name + self.tapelibrary_id_friendlyname = None + # Object's tapelibrary name + self.tapelibrary_name = None + + def find_tapelibrary(self): + """ + Retrieve the ItopapiTapeLibrary related to this instance + """ + if self.tapelibrary_id is not None: + return ItopapiPrototype.get_itop_class('Person').find(self.tapelibrary_id) + return None + + def set_tapelibrary(self, tapelibrary): + """ + Set the ItopapiPerson parameters + """ + self.tapelibrary_id = tapelibrary.instance_id + self.tapelibrary_id_friendlyname = tapelibrary.friendlyname + self.tapelibrary_name = tapelibrary.name diff --git a/itopapi/model/features/hasTeam.py b/itopapi/model/features/hasTeam.py new file mode 100644 index 0000000..a299a6d --- /dev/null +++ b/itopapi/model/features/hasTeam.py @@ -0,0 +1,46 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasTeam is a mixin representing the team attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasTeam(object): + """ + HasTeam represents the Team attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'team_id', 'name': 'team_name', 'table': 'Team'} + + def __init__(self): + super(HasTeam, self).__init__() + + # Object's team id. Call find_team to get the full information or just use + # team_id_friendlyname and team_name + self.team_id = None + # Object's team id's friendly name. Not sure the difference with team_name + self.team_id_friendlyname = None + # Object's team name + self.team_name = None + + def find_team(self): + """ + Retrieve the ItopapiTeam related to this instance + """ + if self.team_id is not None: + return ItopapiPrototype.get_itop_class('Team').find(self.team_id) + return None + + def set_team(self, team): + """ + Set the ItopapiTeam parameters + """ + self.team_id = team.instance_id + self.team_id_friendlyname = team.friendlyname + self.team_name = team.name diff --git a/itopapi/model/features/hasVLAN.py b/itopapi/model/features/hasVLAN.py new file mode 100644 index 0000000..be7ca0f --- /dev/null +++ b/itopapi/model/features/hasVLAN.py @@ -0,0 +1,45 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasVLAN is a mixin representing the VLAN attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasVLAN(object): + """ + HasVLAN represents the VLAN attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'vlan_id', 'name': 'vlan_tag', 'table': 'Person'} + + def __init__(self): + super(HasVLAN, self).__init__() + + # Object's vlan id. Call find_vlan to get the full information or just use vlan_name + self.vlan_id = None + # Object's vlan id's friendly name. Not sure the difference with vlan_name + self.vlan_id_friendlyname = None + # Object's vlan name + self.vlan_name = None + + def find_vlan(self): + """ + Retrieve the ItopapiVLAN related to this instance + """ + if self.vlan_id is not None: + return ItopapiPrototype.get_itop_class('Person').find(self.vlan_id) + return None + + def set_vlan(self, vlan): + """ + Set the ItopapiPerson parameters + """ + self.vlan_id = vlan.instance_id + self.vlan_id_friendlyname = vlan.friendlyname + self.vlan_name = vlan.name diff --git a/itopapi/model/features/hasVirtualHost.py b/itopapi/model/features/hasVirtualHost.py new file mode 100644 index 0000000..e673095 --- /dev/null +++ b/itopapi/model/features/hasVirtualHost.py @@ -0,0 +1,46 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasVirtualHost is a mixin representing the virtualhost attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasVirtualHost(object): + """ + HasVirtualHost represents the VirtualHost attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'virtualhost_id', 'name': 'virtualhost_name', 'table': 'VirtualHost'} + + def __init__(self): + super(HasVirtualHost, self).__init__() + + # Object's virtualhost id. Call find_virtualhost to get the full information or just use + # virtualhost_id_friendlyname and virtualhost_name + self.virtualhost_id = None + # Object's virtualhost id's friendly name. Not sure the difference with virtualhost_name + self.virtualhost_id_friendlyname = None + # Object's virtualhost name + self.virtualhost_name = None + + def find_virtualhost(self): + """ + Retrieve the ItopapiVirtualHost related to this instance + """ + if self.virtualhost_id is not None: + return ItopapiPrototype.get_itop_class('VirtualHost').find(self.virtualhost_id) + return None + + def set_virtualhost(self, virtualhost): + """ + Set the ItopapiVirtualHost parameters + """ + self.virtualhost_id = virtualhost.instance_id + self.virtualhost_id_friendlyname = virtualhost.friendlyname + self.virtualhost_name = virtualhost.name diff --git a/itopapi/model/features/hasVirtualMachine.py b/itopapi/model/features/hasVirtualMachine.py new file mode 100644 index 0000000..cd8c4a7 --- /dev/null +++ b/itopapi/model/features/hasVirtualMachine.py @@ -0,0 +1,46 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasVirtualMachine is a mixin representing the virtualmachine attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasVirtualMachine(object): + """ + HasVirtualMachine represents the VirtualMachine attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'virtualmachine_id', 'name': 'virtualmachine_name', 'table': 'VirtualMachine'} + + def __init__(self): + super(HasVirtualMachine, self).__init__() + + # Object's virtualmachine id. Call find_virtualmachine to get the full information or just use + # virtualmachine_id_friendlyname and virtualmachine_name + self.virtualmachine_id = None + # Object's virtualmachine id's friendly name. Not sure the difference with virtualmachine_name + self.virtualmachine_id_friendlyname = None + # Object's virtualmachine name + self.virtualmachine_name = None + + def find_virtualmachine(self): + """ + Retrieve the ItopapiVirtualMachine related to this instance + """ + if self.virtualmachine_id is not None: + return ItopapiPrototype.get_itop_class('VirtualMachine').find(self.virtualmachine_id) + return None + + def set_virtualmachine(self, virtualmachine): + """ + Set the ItopapiVirtualMachine parameters + """ + self.virtualmachine_id = virtualmachine.instance_id + self.virtualmachine_id_friendlyname = virtualmachine.friendlyname + self.virtualmachine_name = virtualmachine.name diff --git a/itopapi/model/features/hasWebServer.py b/itopapi/model/features/hasWebServer.py new file mode 100644 index 0000000..de1f2f5 --- /dev/null +++ b/itopapi/model/features/hasWebServer.py @@ -0,0 +1,46 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +HasWebServer is a mixin representing the webserver attached to some of the objects. +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class HasWebServer(object): + """ + HasWebServer represents the WebServer attached to some top-level objects. + """ + + """ Configuration specific to itop """ + foreign_key = {'id': 'webserver_id', 'name': 'webserver_name', 'table': 'WebServer'} + + def __init__(self): + super(HasWebServer, self).__init__() + + # Object's webserver id. Call find_webserver to get the full information or just use + # webserver_id_friendlyname and webserver_name + self.webserver_id = None + # Object's webserver id's friendly name. Not sure the difference with webserver_name + self.webserver_id_friendlyname = None + # Object's webserver name + self.webserver_name = None + + def find_webserver(self): + """ + Retrieve the ItopapiWebServer related to this instance + """ + if self.webserver_id is not None: + return ItopapiPrototype.get_itop_class('WebServer').find(self.webserver_id) + return None + + def set_webserver(self, webserver): + """ + Set the ItopapiWebServer parameters + """ + self.webserver_id = webserver.instance_id + self.webserver_id_friendlyname = webserver.friendlyname + self.webserver_name = webserver.name diff --git a/itopapi/model/fiberChannelInterface.py b/itopapi/model/fiberChannelInterface.py new file mode 100644 index 0000000..c15fbb4 --- /dev/null +++ b/itopapi/model/fiberChannelInterface.py @@ -0,0 +1,62 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiFiberChannelInterface is an abstraction of FiberChannelInterface representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.ipInterface import ItopapiIPInterface +from itopapi.model.features.hasDatacenterDevice import HasDatacenterDevice + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiFiberChannelInterface(ItopapiIPInterface): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'FiberChannelInterface', + # Define which fields to save when creating or updating from the python API + 'save': ['name', 'ipaddress', 'macaddress', 'comment', 'ipgateway', 'ipmask', 'speed'], + 'foreign_keys': [ + HasDatacenterDevice.foreign_key, + ], + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of FiberChannelInterface with the given key or criteria """ + return ItopapiPrototype.find(ItopapiFiberChannelInterface, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiFiberChannelInterface, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of FiberChannelInterface """ + return ItopapiPrototype.find_all(ItopapiFiberChannelInterface) + + """ + ItopapiFiberChannelInterface is an object that represents a FiberChannelInterface from iTop + """ + def __init__(self, data=None): + super(ItopapiFiberChannelInterface, self).__init__(data) + # IP address of the FiberChannelInterface + self.ipaddress = None + # MAC address of the FiberChannelInterface + self.macaddress = None + # Any kind of comment + self.comment = None + # IP gateway of the FiberChannelInterface + self.ipgateway = None + # IP mask of the FiberChannelInterface + self.ipmask = None + # speed of the FiberChannelInterface + self.speed = None + + +# Register as a subclass of IPInterface +ItopapiIPInterface.register(ItopapiFiberChannelInterface) diff --git a/itopapi/model/functionalCI.py b/itopapi/model/functionalCI.py new file mode 100644 index 0000000..6b3afb0 --- /dev/null +++ b/itopapi/model/functionalCI.py @@ -0,0 +1,43 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiFunctionalCI is an abstraction of Functional CI representation on iTop +It serves as a base class for a lot of subclasses. +""" + +from abc import ABCMeta +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiFunctionalCI(ItopapiPrototype): + __metaclass__ = ABCMeta + + # Configuration specific to itop + itop = { + 'name': 'FunctionalCI', + 'save': [], + 'foreign_keys': [] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of Functional CI with the given key or criteria """ + return ItopapiPrototype.find(ItopapiFunctionalCI, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiFunctionalCI, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of Functional CI """ + return ItopapiPrototype.find_all(ItopapiFunctionalCI) + + """ + ItopapiFunctionalCI is an object that represents a Functional CI from iTop + """ + def __init__(self, data=None): + super(ItopapiFunctionalCI, self).__init__(data) diff --git a/itopapi/model/hypervisor.py b/itopapi/model/hypervisor.py new file mode 100644 index 0000000..8f8b9fa --- /dev/null +++ b/itopapi/model/hypervisor.py @@ -0,0 +1,76 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiHypervisor is an abstraction of a virtual servers Hypervisor representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.virtualHost import ItopapiVirtualHost +from itopapi.model.features.hasOrganization import HasOrganization +from itopapi.model.features.hasServer import HasServer +from itopapi.model.features.hasFarm import HasFarm + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiHypervisor(ItopapiVirtualHost, HasOrganization, HasFarm): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'Hypervisor', + # Define which fields to save when creating or updating from the python API + 'save': ['name', 'status', 'business_criticity', 'move2production', 'description'], + 'foreign_keys': [ + HasOrganization.foreign_key, + HasServer.foreign_key, + HasFarm.foreign_key, + ], + 'list_types': { + 'contacts_list': 'contact_id_finalclass_recall' + }, + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of Hypervisor with the given key or criteria """ + return ItopapiPrototype.find(ItopapiHypervisor, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiHypervisor, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of Hypervisor """ + return ItopapiPrototype.find_all(ItopapiHypervisor) + + """ + ItopapiHypervisor is an object that represents a Hypervisor from iTop + """ + def __init__(self, data=None): + super(ItopapiHypervisor, self).__init__(data) + # Hypervisor's status. Values within [inactive, active] + self.status = None + # Hypervisor's business criticity. Values within [high, medium, low] + self.business_criticity = None + # Hypervisor's move to production date + self.move2production = None + # Hypervisor's description, as a free text + self.description = None + + # Lists + self.tickets_list = None + self.providercontracts_list = None + self.virtualmachine_list = None + self.services_list = None + self.applicationsolution_list = None + self.softwares_list = None + self.documents_list = None + self.contacts_list = None + self.logicalvolumes_list = None + + +# Register as a subclass of VirtualHost +ItopapiVirtualHost.register(ItopapiHypervisor) diff --git a/itopapi/model/incident.py b/itopapi/model/incident.py new file mode 100644 index 0000000..9299529 --- /dev/null +++ b/itopapi/model/incident.py @@ -0,0 +1,69 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiIncident is an abstraction of a Incident representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.features.hasOrganization import HasOrganization +from itopapi.model.features.hasTeam import HasTeam +from itopapi.model.features.hasAgent import HasAgent + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiIncident(ItopapiPrototype, HasOrganization, HasTeam, HasAgent): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'Incident', + # Define which fields to save when creating or updating from the python API + 'save': ['title', 'description', 'ref', 'start_date', 'end_date', 'close_date', 'last_update'], + 'foreign_keys': [ + HasOrganization.foreign_key, + HasAgent.foreign_key, + HasTeam.foreign_key, + ], + 'list_types': { + 'functionalcis_list': 'functionalci_id_finalclass_recall', + 'contacts_list': 'contact_id_finalclass_recall' + }, + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of PhysicalInterface with the given key or criteria """ + return ItopapiPrototype.find(ItopapiIncident, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiIncident, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of Person """ + return ItopapiPrototype.find_all(ItopapiIncident) + + """ + ItopapiPerson is an object that represents a Person from iTop + """ + def __init__(self, data=None): + super(ItopapiIncident, self).__init__(data) + self.title = None + self.friendlyname = None + self.description = None + self.ref = None + self.start_date = None + self.end_date = None + self.close_date = None + self.last_update = None + + ################################## + # Lists # + ################################## + self.functionalcis_list = None + self.contacts_list = None + self.workers_list = None + self.private_log = None diff --git a/itopapi/model/iosVersion.py b/itopapi/model/iosVersion.py new file mode 100644 index 0000000..5693307 --- /dev/null +++ b/itopapi/model/iosVersion.py @@ -0,0 +1,50 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiIOSVersion is an abstraction of IOSVersion representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.typology import ItopapiTypology +from itopapi.model.features.hasBrand import HasBrand + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiIOSVersion(ItopapiTypology, HasBrand): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'IOSVersion', + # Define which fields to save when creating or updating from the python API + 'save': ['name'], + 'foreign_keys': [ + HasBrand.foreign_key, + ] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of IOSVersion with the given key or criteria """ + return ItopapiPrototype.find(ItopapiIOSVersion, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiIOSVersion, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of IOSVersion """ + return ItopapiPrototype.find_all(ItopapiIOSVersion) + + """ + ItopapiIOSVersion is an object that represents an IOSVersion from iTop + """ + def __init__(self, data=None): + super(ItopapiIOSVersion, self).__init__(data) + + +# Register as a subclass of Typology +ItopapiTypology.register(ItopapiIOSVersion) diff --git a/itopapi/model/ipInterface.py b/itopapi/model/ipInterface.py new file mode 100644 index 0000000..dbdeb6c --- /dev/null +++ b/itopapi/model/ipInterface.py @@ -0,0 +1,47 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiIPInterface is an abstraction of IPInterface representation on iTop +""" + +from abc import ABCMeta +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.networkInterface import ItopapiNetworkInterface + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiIPInterface(ItopapiNetworkInterface): + __metaclass__ = ABCMeta + + # Configuration specific to itop + itop = { + 'name': 'IPInterface', + 'save': [], + 'foreign_keys': [] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of IPInterface with the given key or criteria """ + return ItopapiPrototype.find(ItopapiIPInterface, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiIPInterface, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of IPInterface """ + return ItopapiPrototype.find_all(ItopapiIPInterface) + + """ + ItopapiIPInterface is an object that represents a IPInterface from iTop + """ + def __init__(self, data=None): + super(ItopapiIPInterface, self).__init__(data) + + +# Register as a subclass of NetworkInterface +ItopapiNetworkInterface.register(ItopapiIPInterface) diff --git a/itopapi/model/licence.py b/itopapi/model/licence.py new file mode 100644 index 0000000..a9c0949 --- /dev/null +++ b/itopapi/model/licence.py @@ -0,0 +1,42 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiLicence is an abstraction of Licence representation on iTop +""" + +from abc import ABCMeta +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiLicence(ItopapiPrototype): + __metaclass__ = ABCMeta + + # Configuration specific to itop + itop = { + 'name': 'Licence', + 'save': [], + 'foreign_keys': [] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of Licence with the given key or criteria """ + return ItopapiPrototype.find(ItopapiLicence, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiLicence, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of Licence """ + return ItopapiPrototype.find_all(ItopapiLicence) + + """ + ItopapiLicence is an object that represents a Licence from iTop + """ + def __init__(self, data=None): + super(ItopapiLicence, self).__init__(data) diff --git a/itopapi/model/location.py b/itopapi/model/location.py new file mode 100644 index 0000000..3d420f2 --- /dev/null +++ b/itopapi/model/location.py @@ -0,0 +1,55 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiLocation is an abstraction of a Location representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.features.hasOrganization import HasOrganization + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiLocation(ItopapiPrototype, HasOrganization): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'Location', + # Define which fields to save when creating or updating from the python API + 'save': ['name', 'status', 'address', 'postal_code', 'city', 'country'], + 'foreign_keys': [ + HasOrganization.foreign_key, + ], + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of OSFamily with the given key or criteria """ + return ItopapiPrototype.find(ItopapiLocation, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiLocation, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of OSFamily """ + return ItopapiPrototype.find_all(ItopapiLocation) + + """ + ItopapiLocation is an object that represents an OS Family from iTop + """ + def __init__(self, data=None): + super(ItopapiLocation, self).__init__(data) + # Location's status. Values within [inactive, active] + self.status = None + # Location's street address. Generally multiline + self.address = None + self.postal_code = None + self.city = None + self.country = None + # Lists + self.person_list = {} + self.physicaldevice_list = {} diff --git a/itopapi/model/logicalInterface.py b/itopapi/model/logicalInterface.py new file mode 100644 index 0000000..aa527c1 --- /dev/null +++ b/itopapi/model/logicalInterface.py @@ -0,0 +1,62 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiLogicalInterface is an abstraction of LogicalInterface representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.ipInterface import ItopapiIPInterface +from itopapi.model.features.hasVirtualMachine import HasVirtualMachine + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiLogicalInterface(ItopapiIPInterface, HasVirtualMachine): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'LogicalInterface', + # Define which fields to save when creating or updating from the python API + 'save': ['name', 'ipaddress', 'macaddress', 'comment', 'ipgateway', 'ipmask', 'speed'], + 'foreign_keys': [ + HasVirtualMachine.foreign_key, + ], + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of LogicalInterface with the given key or criteria """ + return ItopapiPrototype.find(ItopapiLogicalInterface, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiLogicalInterface, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of LogicalInterface """ + return ItopapiPrototype.find_all(ItopapiLogicalInterface) + + """ + ItopapiLogicalInterface is an object that represents a LogicalInterface from iTop + """ + def __init__(self, data=None): + super(ItopapiLogicalInterface, self).__init__(data) + # IP address of the LogicalInterface + self.ipaddress = None + # MAC address of the LogicalInterface + self.macaddress = None + # Any kind of comment + self.comment = None + # IP gateway of the LogicalInterface + self.ipgateway = None + # IP mask of the LogicalInterface + self.ipmask = None + # speed of the LogicalInterface + self.speed = None + + +# Register as a subclass of IPInterface +ItopapiIPInterface.register(ItopapiLogicalInterface) diff --git a/itopapi/model/middleware.py b/itopapi/model/middleware.py new file mode 100644 index 0000000..e428add --- /dev/null +++ b/itopapi/model/middleware.py @@ -0,0 +1,86 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +ItopapiMiddleware is an abstraction of Middleware representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.softwareInstance import ItopapiSoftwareInstance +from itopapi.model.features.hasOrganization import HasOrganization +from itopapi.model.features.hasSoftwareLicence import HasSoftwareLicence +from itopapi.model.features.hasSoftware import HasSoftware +from itopapi.model.features.hasSystem import HasSystem + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiMiddleware(ItopapiSoftwareInstance, HasOrganization, HasSoftwareLicence, HasSoftware, HasSystem): + """ + ItopapiMiddleware is an object that represents a Middleware from iTop + """ + + """ Configuration specific to itop """ + itop = { + # Name of the class in Itop + 'name': 'Middleware', + # Define which fields to save when creating or updating from the python API + 'save': ['move2production', 'description', 'status', 'name', 'business_criticity', 'path'], + 'foreign_keys': [ + HasOrganization.foreign_key, + HasSoftware.foreign_key, + HasSoftwareLicence.foreign_key, + HasSystem.foreign_key, + ], + 'list_types': { + 'contacts_list': 'contact_id_finalclass_recall' + }, + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of Middleware with the given key or criteria """ + return ItopapiPrototype.find(ItopapiMiddleware, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiMiddleware, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of Rack """ + return ItopapiPrototype.find_all(ItopapiMiddleware) + + def __init__(self, data=None): + super(ItopapiMiddleware, self).__init__(data) + + ################################## + # Properties # + ################################## + # Middleware's status. Values within [implementation, obsolete, production, stock] + self.status = None + # Middleware's business criticity. Values within [high, medium, low] + self.business_criticity = None + # Middleware's path ? + self.path = None + # Middleware's description, as a free text + self.description = None + # Middleware's move to production date + self.move2production = None + + ################################## + # Lists # + ################################## + self.documents_list = {} + self.softwares_list = {} + self.tickets_list = {} + self.services_list = {} + self.contacts_list = {} + self.providercontracts_list = {} + self.applicationsolution_list = {} + self.middlewareinstance_list = {} + + +# Register as a subclass of SoftwareInstance +ItopapiSoftwareInstance.register(ItopapiMiddleware) + diff --git a/itopapi/model/middlewareInstance.py b/itopapi/model/middlewareInstance.py new file mode 100644 index 0000000..a48b9af --- /dev/null +++ b/itopapi/model/middlewareInstance.py @@ -0,0 +1,76 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=invalid-name +""" +ItopapiMiddlewareInstance is an abstraction of Middleware Instance representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.functionalCI import ItopapiFunctionalCI +from itopapi.model.features.hasOrganization import HasOrganization +from itopapi.model.features.hasMiddleware import HasMiddleware + + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiMiddlewareInstance(ItopapiFunctionalCI, HasOrganization, HasMiddleware): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'MiddlewareInstance', + # Define which fields to save when creating or updating from the python API + 'save': ['name', 'business_criticity', 'move2production', 'description'], + 'foreign_keys': [ + HasOrganization.foreign_key, + HasMiddleware.foreign_key, + ], + 'list_types': { + 'contacts_list': 'contact_id_finalclass_recall' + }, + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of MiddlewareInstance with the given key or criteria """ + return ItopapiPrototype.find(ItopapiMiddlewareInstance, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiMiddlewareInstance, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of MiddlewareInstance """ + return ItopapiPrototype.find_all(ItopapiMiddlewareInstance) + + """ + ItopapiMiddlewareInstance is an object that represents an Middleware Instance from iTop + """ + def __init__(self, data=None): + super(ItopapiMiddlewareInstance, self).__init__(data) + ################################## + # Properties # + ################################## + # Middleware Instance's business criticity. Values within [high, medium, low] + self.business_criticity = None + # Middleware Instance's move to production date + self.move2production = None + # Middleware Instance's description, as a free text + self.description = None + ################################## + # Lists # + ################################## + # One with an s, one without. Because why not? + self.applicationsolution_list = None + self.documents_list = None + self.softwares_list = None + self.tickets_list = None + self.services_list = None + self.contacts_list = None + self.providercontracts_list = None + + +# Register as a subclass of FunctionalCI +ItopapiFunctionalCI.register(ItopapiMiddlewareInstance) diff --git a/itopapi/model/model.py b/itopapi/model/model.py new file mode 100644 index 0000000..220c601 --- /dev/null +++ b/itopapi/model/model.py @@ -0,0 +1,56 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiModel is an abstraction of Model representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.typology import ItopapiTypology +from itopapi.model.features.hasBrand import HasBrand + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiModel(ItopapiTypology, HasBrand): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'Model', + # Define which fields to save when creating or updating from the python API + 'save': ['name', 'type'], + 'foreign_keys': [ + HasBrand.foreign_key, + ] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of Model with the given key or criteria """ + return ItopapiPrototype.find(ItopapiModel, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiModel, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of Model """ + return ItopapiPrototype.find_all(ItopapiModel) + + """ + ItopapiModel is an object that represents a Model from iTop + """ + def __init__(self, data=None): + super(ItopapiModel, self).__init__(data) + # Physical devices using this brand + self.physicaldevices_list = None + # Type of item the Model refers to. Values are within + # [DiskArray, Enclosure, IPPhone, MobilePhone, NAS, NetworkDevice, PC, PDU, Peripheral, Phone, + # PowerSource, Printer, Rack, SANSwitch, Server, StorageSystem, Tablet, TapeLibrary] + self.type = None + + +# Register as a subclass of Typology +ItopapiTypology.register(ItopapiModel) diff --git a/itopapi/model/nas.py b/itopapi/model/nas.py new file mode 100644 index 0000000..8cb8c00 --- /dev/null +++ b/itopapi/model/nas.py @@ -0,0 +1,117 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes,invalid-name, too-many-statements +""" +ItopapiNAS is an abstraction of NAS representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.datacenterDevice import ItopapiDatacenterDevice +from itopapi.model.features.hasOrganization import HasOrganization +from itopapi.model.features.hasLocation import HasLocation +from itopapi.model.features.hasBrand import HasBrand +from itopapi.model.features.hasModel import HasModel +from itopapi.model.features.hasRack import HasRack +from itopapi.model.features.hasEnclosure import HasEnclosure +from itopapi.model.features.hasPowerA import HasPowerA +from itopapi.model.features.hasPowerB import HasPowerB + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiNAS(ItopapiDatacenterDevice, HasOrganization, HasLocation, HasBrand, HasModel, + HasRack, HasEnclosure, HasPowerA, HasPowerB): + """ + ItopapiNAS is an object that represents a NAS from iTop + """ + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'NAS', + # Define which fields to save when creating or updating from the python API + 'save': ['name', 'status', 'business_criticity', 'managementip', + 'nb_u', 'serialnumber', 'asset_number', 'move2production', + 'purchase_date', 'end_of_warranty', 'description'], + 'foreign_keys': [ + HasOrganization.foreign_key, + HasLocation.foreign_key, + HasBrand.foreign_key, + HasModel.foreign_key, + HasRack.foreign_key, + HasEnclosure.foreign_key, + HasPowerA.foreign_key, + HasPowerB.foreign_key, + ], + 'list_types': { + 'contacts_list': 'Person', + }, + } + + @staticmethod + def find(key): + """ Retrieve one or mor instance of NAS with the given key or criteria """ + return ItopapiPrototype.find(ItopapiNAS, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiNAS, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of NAS """ + return ItopapiPrototype.find_all(ItopapiNAS) + + def __init__(self, data=None): + super(ItopapiNAS, self).__init__(data) + + # NAS's status. Values within [implementation, obsolete, production, stock] + self.status = None + # NAS's business criticity. Values within [high, medium, low] + self.business_criticity = None + self.managementip = None + # Rack units + self.nb_u = None + # NAS's serial number + self.serialnumber = None + # NAS's asset number + self.asset_number = None + # NAS's move to production date + self.move2production = None + # NAS's purchase date + self.purchase_date = None + # NAS's end of warranty date + self.end_of_warranty = None + # NAS's description, as a free text + self.description = None + + ############################## + # Lists # + ############################## + # NAS's softwares list + self.softwares_list = {} + # NAS's contacts list + self.contacts_list = {} + # NAS's documents list + self.documents_list = {} + # NAS's tickets list + self.tickets_list = {} + # NAS's application solutions list + self.applicationsolution_list = {} + # NAS's network interfaces list + self.physicalinterface_list = {} + # NAS's FC ports list + self.fiberinterfacelist_list = {} + # NAS's network devices list + self.networkdevice_list = {} + # NAS's SANs list + self.san_list = {} + # NAS's provider contracts list + self.providercontracts_list = {} + # NAS's services list + self.services_list = {} + # NASFileSystem's list + self.nasfilesystem_list = {} + +# Register as a subclass of Datacenter Device +ItopapiDatacenterDevice.register(ItopapiNAS) \ No newline at end of file diff --git a/itopapi/model/networkDevice.py b/itopapi/model/networkDevice.py new file mode 100644 index 0000000..a68a1bb --- /dev/null +++ b/itopapi/model/networkDevice.py @@ -0,0 +1,123 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes,invalid-name, too-many-statements +""" +ItopapiNetworkDevice is an abstraction of NetworkDevice representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.datacenterDevice import ItopapiDatacenterDevice +from itopapi.model.features.hasOrganization import HasOrganization +from itopapi.model.features.hasLocation import HasLocation +from itopapi.model.features.hasBrand import HasBrand +from itopapi.model.features.hasModel import HasModel +from itopapi.model.features.hasRack import HasRack +from itopapi.model.features.hasEnclosure import HasEnclosure +from itopapi.model.features.hasNetworkDeviceType import HasNetworkDeviceType +from itopapi.model.features.hasIOSVersion import HasIOSVersion +from itopapi.model.features.hasPowerA import HasPowerA +from itopapi.model.features.hasPowerB import HasPowerB + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiNetworkDevice(ItopapiDatacenterDevice, HasOrganization, HasLocation, HasBrand, HasModel, + HasRack, HasEnclosure, HasNetworkDeviceType, HasIOSVersion, HasPowerA, HasPowerB): + """ + ItopapiNetworkDevice is an object that represents a NetworkDevice from iTop + """ + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'NetworkDevice', + # Define which fields to save when creating or updating from the python API + 'save': ['name', 'status', 'business_criticity', 'managementip', + 'nb_u', 'serialnumber', 'asset_number', 'move2production', + 'purchase_date', 'end_of_warranty', 'description', 'ram'], + 'foreign_keys': [ + HasOrganization.foreign_key, + HasLocation.foreign_key, + HasBrand.foreign_key, + HasModel.foreign_key, + HasRack.foreign_key, + HasNetworkDeviceType.foreign_key, + HasEnclosure.foreign_key, + HasIOSVersion.foreign_key, + HasPowerA.foreign_key, + HasPowerB.foreign_key, + ], + 'list_types': { + 'contacts_list': 'Person', + }, + } + + @staticmethod + def find(key): + """ Retrieve one or mor instance of NetworkDevice with the given key or criteria """ + return ItopapiPrototype.find(ItopapiNetworkDevice, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiNetworkDevice, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of NetworkDevice """ + return ItopapiPrototype.find_all(ItopapiNetworkDevice) + + def __init__(self, data=None): + super(ItopapiNetworkDevice, self).__init__(data) + + # NetworkDevice's status. Values within [implementation, obsolete, production, stock] + self.status = None + # NetworkDevice's business criticity. Values within [high, medium, low] + self.business_criticity = None + self.managementip = None + # Rack units + self.nb_u = None + # NetworkDevice's serial number + self.serialnumber = None + # NetworkDevice's asset number + self.asset_number = None + # NetworkDevice's move to production date + self.move2production = None + # NetworkDevice's purchase date + self.purchase_date = None + # NetworkDevice's end of warranty date + self.end_of_warranty = None + # NetworkDevice's description, as a free text + self.description = None + # Amount of RAM in the device + self.ram = None + + ############################## + # Lists # + ############################## + # NetworkDevice's softwares list + self.softwares_list = {} + # NetworkDevice's contacts list + self.contacts_list = {} + # NetworkDevice's documents list + self.documents_list = {} + # NetworkDevice's tickets list + self.tickets_list = {} + # NetworkDevice's application solutions list + self.applicationsolution_list = {} + # NetworkDevice's network interfaces list + self.physicalinterface_list = {} + # NetworkDevice's FC ports list + self.fiberinterfacelist_list = {} + # NetworkDevice's network devices list + self.networkdevice_list = {} + # NetworkDevice's SANs list + self.san_list = {} + # NetworkDevice's provider contracts list + self.providercontracts_list = {} + # NetworkDevice's services list + self.services_list = {} + # ConnectableCI's list + self.connectablecis_list = {} + +# Register as a subclass of Datacenter Device +ItopapiDatacenterDevice.register(ItopapiNetworkDevice) \ No newline at end of file diff --git a/itopapi/model/networkDeviceType.py b/itopapi/model/networkDeviceType.py new file mode 100644 index 0000000..3cfbae0 --- /dev/null +++ b/itopapi/model/networkDeviceType.py @@ -0,0 +1,50 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiNetworkDeviceType is an abstraction of NetworkDeviceType representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.typology import ItopapiTypology + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiNetworkDeviceType(ItopapiTypology): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'NetworkDeviceType', + # Define which fields to save when creating or updating from the python API + 'save': ['name'], + 'foreign_keys': [] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of NetworkDeviceType with the given key or criteria """ + return ItopapiPrototype.find(ItopapiNetworkDeviceType, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiNetworkDeviceType, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of NetworkDeviceType """ + return ItopapiPrototype.find_all(ItopapiNetworkDeviceType) + + """ + ItopapiNetworkDeviceType is an object that represents an NetworkDeviceType from iTop + """ + def __init__(self, data=None): + super(ItopapiNetworkDeviceType, self).__init__(data) + + # list of NetworkDevice(s) using this type. + self.networkdevicesdevices = {} + + +# Register as a subclass of Typology +ItopapiTypology.register(ItopapiNetworkDeviceType) diff --git a/itopapi/model/networkInterface.py b/itopapi/model/networkInterface.py new file mode 100644 index 0000000..788f1c0 --- /dev/null +++ b/itopapi/model/networkInterface.py @@ -0,0 +1,42 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiNetworkInterface is an abstraction of NetworkInterface representation on iTop +""" + +from abc import ABCMeta +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiNetworkInterface(ItopapiPrototype): + __metaclass__ = ABCMeta + + # Configuration specific to itop + itop = { + 'name': 'NetworkInterface', + 'save': [], + 'foreign_keys': [] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of NetworkInterface with the given key or criteria """ + return ItopapiPrototype.find(ItopapiNetworkInterface, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiNetworkInterface, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of NetworkInterface """ + return ItopapiPrototype.find_all(ItopapiNetworkInterface) + + """ + ItopapiNetworkInterface is an object that represents a NetworkInterface from iTop + """ + def __init__(self, data=None): + super(ItopapiNetworkInterface, self).__init__(data) diff --git a/itopapi/model/organization.py b/itopapi/model/organization.py new file mode 100644 index 0000000..9b8fb51 --- /dev/null +++ b/itopapi/model/organization.py @@ -0,0 +1,52 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=invalid-name +""" +ItopapiOrganization is an abstraction of Organization representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.deliveryModel import ItopapiDeliveryModel +from itopapi.model.features.hasParentOrganization import HasParentOrganization +from itopapi.model.features.hasDeliveryModel import HasDeliveryModel + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiOrganization(ItopapiPrototype, HasParentOrganization, HasDeliveryModel): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'Organization', + # Define which fields to save when creating or updating from the python API + 'save': ['name', 'code', 'status'], + 'foreign_keys': [ + HasParentOrganization.foreign_key, + HasDeliveryModel.foreign_key, + ] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of ApplicationSolution with the given key or criteria """ + return ItopapiPrototype.find(ItopapiOrganization, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiOrganization, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of OSFamily """ + return ItopapiPrototype.find_all(ItopapiOrganization) + + """ + ItopapiOrganization is an object that represents an Application Solution from iTop + """ + def __init__(self, data=None): + super(ItopapiOrganization, self).__init__(data) + + self.code = None + # Application Solution's status. Values within [inactive, active] + self.status = None diff --git a/itopapi/model/os.py b/itopapi/model/osFamily.py similarity index 71% rename from itopapi/model/os.py rename to itopapi/model/osFamily.py index 89c7004..ae628c2 100644 --- a/itopapi/model/os.py +++ b/itopapi/model/osFamily.py @@ -1,16 +1,17 @@ # -*- coding: utf8 -*-fr """ -ItopapiOSFamily is a abstraction of Rack representation on iTop +ItopapiOSFamily is an abstraction of OSFamily representation on iTop """ from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.typology import ItopapiTypology __version__ = '1.0' -__authors__ = ['Guillaume Philippon '] +__authors__ = ['Julien Nauroy '] -class ItopapiOSFamily(ItopapiPrototype): +class ItopapiOSFamily(ItopapiTypology): # Configuration specific to itop itop = { @@ -36,7 +37,11 @@ def find_all(): return ItopapiPrototype.find_all(ItopapiOSFamily) """ - ItopapiOSFamily is an object that represent an OS Family from iTop + ItopapiOSFamily is an object that represents an OS Family from iTop """ def __init__(self, data=None): super(ItopapiOSFamily, self).__init__(data) + + +# Register as a subclass of Typology +ItopapiTypology.register(ItopapiOSFamily) diff --git a/itopapi/model/osLicence.py b/itopapi/model/osLicence.py new file mode 100644 index 0000000..9e36265 --- /dev/null +++ b/itopapi/model/osLicence.py @@ -0,0 +1,64 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiOSLicence is an abstraction of OSLicence representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.licence import ItopapiLicence +from itopapi.model.features.hasOrganization import HasOrganization +from itopapi.model.features.hasOSVersion import HasOSVersion + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiOSLicence(ItopapiLicence, HasOrganization, HasOSVersion): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'OSLicence', + # Define which fields to save when creating or updating from the python API + 'save': ['name', 'usage_limit', 'description', 'perpetual', 'start_date', 'end_date', 'licence_key'], + 'foreign_keys': [ + HasOrganization.foreign_key, + HasOSVersion.foreign_key, + ], + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of OSLicence with the given key or criteria """ + return ItopapiPrototype.find(ItopapiOSLicence, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiOSLicence, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of OSLicence """ + return ItopapiPrototype.find_all(ItopapiOSLicence) + + """ + ItopapiOSLicence is an object that represents an OSLicence (sic) from iTop + """ + def __init__(self, data=None): + super(ItopapiOSLicence, self).__init__(data) + # Number of concurrent users or licences + self.usage_limit = None + self.description = None + # Possible values are ['yes', 'no'] + self.perpetual = 'no' + self.start_date = None + self.end_date = None + self.licence_key = None + # Lists + self.documents_list = [] + self.servers_list = [] + self.virtualmachines_list = [] + + +# Register as a subclass of FunctionalCI +ItopapiLicence.register(ItopapiOSLicence) diff --git a/itopapi/model/osPatch.py b/itopapi/model/osPatch.py new file mode 100644 index 0000000..573b825 --- /dev/null +++ b/itopapi/model/osPatch.py @@ -0,0 +1,50 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=invalid-name +""" +ItopapiOSPatch is an abstraction of OSPatch representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.features.hasOSVersion import HasOSVersion + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiOSPatch(ItopapiPrototype, HasOSVersion): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'OSPatch', + # Define which fields to save when creating or updating from the python API + 'save': ['name', 'description', 'size'], + 'foreign_keys': [ + HasOSVersion.foreign_key, + ] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of ApplicationSolution with the given key or criteria """ + return ItopapiPrototype.find(ItopapiOSPatch, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiOSPatch, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of OSFamily """ + return ItopapiPrototype.find_all(ItopapiOSPatch) + + """ + ItopapiOSPatch is an object that represents an Application Solution from iTop + """ + def __init__(self, data=None): + super(ItopapiOSPatch, self).__init__(data) + + self.description = None + # Lists + self.documents_list = {} + self.functionalcis_list = {} diff --git a/itopapi/model/osVersion.py b/itopapi/model/osVersion.py new file mode 100644 index 0000000..0e98dce --- /dev/null +++ b/itopapi/model/osVersion.py @@ -0,0 +1,50 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiOSVersion is an abstraction of an OSVersion representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.typology import ItopapiTypology +from itopapi.model.features.hasOSFamily import HasOSFamily + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiOSVersion(ItopapiTypology, HasOSFamily): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'OSVersion', + # Define which fields to save when creating or updating from the python API + 'save': ['name'], + 'foreign_keys': [ + HasOSFamily.foreign_key, + ] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of OSVersion with the given key or criteria """ + return ItopapiPrototype.find(ItopapiOSVersion, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiOSVersion, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of OSVersion """ + return ItopapiPrototype.find_all(ItopapiOSVersion) + + """ + ItopapiOSVersion is an object that represents an OS Version from iTop + """ + def __init__(self, data=None): + super(ItopapiOSVersion, self).__init__(data) + + +# Register as a subclass of Typology +ItopapiTypology.register(ItopapiOSVersion) diff --git a/itopapi/model/otherSoftware.py b/itopapi/model/otherSoftware.py new file mode 100644 index 0000000..8085b3f --- /dev/null +++ b/itopapi/model/otherSoftware.py @@ -0,0 +1,85 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +ItopapiOtherSoftware is an abstraction of OtherSoftware representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.softwareInstance import ItopapiSoftwareInstance +from itopapi.model.features.hasOrganization import HasOrganization +from itopapi.model.features.hasSoftwareLicence import HasSoftwareLicence +from itopapi.model.features.hasSoftware import HasSoftware +from itopapi.model.features.hasSystem import HasSystem + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiOtherSoftware(ItopapiSoftwareInstance, HasOrganization, HasSoftwareLicence, HasSoftware, HasSystem): + """ + ItopapiOtherSoftware is an object that represents a OtherSoftware from iTop + """ + + """ Configuration specific to itop """ + itop = { + # Name of the class in Itop + 'name': 'OtherSoftware', + # Define which fields to save when creating or updating from the python API + 'save': ['move2production', 'description', 'status', 'name', 'business_criticity', 'path'], + 'foreign_keys': [ + HasOrganization.foreign_key, + HasSoftware.foreign_key, + HasSoftwareLicence.foreign_key, + HasSystem.foreign_key, + ], + 'list_types': { + 'contacts_list': 'contact_id_finalclass_recall' + }, + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of OtherSoftware with the given key or criteria """ + return ItopapiPrototype.find(ItopapiOtherSoftware, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiOtherSoftware, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of Rack """ + return ItopapiPrototype.find_all(ItopapiOtherSoftware) + + def __init__(self, data=None): + super(ItopapiOtherSoftware, self).__init__(data) + + ################################## + # Properties # + ################################## + # OtherSoftware's status. Values within [implementation, obsolete, production, stock] + self.status = None + # OtherSoftware's business criticity. Values within [high, medium, low] + self.business_criticity = None + # OtherSoftware's path ? + self.path = None + # OtherSoftware's description, as a free text + self.description = None + # OtherSoftware's move to production date + self.move2production = None + + ################################## + # Lists # + ################################## + self.documents_list = {} + self.softwares_list = {} + self.tickets_list = {} + self.services_list = {} + self.contacts_list = {} + self.providercontracts_list = {} + self.applicationsolution_list = {} + + +# Register as a subclass of SoftwareInstance +ItopapiSoftwareInstance.register(ItopapiOtherSoftware) + diff --git a/itopapi/model/patch.py b/itopapi/model/patch.py new file mode 100644 index 0000000..4010ade --- /dev/null +++ b/itopapi/model/patch.py @@ -0,0 +1,42 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiPatch is an abstraction of Patch representation on iTop +""" + +from abc import ABCMeta +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiPatch(ItopapiPrototype): + __metaclass__ = ABCMeta + + # Configuration specific to itop + itop = { + 'name': 'Patch', + 'save': [], + 'foreign_keys': [] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of Patch with the given key or criteria """ + return ItopapiPrototype.find(ItopapiPatch, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiPatch, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of Patch """ + return ItopapiPrototype.find_all(ItopapiPatch) + + """ + ItopapiPatch is an object that represents a Patch from iTop + """ + def __init__(self, data=None): + super(ItopapiPatch, self).__init__(data) diff --git a/itopapi/model/pcSoftware.py b/itopapi/model/pcSoftware.py new file mode 100644 index 0000000..2819c76 --- /dev/null +++ b/itopapi/model/pcSoftware.py @@ -0,0 +1,83 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +ItopapiPCSoftware is an abstraction of PCSoftware representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.softwareInstance import ItopapiSoftwareInstance +from itopapi.model.features.hasOrganization import HasOrganization +from itopapi.model.features.hasSoftwareLicence import HasSoftwareLicence +from itopapi.model.features.hasSoftware import HasSoftware + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiPCSoftware(ItopapiSoftwareInstance, HasOrganization, HasSoftwareLicence, HasSoftware): + """ + ItopapiPCSoftware is an object that represents a PCSoftware from iTop + """ + + """ Configuration specific to itop """ + itop = { + # Name of the class in Itop + 'name': 'PCSoftware', + # Define which fields to save when creating or updating from the python API + 'save': ['move2production', 'description', 'status', 'name', 'business_criticity', 'path'], + 'foreign_keys': [ + HasOrganization.foreign_key, + HasSoftware.foreign_key, + HasSoftwareLicence.foreign_key, + ], + 'list_types': { + 'contacts_list': 'contact_id_finalclass_recall' + }, + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of PCSoftware with the given key or criteria """ + return ItopapiPrototype.find(ItopapiPCSoftware, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiPCSoftware, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of Rack """ + return ItopapiPrototype.find_all(ItopapiPCSoftware) + + def __init__(self, data=None): + super(ItopapiPCSoftware, self).__init__(data) + + ################################## + # Properties # + ################################## + # PCSoftware's status. Values within [implementation, obsolete, production, stock] + self.status = None + # PCSoftware's business criticity. Values within [high, medium, low] + self.business_criticity = None + # PCSoftware's path ? + self.path = None + # PCSoftware's description, as a free text + self.description = None + # PCSoftware's move to production date + self.move2production = None + + ################################## + # Lists # + ################################## + self.documents_list = {} + self.softwares_list = {} + self.tickets_list = {} + self.services_list = {} + self.contacts_list = {} + self.providercontracts_list = {} + self.applicationsolution_list = {} + + +# Register as a subclass of SoftwareInstance +ItopapiSoftwareInstance.register(ItopapiPCSoftware) + diff --git a/itopapi/model/pdu.py b/itopapi/model/pdu.py new file mode 100644 index 0000000..601a410 --- /dev/null +++ b/itopapi/model/pdu.py @@ -0,0 +1,83 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiPDU is an abstraction of PDU representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.powerConnection import ItopapiPowerConnection +from itopapi.model.features.hasOrganization import HasOrganization +from itopapi.model.features.hasLocation import HasLocation +from itopapi.model.features.hasBrand import HasBrand +from itopapi.model.features.hasModel import HasModel +from itopapi.model.features.hasRack import HasRack +from itopapi.model.features.hasPowerStart import HasPowerStart + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiPDU(ItopapiPowerConnection, HasOrganization, HasLocation, HasBrand, HasModel, HasRack, HasPowerStart): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'PDU', + # Define which fields to save when creating or updating from the python API + 'save': ['name', 'status', 'business_criticity', 'serialnumber', 'asset_number', + 'move2production', 'purchase_date', 'end_of_warranty', 'description'], + 'foreign_keys': [ + HasOrganization.foreign_key, + HasLocation.foreign_key, + HasBrand.foreign_key, + HasModel.foreign_key, + HasPowerStart.foreign_key, + ] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of PDU with the given key or criteria """ + return ItopapiPrototype.find(ItopapiPDU, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiPDU, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of PDU """ + return ItopapiPrototype.find_all(ItopapiPDU) + + """ + ItopapiPDU is an object that represents a PDU from iTop + """ + def __init__(self, data=None): + super(ItopapiPDU, self).__init__(data) + + # PDU's status. Values within [implementation, obsolete, production, stock] + self.status = None + # PDU's business criticity. Values within [high, medium, low] + self.business_criticity = None + # Serial number + self.serialnumber = None + # Asset number + self.asset_number = None + # Server's move to production date + self.move2production = None + # Server's purchase date + self.purchase_date = None + # Server's end of warranty date + self.end_of_warranty = None + self.description = None + ################################## + # Lists # + ################################## + self.documents_list = {} + self.softwares_list = {} + self.services_list = {} + self.applicationsolution_list = {} + self.contacts_list = {} + self.tickets_list = {} + self.providercontracts_list = {} + self.pdus_list = {} diff --git a/itopapi/model/person.py b/itopapi/model/person.py new file mode 100644 index 0000000..c2da9d0 --- /dev/null +++ b/itopapi/model/person.py @@ -0,0 +1,77 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiPerson is an abstraction of a Person representation on iTop +It inherits from ItopapiContact +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.contact import ItopapiContact +from itopapi.model.features.hasOrganization import HasOrganization +from itopapi.model.features.hasLocation import HasLocation +from itopapi.model.features.hasManager import HasManager + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiPerson(ItopapiContact, HasOrganization, HasLocation, HasManager): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'Person', + # Define which fields to save when creating or updating from the python API + 'save': ['name', 'contact_id', 'contact_name', 'function', 'first_name', + 'email', 'mobile_phone', 'phone', 'notify', 'employee_number', 'status'], + 'foreign_keys': [ + HasOrganization.foreign_key, + HasLocation.foreign_key, + HasManager.foreign_key, + ], + 'list_types': { + 'team_list': 'Team', + 'cis_list': 'functionalci_id_finalclass_recall' + }, + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of PhysicalInterface with the given key or criteria """ + return ItopapiPrototype.find(ItopapiPerson, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiPerson, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of Person """ + return ItopapiPrototype.find_all(ItopapiPerson) + + """ + ItopapiPerson is an object that represents a Person from iTop + """ + def __init__(self, data=None): + super(ItopapiPerson, self).__init__(data) + + ################################## + # Properties # + ################################## + self.first_name = None + self.function = None + self.email = None + self.mobile_phone = None + self.phone = None + self.notify = None + self.employee_number = None + self.status = None + ################################## + # Lists # + ################################## + self.tickets_list = None + self.cis_list = None + self.team_list = None + +# Register as a subclass of Contact +ItopapiContact.register(ItopapiPerson) diff --git a/itopapi/model/physicalDevice.py b/itopapi/model/physicalDevice.py new file mode 100644 index 0000000..7e06ce8 --- /dev/null +++ b/itopapi/model/physicalDevice.py @@ -0,0 +1,47 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiPhysicalDevice is an abstraction of Physical Device representation on iTop +It serves as a base class for Racks Servers and much more. +""" + +from abc import ABCMeta +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.functionalCI import ItopapiFunctionalCI + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiPhysicalDevice(ItopapiFunctionalCI): + __metaclass__ = ABCMeta + + # Configuration specific to itop + itop = { + 'name': 'PhysicalDevice', + 'save': [], + 'foreign_keys': [] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of Physical Device with the given key or criteria """ + return ItopapiPrototype.find(ItopapiPhysicalDevice, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiPhysicalDevice, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of Physical Device """ + return ItopapiPrototype.find_all(ItopapiPhysicalDevice) + + """ + ItopapiPhysicalDevice is an object that represents a Physical Device from iTop + """ + def __init__(self, data=None): + super(ItopapiPhysicalDevice, self).__init__(data) + +# Register as a subclass of FunctionalCI +ItopapiFunctionalCI.register(ItopapiPhysicalDevice) diff --git a/itopapi/model/physicalInterface.py b/itopapi/model/physicalInterface.py index 6115ba4..4b403b3 100644 --- a/itopapi/model/physicalInterface.py +++ b/itopapi/model/physicalInterface.py @@ -1,16 +1,18 @@ # -*- coding: utf8 -*-fr """ -ItopapiPhysicalInterface is a abstraction of PhysicalInterface representation on iTop +ItopapiPhysicalInterface is an abstraction of PhysicalInterface representation on iTop """ from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.ipInterface import ItopapiIPInterface +from itopapi.model.features.hasConnectableCI import HasConnectableCI __version__ = '1.0' __authors__ = ['Julien Nauroy '] -class ItopapiPhysicalInterface(ItopapiPrototype): +class ItopapiPhysicalInterface(ItopapiIPInterface, HasConnectableCI): # Configuration specific to itop itop = { @@ -19,11 +21,7 @@ class ItopapiPhysicalInterface(ItopapiPrototype): # Define which fields to save when creating or updating from the python API 'save': ['name', 'ipaddress', 'macaddress', 'comment', 'ipgateway', 'ipmask', 'speed'], 'foreign_keys': [ - # TODO the table is not necessarily a server, it is defined by connectableci_id_finalclass_recall - {'id': 'connectableci_id', 'name': 'connectableci_name', 'table': 'Server'}, - # TODO good for fetching, but not for saving since there is no "name" and "finalclass" in this list! - # Find a solution - # {'id': 'vlan_id', 'name': 'vlan_tag', 'table': 'VLAN'}, + HasConnectableCI.foreign_key, ], 'list_types': {'vlans_list': 'VLAN'}, } @@ -43,15 +41,10 @@ def find_all(): return ItopapiPrototype.find_all(ItopapiPhysicalInterface) """ - ItopapiPhysicalInterface is an object that represent a PhysicalInterface from iTop + ItopapiPhysicalInterface is an object that represents a PhysicalInterface from iTop """ def __init__(self, data=None): super(ItopapiPhysicalInterface, self).__init__(data) - # CI the Physical Interface is connected to - self.connectableci_name = None - self.connectableci_id = None - self.connectableci_id_friendlyname = None - self.connectableci_id_finalclass_recall = None # IP address of the PhysicalInterface self.ipaddress = None # MAC address of the PhysicalInterface @@ -65,4 +58,8 @@ def __init__(self, data=None): # speed of the PhysicalInterface self.speed = None # List of vlans for the PhysicalInterface - self.vlans_list = None \ No newline at end of file + self.vlans_list = None + + +# Register as a subclass of IPInterface +ItopapiIPInterface.register(ItopapiPhysicalInterface) diff --git a/itopapi/model/powerConnection.py b/itopapi/model/powerConnection.py new file mode 100644 index 0000000..cdc6c10 --- /dev/null +++ b/itopapi/model/powerConnection.py @@ -0,0 +1,47 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiPowerConnection is an abstraction of Connectable CI representation on iTop +""" + +from abc import ABCMeta +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.physicalDevice import ItopapiPhysicalDevice + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiPowerConnection(ItopapiPhysicalDevice): + __metaclass__ = ABCMeta + + # Configuration specific to itop + itop = { + 'name': 'PowerConnection', + 'save': [], + 'foreign_keys': [] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of Connectable CI with the given key or criteria """ + return ItopapiPrototype.find(ItopapiPowerConnection, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiPowerConnection, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of Connectable CI """ + return ItopapiPrototype.find_all(ItopapiPowerConnection) + + """ + ItopapiPowerConnection is an object that represents a Connectable CI from iTop + """ + def __init__(self, data=None): + super(ItopapiPowerConnection, self).__init__(data) + + +# Register as a subclass of PhysicalDevice +ItopapiPhysicalDevice.register(ItopapiPowerConnection) \ No newline at end of file diff --git a/itopapi/model/powerSource.py b/itopapi/model/powerSource.py new file mode 100644 index 0000000..99c1e68 --- /dev/null +++ b/itopapi/model/powerSource.py @@ -0,0 +1,80 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiPowerSource is an abstraction of PowerSource representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.powerConnection import ItopapiPowerConnection +from itopapi.model.features.hasOrganization import HasOrganization +from itopapi.model.features.hasLocation import HasLocation +from itopapi.model.features.hasBrand import HasBrand +from itopapi.model.features.hasModel import HasModel + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiPowerSource(ItopapiPowerConnection, HasOrganization, HasLocation, HasBrand, HasModel): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'PowerSource', + # Define which fields to save when creating or updating from the python API + 'save': ['name', 'status', 'business_criticity', 'serialnumber', 'asset_number', + 'move2production', 'purchase_date', 'end_of_warranty', 'description'], + 'foreign_keys': [ + HasOrganization.foreign_key, + HasLocation.foreign_key, + HasBrand.foreign_key, + HasModel.foreign_key, + ] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of PowerSource with the given key or criteria """ + return ItopapiPrototype.find(ItopapiPowerSource, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiPowerSource, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of PowerSource """ + return ItopapiPrototype.find_all(ItopapiPowerSource) + + """ + ItopapiPowerSource is an object that represents a PowerSource from iTop + """ + def __init__(self, data=None): + super(ItopapiPowerSource, self).__init__(data) + + # PowerSource's status. Values within [implementation, obsolete, production, stock] + self.status = None + # PowerSource's business criticity. Values within [high, medium, low] + self.business_criticity = None + # Serial number + self.serialnumber = None + # Asset number + self.asset_number = None + # Server's move to production date + self.move2production = None + # Server's purchase date + self.purchase_date = None + # Server's end of warranty date + self.end_of_warranty = None + self.description = None + ################################## + # Lists # + ################################## + self.documents_list = {} + self.softwares_list = {} + self.services_list = {} + self.applicationsolution_list = {} + self.contacts_list = {} + self.tickets_list = {} + self.providercontracts_list = {} + self.pdus_list = {} diff --git a/itopapi/model/prototype.py b/itopapi/model/prototype.py index 76a1c20..ab79dd9 100644 --- a/itopapi/model/prototype.py +++ b/itopapi/model/prototype.py @@ -9,7 +9,7 @@ from itopapi.itopapiconfig import ItopapiConfig __version__ = '1.0' -__authors__ = ['Guillaume Philippon '] +__authors__ = ['Guillaume Philippon ', 'Julien Nauroy '] class UnknownItopClass(Exception): @@ -35,6 +35,7 @@ class ItopapiPrototype(object): itop = {'name': '', 'save': [], 'foreign_keys': [], 'list_types': {}} def __init__(self, data=None): + super(ItopapiPrototype, self).__init__() self.instance_id = None # Every instance should have an unique ID self.name = None @@ -112,7 +113,11 @@ def find_by_name(itop_class, name): :param name: string :return: Itopapi* """ - return ItopapiPrototype.find(itop_class, {'name': name}) + found = ItopapiPrototype.find(itop_class, {'name': name}) + # find_by_name can have only one result. In this case, return an object, not a list. + if found is not None: + return found[0] + return None @staticmethod def find(itop_class, key): @@ -120,7 +125,7 @@ def find(itop_class, key): Find a list of objects given its id or some criteria passed as a dictionary :param itop_class: :param key: - :return: array or None if there is no object + :return: array """ json_data = json.dumps({ 'operation': 'core/get', @@ -135,13 +140,18 @@ def find(itop_class, key): # If there's no object to process, return immediately if data['objects'] is None: - return None - - ItopapiPrototype.parse_data(data) + return [] objects = [] for information in data['objects']: - obj = itop_class({}) + # If the class is provided in the returned object, use it, else ise itop_class + # Sometimes itop_class is a generic type (e.g. Contact) and instances are a specific class (e.g. Person) + object_class = itop_class + try: + object_class = ItopapiPrototype.get_itop_class(data['objects'][information]['class']) + except UnknownItopClass as e: + pass + obj = object_class({}) obj.instance_id = data['objects'][information]['key'] # update all the object's fields with the following line obj.__dict__.update(data['objects'][information]['fields']) @@ -201,6 +211,7 @@ def save(self): if (result['code'] == '0') and (self.instance_id is None): objects = result['objects'] self.instance_id = objects[objects.keys()[0]].id + self.friendlyname = objects[objects.keys()[0]].friendlyname return result @@ -251,9 +262,13 @@ def __process_lists(self): if "finalclass" in element: element_class = ItopapiPrototype.get_itop_class(element["finalclass"]) else: - class_name = self.__class__.itop["list_types"][key] - if class_name is not None: - element_class = ItopapiPrototype.get_itop_class(class_name) + # class_key can be either the class name itself, or the variable pointing to the class name + class_key = self.__class__.itop["list_types"][key] + if class_key is not None: + if class_key in element: + element_class = ItopapiPrototype.get_itop_class(element[class_key]) + else: + element_class = ItopapiPrototype.get_itop_class(class_key) else: element_class = None if element_class is not None: @@ -272,13 +287,15 @@ def __process_lists(self): def get_itop_class(itop_class): """ Associate the string passed as an argument to the corresponding Itop class - Maybe move it to ItopapiPrototype someday :param itop_class: iTop class """ itop_class = itop_class.lower() # Populate the list of classes if need be if len(ItopapiPrototype.__classes) == 0: - for c in ItopapiPrototype.__subclasses__(): + def all_subclasses(cls): + return cls.__subclasses__() + [g for s in cls.__subclasses__() + for g in all_subclasses(s)] + for c in all_subclasses(ItopapiPrototype): ItopapiPrototype.__classes[c.itop["name"].lower()] = c # Retrieve the proper class depending on the name diff --git a/itopapi/model/rack.py b/itopapi/model/rack.py index 6d95e04..fdefd7f 100644 --- a/itopapi/model/rack.py +++ b/itopapi/model/rack.py @@ -1,18 +1,21 @@ # -*- coding: utf8 -*-fr # pylint: disable=too-many-instance-attributes, invalid-name """ -ItopapiRack is a abstraction of Rack representation on iTop +ItopapiRack is an abstraction of Rack representation on iTop """ from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.physicalDevice import ItopapiPhysicalDevice +from itopapi.model.features.hasOrganization import HasOrganization +from itopapi.model.features.hasLocation import HasLocation __version__ = '1.0' -__authors__ = ['Guillaume Philippon '] +__authors__ = ['Guillaume Philippon ', 'Julien Nauroy '] -class ItopapiRack(ItopapiPrototype): +class ItopapiRack(ItopapiPhysicalDevice, HasOrganization, HasLocation): """ - ItopapiRack is a object that represent a Rack from iTop + ItopapiRack is an object that represents a Rack from iTop """ """ Configuration specific to itop """ @@ -23,9 +26,12 @@ class ItopapiRack(ItopapiPrototype): 'save': ['name', 'status', 'business_criticity', 'nb_u', 'serialnumber', 'asset_number', 'move2production', 'purchase_date', 'end_of_warranty', 'description'], 'foreign_keys': [ - {'id': 'org_id', 'name': 'organization_name', 'table': 'Organization'}, - {'id': 'location_id', 'name': 'location_name', 'table': 'Localization'}, - ] + HasOrganization.foreign_key, + HasLocation.foreign_key, + ], + 'list_types': { + 'contacts_list': 'contact_id_finalclass_recall' + }, } @staticmethod @@ -48,24 +54,10 @@ def __init__(self, data=None): ################################## # Properties # ################################## - # Rack's organization id. Call findOrganization to get the full information or just use - # org_id_friendlyname and organization_name - self.org_id = None - # Rack's organization friendly name. Not sure the difference with organization_name - self.org_id_friendlyname = None - # Rack's organization name - self.organization_name = None # Rack's status. Values within [implementation, obsolete, production, stock] self.status = None # Rack's business criticity. Values within [high, medium, low] self.business_criticity = None - # Rack's location id. Call findLocation to get the full information or just use location_id - # _friendlyname and location_name - self.location_id = None - # Rack's location id's friendly name. Not sure the difference with location_name - self.location_id_friendlyname = None - # Rack's location name - self.location_name = None # Rack's height in "rack units" self.nb_u = None # Rack's serial number @@ -123,7 +115,10 @@ def __init__(self, data=None): # Rack's services list self.services_list = {} - # TODO WTF is this doing here?!? + # Other lists self.applicationsolution_list = None self.softwares_list = None self.logicalvolumes_list = None + +# Register as a subclass of PhysicalDevice +ItopapiPhysicalDevice.register(ItopapiRack) \ No newline at end of file diff --git a/itopapi/model/sanSwitch.py b/itopapi/model/sanSwitch.py new file mode 100644 index 0000000..1a83468 --- /dev/null +++ b/itopapi/model/sanSwitch.py @@ -0,0 +1,117 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes,invalid-name, too-many-statements +""" +ItopapiSANSwitchs is an abstraction of SANSwitch representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.datacenterDevice import ItopapiDatacenterDevice +from itopapi.model.features.hasOrganization import HasOrganization +from itopapi.model.features.hasLocation import HasLocation +from itopapi.model.features.hasBrand import HasBrand +from itopapi.model.features.hasModel import HasModel +from itopapi.model.features.hasRack import HasRack +from itopapi.model.features.hasEnclosure import HasEnclosure +from itopapi.model.features.hasPowerA import HasPowerA +from itopapi.model.features.hasPowerB import HasPowerB + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiSANSwitch(ItopapiDatacenterDevice, HasOrganization, HasLocation, HasBrand, HasModel, + HasRack, HasEnclosure, HasPowerA, HasPowerB): + """ + ItopapiSANSwitch is an object that represents a SANSwitch from iTop + """ + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'SANSwitch', + # Define which fields to save when creating or updating from the python API + 'save': ['name', 'status', 'business_criticity', 'managementip', + 'nb_u', 'serialnumber', 'asset_number', 'move2production', + 'purchase_date', 'end_of_warranty', 'description'], + 'foreign_keys': [ + HasOrganization.foreign_key, + HasLocation.foreign_key, + HasBrand.foreign_key, + HasModel.foreign_key, + HasRack.foreign_key, + HasEnclosure.foreign_key, + HasPowerA.foreign_key, + HasPowerB.foreign_key, + ], + 'list_types': { + 'contacts_list': 'Person', + }, + } + + @staticmethod + def find(key): + """ Retrieve one or mor instance of SANSwitch with the given key or criteria """ + return ItopapiPrototype.find(ItopapiSANSwitch, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiSANSwitch, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of SANSwitch """ + return ItopapiPrototype.find_all(ItopapiSANSwitch) + + def __init__(self, data=None): + super(ItopapiSANSwitch, self).__init__(data) + + # SANSwitch's status. Values within [implementation, obsolete, production, stock] + self.status = None + # SANSwitch's business criticity. Values within [high, medium, low] + self.business_criticity = None + self.managementip = None + # Rack units + self.nb_u = None + # SANSwitch's serial number + self.serialnumber = None + # SANSwitch's asset number + self.asset_number = None + # SANSwitch's move to production date + self.move2production = None + # SANSwitch's purchase date + self.purchase_date = None + # SANSwitch's end of warranty date + self.end_of_warranty = None + # SANSwitch's description, as a free text + self.description = None + + ############################## + # Lists # + ############################## + # SANSwitch's softwares list + self.softwares_list = {} + # SANSwitch's contacts list + self.contacts_list = {} + # SANSwitch's documents list + self.documents_list = {} + # SANSwitch's tickets list + self.tickets_list = {} + # SANSwitch's application solutions list + self.applicationsolution_list = {} + # SANSwitch's network interfaces list + self.physicalinterface_list = {} + # SANSwitch's FC ports list + self.fiberinterfacelist_list = {} + # SANSwitch's network devices list + self.networkdevice_list = {} + # SANSwitch's SANs list + self.san_list = {} + # SANSwitch's provider contracts list + self.providercontracts_list = {} + # SANSwitch's services list + self.services_list = {} + # List of DataCenterDevices + self.datacenterdevice_list = {} + +# Register as a subclass of Datacenter Device +ItopapiDatacenterDevice.register(ItopapiSANSwitch) \ No newline at end of file diff --git a/itopapi/model/server.py b/itopapi/model/server.py index 031abc2..6a3f8da 100644 --- a/itopapi/model/server.py +++ b/itopapi/model/server.py @@ -1,19 +1,31 @@ # -*- coding: utf8 -*-fr # pylint: disable=too-many-instance-attributes,invalid-name, too-many-statements """ -ItopapiServers is a abstraction of Rack representation on iTop +ItopapiServers is an abstraction of Server representation on iTop """ -from itopapi.model.prototype import ItopapiPrototype, ItopapiUnimplementedMethod -from itopapi.model.rack import ItopapiRack +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.datacenterDevice import ItopapiDatacenterDevice +from itopapi.model.features.hasOrganization import HasOrganization +from itopapi.model.features.hasLocation import HasLocation +from itopapi.model.features.hasBrand import HasBrand +from itopapi.model.features.hasModel import HasModel +from itopapi.model.features.hasOSFamily import HasOSFamily +from itopapi.model.features.hasOSVersion import HasOSVersion +from itopapi.model.features.hasOSLicence import HasOSLicence +from itopapi.model.features.hasRack import HasRack +from itopapi.model.features.hasEnclosure import HasEnclosure +from itopapi.model.features.hasPowerA import HasPowerA +from itopapi.model.features.hasPowerB import HasPowerB __version__ = '1.0' -__authors__ = ['Guillaume Philippon '] +__authors__ = ['Julien Nauroy '] -class ItopapiServer(ItopapiPrototype): +class ItopapiServer(ItopapiDatacenterDevice, HasOrganization, HasLocation, HasBrand, HasModel, + HasOSFamily, HasOSVersion, HasOSLicence, HasRack, HasEnclosure, HasPowerA, HasPowerB): """ - ItopapiServers is a object that represent a Servers from iTop + ItopapiServers is an object that represents a Server from iTop """ # Configuration specific to itop @@ -21,20 +33,25 @@ class ItopapiServer(ItopapiPrototype): # Name of the class in Itop 'name': 'Server', # Define which fields to save when creating or updating from the python API - 'save': ['name', 'status', 'business_criticity', - 'rack_id', 'enclosure_id', 'brand_id', 'model_id', 'managementip', + 'save': ['name', 'status', 'business_criticity', 'managementip', 'cpu', 'ram', 'nb_u', 'serialnumber', 'asset_number', 'move2production', 'purchase_date', 'end_of_warranty', 'description'], 'foreign_keys': [ - {'id': 'org_id', 'name': 'organization_name', 'table': 'Organization'}, - {'id': 'location_id', 'name': 'location_name', 'table': 'Localization'}, - {'id': 'osfamily_id', 'name': 'osfamily_name', 'table': 'OSFamily'}, - {'id': 'osversion_id', 'name': 'osversion_name', 'table': 'OSVersion'}, - {'id': 'oslicence_id', 'name': 'oslicence_name', 'table': 'OSLicence'}, - # TODO which is the relevant table? - {'id': 'powerA_id', 'name': 'powerA_name', 'table': 'TODO'}, - {'id': 'powerB_id', 'name': 'powerB_name', 'table': 'TODO'}, - ] + HasOrganization.foreign_key, + HasLocation.foreign_key, + HasBrand.foreign_key, + HasModel.foreign_key, + HasOSFamily.foreign_key, + HasOSVersion.foreign_key, + HasOSLicence.foreign_key, + HasRack.foreign_key, + HasEnclosure.foreign_key, + HasPowerA.foreign_key, + HasPowerB.foreign_key, + ], + 'list_types': { + 'contacts_list': 'Person', + }, } @staticmethod @@ -54,272 +71,55 @@ def find_all(): def __init__(self, data=None): super(ItopapiServer, self).__init__(data) - ################################## - # Properties/General Information # - ################################## - # Server's organization id. Call findOrganization to get the full information or just - # use org_id_friendlyname and organization_name - self.org_id = None - # Server's organization friendly name. Not sure the difference with organization_name - self.org_id_friendlyname = None - # Server's organization name - self.organization_name = None # Server's status. Values within [implementation, obsolete, production, stock] self.status = None # Server's business criticity. Values within [high, medium, low] self.business_criticity = None - # Server's location id. Call findLocation to get the full information or just use - # location_id_friendlyname and location_name - self.location_id = None - # Server's location id's friendly name. Not sure the difference with location_name - self.location_id_friendlyname = None - # Server's location name - self.location_name = None - # Server's rack id. Call findRack to get the full information or just use rack_id - # friendlyname and rack_name - self.rack_id = None - # Server's rack id's friendly name. Not sure the difference with rack_name - self.rack_id_friendlyname = None - # Server's rack name""" - self.rack_name = None - # Server's enclosure (chassis) id. Call findEnclosure to get the full information or just - # use enclosure_id_friendlyname and enclosure_name - self.enclosure_id = None - # Server's enclosure id's friendly name. Not sure the difference with enclosure_name - self.enclosure_id_friendlyname = None - # Server's enclosure name - self.enclosure_name = None - - ################################## - # Properties/More Information # - ################################## - self.brand_id = None - self.brand_id_friendlyname = None - self.brand_name = None - - self.model_id = None - self.model_id_friendlyname = None - self.model_name = None - - self.osfamily_id = None - self.osfamily_id_friendlyname = None - self.osfamily_name = None - - self.osversion_id = None - self.osversion_id_friendlyname = None - self.osversion_name = None - self.managementip = None - - self.oslicence_id = None - self.oslicence_id_friendlyname = None - self.oslicence_name = None - self.cpu = None self.ram = None # Rack units self.nb_u = None + # Server's serial number self.serialnumber = None # Server's asset number self.asset_number = None - - ################################## - # Properties/Date # - ################################## # Server's move to production date self.move2production = None # Server's purchase date self.purchase_date = None # Server's end of warranty date self.end_of_warranty = None - - ################################## - # Properties/Other Information # - ################################## - self.powerA_id = None - self.powerA_id_finalclass_recall = None - self.powerA_id_friendlyname = None - self.powerA_name = None - self.powerB_id = None - self.powerB_id_finalclass_recall = None - self.powerB_id_friendlyname = None - self.powerB_name = None # Server's description, as a free text self.description = None - ################################## - # Softwares # - ################################## + ############################## + # Lists # + ############################## # Server's softwares list self.softwares_list = {} - - ################################## - # Contacts # - ################################## # Server's contacts list self.contacts_list = {} - - ################################## - # Documents # - ################################## # Server's documents list self.documents_list = {} - - ################################## - # Tickets # - ################################## # Server's tickets list self.tickets_list = {} - - ################################## - # Application solutions # - ################################## # Server's application solutions list self.applicationsolution_list = {} - - ################################## - # Network interfaces # - ################################## # Server's network interfaces list self.physicalinterface_list = {} - - ################################## - # FC ports # - ################################## # Server's FC ports list self.fiberinterfacelist_list = {} - - ################################## - # Network devices # - ################################## # Server's network devices list self.networkdevice_list = {} - - ################################## - # SANs # - ################################## # Server's SANs list self.san_list = {} - - ################################## - # Logical volumes # - ################################## # Server's logical volumes list self.logicalvolumes_list = {} - - ################################## - # Provider contracts # - ################################## # Server's provider contracts list self.providercontracts_list = {} - - ################################## - # Services # - ################################## # Server's services list self.services_list = {} - def load_from_json_quattor(self, json_quattor): - """ - Create a ItopapiServer description based on quattor s JSON output - :param json_quattor: json - """ - pass - - def find_rack(self): - """ - Retrieve the ItopapiRack corresponding to this server - """ - if self.rack_id is not None: - return ItopapiRack.find(self.rack_id) - return None - - def find_organization(self): - """ - Retrieve the ItopapiOrganization corresponding to this server - """ - if self.org_id is not None: - # TODO define ItopapiOrganization return ItopapiOrganization.find(self.org_id) - raise ItopapiUnimplementedMethod() - return None - - def find_location(self): - """ - Retrieve the ItopapiLocation corresponding to this server - """ - if self.location_id is not None: - # TODO define ItopapiLocation return ItopapiLocation.find(self.location_id) - raise ItopapiUnimplementedMethod() - return None - - def find_enclosure(self): - """ - Retrieve the ItopapiEnclosure corresponding to this server - """ - if self.enclosure_id is not None: - # TODO define ItopapiEnclosure return ItopapiEnclosure.find(self.enclosure_id) - raise ItopapiUnimplementedMethod() - return None - - def find_brand(self): - """ - Retrieve the ItopapiBrand corresponding to this server - """ - if self.brand_id is not None: - # TODO define ItopapiBrand return ItopapiBrand.find(self.brand_id) - raise ItopapiUnimplementedMethod() - return None - - def find_model(self): - """ - Retrieve the ItopapiModel corresponding to this server - """ - if self.model_id is not None: - # TODO define ItopapiModel return ItopapiModel.find(self.model_id) - raise ItopapiUnimplementedMethod() - return None - - def find_os_family(self): - """ - Retrieve the ItopapiOSFamily corresponding to this server - """ - if self.osfamily_id is not None: - # TODO define ItopapiOSFamily return ItopapiOSFamily.find(self.osfamily_id) - raise ItopapiUnimplementedMethod() - return None - - def find_os_version(self): - """ - Retrieve the ItopapiOSVersion corresponding to this server - """ - if self.osversion_id is not None: - # TODO define ItopapiOSVersion return ItopapiOSVersion.find(self.osversion_id) - raise ItopapiUnimplementedMethod() - return None - - def find_os_licence(self): - """ - Retrieve the ItopapiOSLicence corresponding to this server - """ - if self.oslicence_id is not None: - # TODO define ItopapiOSLicence return ItopapiOSLicence.find(self.oslicence_id) - raise ItopapiUnimplementedMethod() - return None - - def find_power_a(self): - """ - Retrieve the ItopapiPowerA corresponding to this server - """ - if self.powerA_id is not None: - # TODO define ItopapiPowerA return ItopapiOPowerA.find(self.powerA_id) - raise ItopapiUnimplementedMethod() - return None - - def find_power_b(self): - """ - Retrieve the ItopapiPowerB corresponding to this server - """ - if self.powerB_id is not None: - # TODO define ItopapiPowerB return ItopapiOPowerB.find(self.powerB_id) - raise ItopapiUnimplementedMethod() - return None +# Register as a subclass of Datacenter Device +ItopapiDatacenterDevice.register(ItopapiServer) \ No newline at end of file diff --git a/itopapi/model/service.py b/itopapi/model/service.py index 51c008d..813a5d5 100644 --- a/itopapi/model/service.py +++ b/itopapi/model/service.py @@ -1,16 +1,18 @@ # -*- coding: utf8 -*-fr """ -ItopapiService is a abstraction of Service representation on iTop +ItopapiService is an abstraction of Service representation on iTop """ from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.features.hasOrganization import HasOrganization +from itopapi.model.features.hasServiceFamily import HasServiceFamily __version__ = '1.0' __authors__ = ['Julien Nauroy '] -class ItopapiService(ItopapiPrototype): +class ItopapiService(ItopapiPrototype, HasOrganization, HasServiceFamily): # Configuration specific to itop itop = { @@ -19,9 +21,13 @@ class ItopapiService(ItopapiPrototype): # Define which fields to save when creating or updating from the python API 'save': ['name', 'description', 'status'], 'foreign_keys': [ - {'id': 'servicefamily_id', 'name': 'servicefamily_name', 'table': 'ServiceFamily'}, + HasOrganization.foreign_key, + HasServiceFamily.foreign_key, ], - 'list_types': {'functionalcis_list': None}, + 'list_types': { + 'functionalcis_list': 'functionalci_id_finalclass_recall', + 'contacts_list': 'contact_id_finalclass_recall' + }, } @staticmethod @@ -39,15 +45,10 @@ def find_all(): return ItopapiPrototype.find_all(ItopapiService) """ - ItopapiPhysicalInterface is an object that represent a PhysicalInterface from iTop + ItopapiService is an object that represents a Service from iTop """ def __init__(self, data=None): super(ItopapiService, self).__init__(data) - # TODO provider not returned ?!? - # Service Family - self.servicefamily_id = None - self.servicefamily_id_friendlyname = None - self.servicefamily_name = None # Description self.description = None # Service's status. Values within [implementation, obsolete, production] @@ -59,5 +60,3 @@ def __init__(self, data=None): self.customercontracts_list = None self.providercontracts_list = None self.functionalcis_list = None - - # TODO findOrganization method, based on Server \ No newline at end of file diff --git a/itopapi/model/serviceFamily.py b/itopapi/model/serviceFamily.py new file mode 100644 index 0000000..37abd00 --- /dev/null +++ b/itopapi/model/serviceFamily.py @@ -0,0 +1,45 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiServiceFamily is an abstraction of ServiceFamily representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiServiceFamily(ItopapiPrototype): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'ServiceFamily', + # Define which fields to save when creating or updating from the python API + 'save': ['name'], + 'foreign_keys': [] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of ServiceFamily with the given key or criteria """ + return ItopapiPrototype.find(ItopapiServiceFamily, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiServiceFamily, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of ServiceFamily """ + return ItopapiPrototype.find_all(ItopapiServiceFamily) + + """ + ItopapiServiceFamily is an object that represents a ServiceFamily from iTop + """ + def __init__(self, data=None): + super(ItopapiServiceFamily, self).__init__(data) + + # Services which are part of the ServiceFamily + self.services_list = None diff --git a/itopapi/model/softwareInstance.py b/itopapi/model/softwareInstance.py new file mode 100644 index 0000000..afa43fc --- /dev/null +++ b/itopapi/model/softwareInstance.py @@ -0,0 +1,46 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiSoftwareInstance is an abstraction of Software Instance representation on iTop +""" + +from abc import ABCMeta +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.functionalCI import ItopapiFunctionalCI + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiSoftwareInstance(ItopapiFunctionalCI): + __metaclass__ = ABCMeta + + # Configuration specific to itop + itop = { + 'name': 'SoftwareInstance', + 'save': [], + 'foreign_keys': [] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of Software Instance with the given key or criteria """ + return ItopapiPrototype.find(ItopapiSoftwareInstance, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiSoftwareInstance, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of Software Instance """ + return ItopapiPrototype.find_all(ItopapiSoftwareInstance) + + """ + ItopapiSoftwareInstance is an object that represents a Software Instance from iTop + """ + def __init__(self, data=None): + super(ItopapiSoftwareInstance, self).__init__(data) + +# Register as a subclass of FunctionalCI +ItopapiFunctionalCI.register(ItopapiSoftwareInstance) diff --git a/itopapi/model/softwareLicence.py b/itopapi/model/softwareLicence.py new file mode 100644 index 0000000..33a92c0 --- /dev/null +++ b/itopapi/model/softwareLicence.py @@ -0,0 +1,63 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiSoftwareLicence is an abstraction of SoftwareLicence representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.licence import ItopapiLicence +from itopapi.model.features.hasOrganization import HasOrganization +from itopapi.model.features.hasSoftware import HasSoftware + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiSoftwareLicence(ItopapiLicence, HasOrganization, HasSoftware): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'SoftwareLicence', + # Define which fields to save when creating or updating from the python API + 'save': ['name', 'usage_limit', 'description', 'perpetual', 'start_date', 'end_date', 'licence_key'], + 'foreign_keys': [ + HasOrganization.foreign_key, + HasSoftware.foreign_key, + ], + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of SoftwareLicence with the given key or criteria """ + return ItopapiPrototype.find(ItopapiSoftwareLicence, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiSoftwareLicence, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of SoftwareLicence """ + return ItopapiPrototype.find_all(ItopapiSoftwareLicence) + + """ + ItopapiSoftwareLicence is an object that represents an SoftwareLicence (sic) from iTop + """ + def __init__(self, data=None): + super(ItopapiSoftwareLicence, self).__init__(data) + # Number of concurrent users or licences + self.usage_limit = None + self.description = None + # Possible values are ['yes', 'no'] + self.perpetual = 'no' + self.start_date = None + self.end_date = None + self.licence_key = None + # Lists + self.documents_list = [] + self.softwareinstance_list = [] + + +# Register as a subclass of FunctionalCI +ItopapiLicence.register(ItopapiSoftwareLicence) diff --git a/itopapi/model/softwarePatch.py b/itopapi/model/softwarePatch.py new file mode 100644 index 0000000..01b1650 --- /dev/null +++ b/itopapi/model/softwarePatch.py @@ -0,0 +1,50 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=invalid-name +""" +ItopapiSoftwarePatch is an abstraction of SoftwarePatch representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.features.hasSoftware import HasSoftware + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiSoftwarePatch(ItopapiPrototype, HasSoftware): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'SoftwarePatch', + # Define which fields to save when creating or updating from the python API + 'save': ['name', 'description', 'size'], + 'foreign_keys': [ + HasSoftware.foreign_key, + ] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of ApplicationSolution with the given key or criteria """ + return ItopapiPrototype.find(ItopapiSoftwarePatch, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiSoftwarePatch, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of OSFamily """ + return ItopapiPrototype.find_all(ItopapiSoftwarePatch) + + """ + ItopapiSoftwarePatch is an object that represents an Application Solution from iTop + """ + def __init__(self, data=None): + super(ItopapiSoftwarePatch, self).__init__(data) + + self.description = None + # Lists + self.documents_list = {} + self.softwareinstances_list = {} diff --git a/itopapi/model/storageSystem.py b/itopapi/model/storageSystem.py new file mode 100644 index 0000000..04c24a8 --- /dev/null +++ b/itopapi/model/storageSystem.py @@ -0,0 +1,117 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes,invalid-name, too-many-statements +""" +ItopapiStorageSystem is an abstraction of StorageSystem representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.datacenterDevice import ItopapiDatacenterDevice +from itopapi.model.features.hasOrganization import HasOrganization +from itopapi.model.features.hasLocation import HasLocation +from itopapi.model.features.hasBrand import HasBrand +from itopapi.model.features.hasModel import HasModel +from itopapi.model.features.hasRack import HasRack +from itopapi.model.features.hasEnclosure import HasEnclosure +from itopapi.model.features.hasPowerA import HasPowerA +from itopapi.model.features.hasPowerB import HasPowerB + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiStorageSystem(ItopapiDatacenterDevice, HasOrganization, HasLocation, HasBrand, HasModel, + HasRack, HasEnclosure, HasPowerA, HasPowerB): + """ + ItopapiStorageSystem is an object that represents a StorageSystem from iTop + """ + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'StorageSystem', + # Define which fields to save when creating or updating from the python API + 'save': ['name', 'status', 'business_criticity', 'managementip', + 'nb_u', 'serialnumber', 'asset_number', 'move2production', + 'purchase_date', 'end_of_warranty', 'description'], + 'foreign_keys': [ + HasOrganization.foreign_key, + HasLocation.foreign_key, + HasBrand.foreign_key, + HasModel.foreign_key, + HasRack.foreign_key, + HasEnclosure.foreign_key, + HasPowerA.foreign_key, + HasPowerB.foreign_key, + ], + 'list_types': { + 'contacts_list': 'Person', + }, + } + + @staticmethod + def find(key): + """ Retrieve one or mor instance of StorageSystem with the given key or criteria """ + return ItopapiPrototype.find(ItopapiStorageSystem, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiStorageSystem, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of StorageSystem """ + return ItopapiPrototype.find_all(ItopapiStorageSystem) + + def __init__(self, data=None): + super(ItopapiStorageSystem, self).__init__(data) + + # StorageSystem's status. Values within [implementation, obsolete, production, stock] + self.status = None + # StorageSystem's business criticity. Values within [high, medium, low] + self.business_criticity = None + self.managementip = None + # Rack units + self.nb_u = None + # StorageSystem's serial number + self.serialnumber = None + # StorageSystem's asset number + self.asset_number = None + # StorageSystem's move to production date + self.move2production = None + # StorageSystem's purchase date + self.purchase_date = None + # StorageSystem's end of warranty date + self.end_of_warranty = None + # StorageSystem's description, as a free text + self.description = None + + ############################## + # Lists # + ############################## + # StorageSystem's softwares list + self.softwares_list = {} + # StorageSystem's contacts list + self.contacts_list = {} + # StorageSystem's documents list + self.documents_list = {} + # StorageSystem's tickets list + self.tickets_list = {} + # StorageSystem's application solutions list + self.applicationsolution_list = {} + # StorageSystem's network interfaces list + self.physicalinterface_list = {} + # StorageSystem's FC ports list + self.fiberinterfacelist_list = {} + # StorageSystem's network devices list + self.networkdevice_list = {} + # StorageSystem's SANs list + self.san_list = {} + # StorageSystem's provider contracts list + self.providercontracts_list = {} + # StorageSystem's services list + self.services_list = {} + # LogicalVolume's list + self.logicalvolume_list = {} + +# Register as a subclass of Datacenter Device +ItopapiDatacenterDevice.register(ItopapiStorageSystem) \ No newline at end of file diff --git a/itopapi/model/subnet.py b/itopapi/model/subnet.py index 5a327be..c04d3ee 100644 --- a/itopapi/model/subnet.py +++ b/itopapi/model/subnet.py @@ -1,16 +1,17 @@ # -*- coding: utf8 -*-fr """ -ItopapiSubnet is a abstraction of Subnet representation on iTop +ItopapiSubnet is an abstraction of Subnet representation on iTop """ from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.features.hasOrganization import HasOrganization __version__ = '1.0' __authors__ = ['Julien Nauroy '] -class ItopapiSubnet(ItopapiPrototype): +class ItopapiSubnet(ItopapiPrototype, HasOrganization): # Configuration specific to itop itop = { @@ -19,7 +20,7 @@ class ItopapiSubnet(ItopapiPrototype): # Define which fields to save when creating or updating from the python API 'save': ['ip', 'ip_mask', 'subnet_name', 'description'], 'foreign_keys': [ - {'id': 'org_id', 'name': 'organization_name', 'table': 'Organization'}, + HasOrganization.foreign_key, ], 'list_types': {'vlans_list': 'VLAN'}, } @@ -39,7 +40,7 @@ def find_all(): return ItopapiPrototype.find_all(ItopapiSubnet) """ - ItopapiPhysicalInterface is an object that represent a PhysicalInterface from iTop + ItopapiPhysicalInterface is an object that represents a PhysicalInterface from iTop """ def __init__(self, data=None): super(ItopapiSubnet, self).__init__(data) @@ -49,16 +50,7 @@ def __init__(self, data=None): self.ip_mask = None # Subnet name self.subnet_name = None - # Subnet's organization id. Call findOrganization to get the full information or just use - # org_id_friendlyname and organization_name - self.org_id = None - # Subnet's organization friendly name. Not sure the difference with organization_name - self.org_id_friendlyname = None - # Subnet's organization name - self.org_name = None # Subnet's description self.description = None # VLANs associated with this Subnet - self.vlans_list = None - - # TODO findOrganization method, based on Server \ No newline at end of file + self.vlans_list = None \ No newline at end of file diff --git a/itopapi/model/tape.py b/itopapi/model/tape.py new file mode 100644 index 0000000..642d75d --- /dev/null +++ b/itopapi/model/tape.py @@ -0,0 +1,48 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=invalid-name +""" +ItopapiTape is an abstraction of Tape representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.features.hasTapeLibrary import HasTapeLibrary + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiTape(ItopapiPrototype, HasTapeLibrary): + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'Tape', + # Define which fields to save when creating or updating from the python API + 'save': ['name', 'description', 'size'], + 'foreign_keys': [ + HasTapeLibrary.foreign_key, + ] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of ApplicationSolution with the given key or criteria """ + return ItopapiPrototype.find(ItopapiTape, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiTape, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of OSFamily """ + return ItopapiPrototype.find_all(ItopapiTape) + + """ + ItopapiTape is an object that represents an Application Solution from iTop + """ + def __init__(self, data=None): + super(ItopapiTape, self).__init__(data) + + self.description = None + self.size = None diff --git a/itopapi/model/tapeLibrary.py b/itopapi/model/tapeLibrary.py new file mode 100644 index 0000000..1a22048 --- /dev/null +++ b/itopapi/model/tapeLibrary.py @@ -0,0 +1,117 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes,invalid-name, too-many-statements +""" +ItopapiTapeLibrarys is an abstraction of TapeLibrary representation on iTop +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.datacenterDevice import ItopapiDatacenterDevice +from itopapi.model.features.hasOrganization import HasOrganization +from itopapi.model.features.hasLocation import HasLocation +from itopapi.model.features.hasBrand import HasBrand +from itopapi.model.features.hasModel import HasModel +from itopapi.model.features.hasRack import HasRack +from itopapi.model.features.hasEnclosure import HasEnclosure +from itopapi.model.features.hasPowerA import HasPowerA +from itopapi.model.features.hasPowerB import HasPowerB + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiTapeLibrary(ItopapiDatacenterDevice, HasOrganization, HasLocation, HasBrand, HasModel, + HasRack, HasEnclosure, HasPowerA, HasPowerB): + """ + ItopapiTapeLibrary is an object that represents a TapeLibrary from iTop + """ + + # Configuration specific to itop + itop = { + # Name of the class in Itop + 'name': 'TapeLibrary', + # Define which fields to save when creating or updating from the python API + 'save': ['name', 'status', 'business_criticity', 'managementip', + 'nb_u', 'serialnumber', 'asset_number', 'move2production', + 'purchase_date', 'end_of_warranty', 'description'], + 'foreign_keys': [ + HasOrganization.foreign_key, + HasLocation.foreign_key, + HasBrand.foreign_key, + HasModel.foreign_key, + HasRack.foreign_key, + HasEnclosure.foreign_key, + HasPowerA.foreign_key, + HasPowerB.foreign_key, + ], + 'list_types': { + 'contacts_list': 'Person', + }, + } + + @staticmethod + def find(key): + """ Retrieve one or mor instance of TapeLibrary with the given key or criteria """ + return ItopapiPrototype.find(ItopapiTapeLibrary, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiTapeLibrary, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of TapeLibrary """ + return ItopapiPrototype.find_all(ItopapiTapeLibrary) + + def __init__(self, data=None): + super(ItopapiTapeLibrary, self).__init__(data) + + # TapeLibrary's status. Values within [implementation, obsolete, production, stock] + self.status = None + # TapeLibrary's business criticity. Values within [high, medium, low] + self.business_criticity = None + self.managementip = None + # Rack units + self.nb_u = None + # TapeLibrary's serial number + self.serialnumber = None + # TapeLibrary's asset number + self.asset_number = None + # TapeLibrary's move to production date + self.move2production = None + # TapeLibrary's purchase date + self.purchase_date = None + # TapeLibrary's end of warranty date + self.end_of_warranty = None + # TapeLibrary's description, as a free text + self.description = None + + ############################## + # Lists # + ############################## + # TapeLibrary's softwares list + self.softwares_list = {} + # TapeLibrary's contacts list + self.contacts_list = {} + # TapeLibrary's documents list + self.documents_list = {} + # TapeLibrary's tickets list + self.tickets_list = {} + # TapeLibrary's application solutions list + self.applicationsolution_list = {} + # TapeLibrary's network interfaces list + self.physicalinterface_list = {} + # TapeLibrary's FC ports list + self.fiberinterfacelist_list = {} + # TapeLibrary's network devices list + self.networkdevice_list = {} + # TapeLibrary's SANs list + self.san_list = {} + # TapeLibrary's provider contracts list + self.providercontracts_list = {} + # TapeLibrary's services list + self.services_list = {} + # List of Tapes + self.tapes_list = {} + +# Register as a subclass of Datacenter Device +ItopapiDatacenterDevice.register(ItopapiTapeLibrary) \ No newline at end of file diff --git a/itopapi/model/team.py b/itopapi/model/team.py new file mode 100644 index 0000000..0214c9d --- /dev/null +++ b/itopapi/model/team.py @@ -0,0 +1,69 @@ +# -*- coding: utf8 -*-fr +# pylint: disable=too-many-instance-attributes, invalid-name +""" +ItopapiTeam is an abstraction of Team representation on iTop +It inherits from ItopapiContact +""" + +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.contact import ItopapiContact +from itopapi.model.features.hasOrganization import HasOrganization + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiTeam(ItopapiContact, HasOrganization): + """ + ItopapiTeam is an object that represents a Team from iTop + """ + + """ Configuration specific to itop """ + itop = { + # Name of the class in Itop + 'name': 'Team', + # Define which fields to save when creating or updating from the python API + 'save': ['status', 'phone', 'notify', 'name', 'function', 'email'], + 'foreign_keys': [ + HasOrganization.foreign_key, + ], + 'list_types': { + 'persons_list': 'Person', + 'cis_list': 'functionalci_id_finalclass_recall' + }, + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of Team with the given key or criteria """ + return ItopapiPrototype.find(ItopapiTeam, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiTeam, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of Rack """ + return ItopapiPrototype.find_all(ItopapiTeam) + + def __init__(self, data=None): + super(ItopapiTeam, self).__init__(data) + + ################################## + # Properties # + ################################## + self.status = None + self.phone = None + self.notify = None + self.function = None + self.email = None + ################################## + # Lists # + ################################## + self.cis_list = None + self.tickets_list = None + self.persons_list = None + +# Register as a subclass of Contact +ItopapiContact.register(ItopapiTeam) \ No newline at end of file diff --git a/itopapi/model/typology.py b/itopapi/model/typology.py new file mode 100644 index 0000000..d9f9b16 --- /dev/null +++ b/itopapi/model/typology.py @@ -0,0 +1,42 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiTypology is an abstraction of Typology representation on iTop +""" + +from abc import ABCMeta +from itopapi.model.prototype import ItopapiPrototype + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiTypology(ItopapiPrototype): + __metaclass__ = ABCMeta + + # Configuration specific to itop + itop = { + 'name': 'Typology', + 'save': [], + 'foreign_keys': [] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of Functional CI with the given key or criteria """ + return ItopapiPrototype.find(ItopapiTypology, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiTypology, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of Functional CI """ + return ItopapiPrototype.find_all(ItopapiTypology) + + """ + ItopapiTypology is an object that represents a Functional CI from iTop + """ + def __init__(self, data=None): + super(ItopapiTypology, self).__init__(data) diff --git a/itopapi/model/virtualDevice.py b/itopapi/model/virtualDevice.py new file mode 100644 index 0000000..c766046 --- /dev/null +++ b/itopapi/model/virtualDevice.py @@ -0,0 +1,47 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiVirtualDevice is an abstraction of VirtualDevice representation on iTop +""" + +from abc import ABCMeta +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.functionalCI import ItopapiFunctionalCI + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiVirtualDevice(ItopapiFunctionalCI): + __metaclass__ = ABCMeta + + # Configuration specific to itop + itop = { + 'name': 'VirtualDevice', + 'save': [], + 'foreign_keys': [] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of VirtualDevice with the given key or criteria """ + return ItopapiPrototype.find(ItopapiVirtualDevice, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiVirtualDevice, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of VirtualDevice """ + return ItopapiPrototype.find_all(ItopapiVirtualDevice) + + """ + ItopapiVirtualDevice is an object that represents a VirtualDevice from iTop + """ + def __init__(self, data=None): + super(ItopapiVirtualDevice, self).__init__(data) + + +# Register as a subclass of FunctionalCI +ItopapiFunctionalCI.register(ItopapiVirtualDevice) diff --git a/itopapi/model/virtualHost.py b/itopapi/model/virtualHost.py new file mode 100644 index 0000000..de915d2 --- /dev/null +++ b/itopapi/model/virtualHost.py @@ -0,0 +1,48 @@ +# -*- coding: utf8 -*-fr + +""" +ItopapiVirtualHost is an abstraction of VirtualHost representation on iTop +""" + +from abc import ABCMeta +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.virtualDevice import ItopapiVirtualDevice +from itopapi.model.functionalCI import ItopapiFunctionalCI + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + + +class ItopapiVirtualHost(ItopapiVirtualDevice): + __metaclass__ = ABCMeta + + # Configuration specific to itop + itop = { + 'name': 'VirtualHost', + 'save': [], + 'foreign_keys': [] + } + + @staticmethod + def find(key): + """ Retrieve one or more instance of VirtualHost with the given key or criteria """ + return ItopapiPrototype.find(ItopapiVirtualHost, key) + + @staticmethod + def find_by_name(name): + return ItopapiPrototype.find_by_name(ItopapiVirtualHost, name) + + @staticmethod + def find_all(): + """ Retrieve all instance of VirtualHost """ + return ItopapiPrototype.find_all(ItopapiVirtualHost) + + """ + ItopapiVirtualHost is an object that represents a VirtualHost from iTop + """ + def __init__(self, data=None): + super(ItopapiVirtualHost, self).__init__(data) + + +# Register as a subclass of VirtualDevice +ItopapiVirtualDevice.register(ItopapiVirtualHost) diff --git a/itopapi/model/virtualMachine.py b/itopapi/model/virtualMachine.py index cae3a21..781014d 100644 --- a/itopapi/model/virtualMachine.py +++ b/itopapi/model/virtualMachine.py @@ -1,16 +1,22 @@ # -*- coding: utf8 -*-fr """ -ItopapiVirtualMachine is a abstraction of VLAN representation on iTop +ItopapiVirtualMachine is an abstraction of a VirtualMachine representation on iTop """ -from itopapi.model.prototype import ItopapiPrototype, ItopapiUnimplementedMethod +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.virtualDevice import ItopapiVirtualDevice +from itopapi.model.features.hasOrganization import HasOrganization +from itopapi.model.features.hasOSFamily import HasOSFamily +from itopapi.model.features.hasOSVersion import HasOSVersion +from itopapi.model.features.hasOSLicence import HasOSLicence +from itopapi.model.features.hasVirtualHost import HasVirtualHost __version__ = '1.0' __authors__ = ['Julien Nauroy '] -class ItopapiVirtualMachine(ItopapiPrototype): +class ItopapiVirtualMachine(ItopapiVirtualDevice, HasOrganization, HasOSFamily, HasOSVersion, HasOSLicence, HasVirtualHost): # Configuration specific to itop itop = { @@ -20,12 +26,15 @@ class ItopapiVirtualMachine(ItopapiPrototype): 'managementip', 'oslicence_id', 'cpu', 'ram', 'move2production', 'description'], 'foreign_keys': [ - {'id': 'virtualhost_id', 'name': 'virtualhost_name', 'table': 'VirtualHost'}, - {'id': 'org_id', 'name': 'organization_name', 'table': 'Organization'}, - {'id': 'osfamily_id', 'name': 'osfamily_name', 'table': 'OSFamily'}, - {'id': 'osversion_id', 'name': 'osversion_name', 'table': 'OSVersion'}, - {'id': 'oslicence_id', 'name': 'oslicence_name', 'table': 'OSLicence'}, - ] + HasOrganization.foreign_key, + HasOSFamily.foreign_key, + HasOSVersion.foreign_key, + HasOSLicence.foreign_key, + HasVirtualHost.foreign_key, + ], + 'list_types': { + 'contacts_list': 'contact_id_finalclass_recall' + }, } @staticmethod @@ -43,159 +52,45 @@ def find_all(): return ItopapiPrototype.find_all(ItopapiVirtualMachine) """ - ItopapiPhysicalInterface is an object that represent a PhysicalInterface from iTop + ItopapiPhysicalInterface is an object that represents a PhysicalInterface from iTop """ def __init__(self, data=None): super(ItopapiVirtualMachine, self).__init__(data) - ################################## - # Properties/General Information # - ################################## - # VirtualMachine's organization id. Call findOrganization to get the full information or just - # use org_id_friendlyname and organization_name - self.org_id = None - # VirtualMachine's organization friendly name. Not sure the difference with organization_name - self.org_id_friendlyname = None - # VirtualMachine's organization name - self.organization_name = None # VirtualMachine's status. Values within [implementation, obsolete, production, stock] self.status = None # VirtualMachine's business criticity. Values within [high, medium, low] self.business_criticity = None - # VirtualMachine's virtual host - self.virtualhost_id = None - self.virtualhost_id_finalclass_recall = None - self.virtualhost_id_friendlyname = None - self.virtualhost_name = None - - ################################## - # Properties/More Information # - ################################## - - self.osfamily_id = None - self.osfamily_id_friendlyname = None - self.osfamily_name = None - - self.osversion_id = None - self.osversion_id_friendlyname = None - self.osversion_name = None - self.managementip = None - - self.oslicence_id = None - self.oslicence_id_friendlyname = None - self.oslicence_name = None - self.cpu = None self.ram = None - # Rack units - self.nb_u = None - - ################################## - # Properties/Date # - ################################## - - ################################## - # Properties/Other Information # - ################################## # VirtualMachine's move to production date self.move2production = None # VirtualMachine's description, as a free text self.description = None - ################################## - # Softwares # - ################################## + ############################## + # Lists # + ############################## # VirtualMachine's softwares list self.softwares_list = {} - - ################################## - # Contacts # - ################################## # VirtualMachine's contacts list self.contacts_list = {} - - ################################## - # Documents # - ################################## # VirtualMachine's documents list self.documents_list = {} - - ################################## - # Tickets # - ################################## # VirtualMachine's tickets list self.tickets_list = {} - - ################################## - # Application solutions # - ################################## # VirtualMachine's application solutions list self.applicationsolution_list = {} - - ################################## - # Network interfaces # - ################################## # VirtualMachine's network interfaces list self.physicalinterface_list = {} - - ################################## - # Logical volumes # - ################################## # VirtualMachine's logical volumes list self.logicalvolumes_list = {} - - ################################## - # Provider contracts # - ################################## # VirtualMachine's provider contracts list self.providercontracts_list = {} - - ################################## - # Services # - ################################## # VirtualMachine's services list self.services_list = {} - def load_from_json_quattor(self, json_quattor): - """ - Create a ItopapiVirtualMachine description based on quattor s JSON output - :param json_quattor: json - """ - pass - - def find_organization(self): - """ - Retrieve the ItopapiOrganization corresponding to this VirtualMachine - """ - if self.org_id is not None: - # TODO define ItopapiOrganization return ItopapiOrganization.find(self.org_id) - raise ItopapiUnimplementedMethod() - return None - - def find_os_family(self): - """ - Retrieve the ItopapiOSFamily corresponding to this VirtualMachine - """ - if self.osfamily_id is not None: - # TODO define ItopapiOSFamily return ItopapiOSFamily.find(self.osfamily_id) - raise ItopapiUnimplementedMethod() - return None - - def find_os_version(self): - """ - Retrieve the ItopapiOSVersion corresponding to this VirtualMachine - """ - if self.osversion_id is not None: - # TODO define ItopapiOSVersion return ItopapiOSVersion.find(self.osversion_id) - raise ItopapiUnimplementedMethod() - return None - def find_os_licence(self): - """ - Retrieve the ItopapiOSLicence corresponding to this VirtualMachine - """ - if self.oslicence_id is not None: - # TODO define ItopapiOSLicence return ItopapiOSLicence.find(self.oslicence_id) - raise ItopapiUnimplementedMethod() - return None \ No newline at end of file +# Register as a subclass of VirtualDevice +ItopapiVirtualDevice.register(ItopapiVirtualMachine) diff --git a/itopapi/model/vlan.py b/itopapi/model/vlan.py index 7c3949a..48c3bd8 100644 --- a/itopapi/model/vlan.py +++ b/itopapi/model/vlan.py @@ -1,17 +1,18 @@ # -*- coding: utf8 -*-fr """ -ItopapiVLAN is a abstraction of VLAN representation on iTop +ItopapiVLAN is an abstraction of VLAN representation on iTop Note : VLAN has no finalclass and name. It complicates things... """ from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.features.hasOrganization2 import HasOrganization2 __version__ = '1.0' __authors__ = ['Julien Nauroy '] -class ItopapiVLAN(ItopapiPrototype): +class ItopapiVLAN(ItopapiPrototype, HasOrganization2): # Configuration specific to itop itop = { @@ -20,14 +21,14 @@ class ItopapiVLAN(ItopapiPrototype): # Define which fields to save when creating or updating from the python API 'save': ['vlan_tag', 'description'], 'foreign_keys': [ - {'id': 'org_id', 'name': 'organization_name', 'table': 'Organization'}, + HasOrganization2.foreign_key ], 'list_types': {'physicalinterfaces_list': 'PhysicalInterface', 'subnets_list': 'Subnet'}, } @staticmethod def find(key): - """ Retrieve one or more instance of PhysicalInterface with the given key or criteria """ + """ Retrieve one or more instance of VLAN with the given key or criteria """ return ItopapiPrototype.find(ItopapiVLAN, key) @staticmethod @@ -36,28 +37,19 @@ def find_by_name(name): @staticmethod def find_all(): - """ Retrieve all instance of PhysicalInterface """ + """ Retrieve all instance of VLAN """ return ItopapiPrototype.find_all(ItopapiVLAN) """ - ItopapiPhysicalInterface is an object that represent a PhysicalInterface from iTop + ItopapiVLAN is an object that represents a VLAN from iTop """ def __init__(self, data=None): super(ItopapiVLAN, self).__init__(data) # VLAN tag, replaces the "name" value for other classes self.vlan_tag = None - # VLAN's organization id. Call findOrganization to get the full information or just use - # org_id_friendlyname and organization_name - self.org_id = None - # VLAN's organization friendly name. Not sure the difference with organization_name - self.org_id_friendlyname = None - # VLAN's organization name - self.org_name = None # VLAN's description self.description = None # Interfaces self.physicalinterfaces_list = None # subnets self.subnets_list = None - - # TODO findOrganization method, based on Server \ No newline at end of file diff --git a/itopapi/model/webapplication.py b/itopapi/model/webApplication.py similarity index 55% rename from itopapi/model/webapplication.py rename to itopapi/model/webApplication.py index 9435f80..9e3b909 100644 --- a/itopapi/model/webapplication.py +++ b/itopapi/model/webApplication.py @@ -1,19 +1,21 @@ # -*- coding: utf8 -*-fr # pylint: disable=too-many-instance-attributes,invalid-name, too-many-statements """ -ItopapiWebApplication is a abstraction of Rack representation on iTop +ItopapiWebApplication is an abstraction of WebApplication representation on iTop """ -from itopapi.model.prototype import ItopapiPrototype, ItopapiUnimplementedMethod -from itopapi.model.rack import ItopapiRack +from itopapi.model.prototype import ItopapiPrototype +from itopapi.model.functionalCI import ItopapiFunctionalCI +from itopapi.model.features.hasOrganization import HasOrganization +from itopapi.model.features.hasWebServer import HasWebServer __version__ = '1.0' -__authors__ = ['Guillaume Philippon '] +__authors__ = ['Julien Nauroy '] -class ItopapiWebApplication(ItopapiPrototype): +class ItopapiWebApplication(ItopapiFunctionalCI, HasOrganization, HasWebServer): """ - ItopapiWebApplication is a object that represent a WebApplication from iTop + ItopapiWebApplication is an object that represents a WebApplication from iTop """ # Configuration specific to itop @@ -21,13 +23,15 @@ class ItopapiWebApplication(ItopapiPrototype): # Name of the class in Itop 'name': 'WebApplication', # Define which fields to save when creating or updating from the python API - 'save': ['name', 'url', 'business_criticity', - 'move2production', 'description'], + 'save': ['name', 'url', 'business_criticity', 'move2production', 'description'], 'foreign_keys': [ - {'id': 'org_id', 'name': 'organization_name', 'table': 'Organization'}, - {'id': 'webserver_id', 'name': 'webserver_name', 'table': 'WebServer'}, + HasOrganization.foreign_key, + HasWebServer.foreign_key, ], - 'list_types': {'services_list': 'Service'} + 'list_types': { + 'services_list': 'Service', + 'contacts_list': 'contact_id_finalclass_recall' + }, } @staticmethod @@ -50,17 +54,6 @@ def __init__(self, data=None): ################################## # Properties/General Information # ################################## - # WebApplication's organization id. Call findOrganization to get the full information or just - # use org_id_friendlyname and organization_name - self.org_id = None - # WebApplication's organization friendly name. Not sure the difference with organization_name - self.org_id_friendlyname = None - # WebApplication's organization name - self.organization_name = None - # WebServer hosting the application - self.webserver_id = None - self.webserver_id_friendlyname = None - self.webserver_name = None # WebApplication's URL self.url = None # WebApplication's business criticity. Values within [high, medium, low] @@ -106,27 +99,6 @@ def __init__(self, data=None): # WebApplication's services list self.services_list = {} - def load_from_json_quattor(self, json_quattor): - """ - Create a ItopapiWebApplication description based on quattor s JSON output - :param json_quattor: json - """ - pass - - def find_organization(self): - """ - Retrieve the ItopapiOrganization corresponding to this WebApplication - """ - if self.org_id is not None: - # TODO define ItopapiOrganization return ItopapiOrganization.find(self.org_id) - raise ItopapiUnimplementedMethod() - return None - - def find_web_server(self): - """ - Retrieve the ItopapiOrganization corresponding to this WebApplication - """ - if self.webserver_id is not None: - # TODO define ItopapiOrganization return ItopapiOrganization.find(self.org_id) - raise ItopapiUnimplementedMethod() - return None + +# Register as a subclass of FunctionalCI +ItopapiFunctionalCI.register(ItopapiWebApplication) diff --git a/itopapi/model/webServer.py b/itopapi/model/webServer.py index 7c5ce72..6a9eefd 100644 --- a/itopapi/model/webServer.py +++ b/itopapi/model/webServer.py @@ -1,19 +1,23 @@ # -*- coding: utf8 -*-fr # pylint: disable=too-many-instance-attributes,invalid-name, too-many-statements """ -ItopapiWebServer is a abstraction of Rack representation on iTop +ItopapiWebServer is an abstraction of WebServer representation on iTop """ from itopapi.model.prototype import ItopapiPrototype, ItopapiUnimplementedMethod -from itopapi.model.rack import ItopapiRack +from itopapi.model.softwareInstance import ItopapiSoftwareInstance +from itopapi.model.features.hasOrganization import HasOrganization +from itopapi.model.features.hasSoftwareLicence import HasSoftwareLicence +from itopapi.model.features.hasSoftware import HasSoftware +from itopapi.model.features.hasSystem import HasSystem __version__ = '1.0' -__authors__ = ['Guillaume Philippon '] +__authors__ = ['Julien Nauroy '] -class ItopapiWebServer(ItopapiPrototype): +class ItopapiWebServer(ItopapiSoftwareInstance, HasOrganization, HasSoftwareLicence, HasSoftware, HasSystem): """ - ItopapiWebServer is a object that represent a WebServer from iTop + ItopapiWebServer is an object that represents a WebServer from iTop """ # Configuration specific to itop @@ -23,11 +27,14 @@ class ItopapiWebServer(ItopapiPrototype): # Define which fields to save when creating or updating from the python API 'save': ['name', 'status', 'business_criticity', 'path', 'move2production', 'description'], 'foreign_keys': [ - {'id': 'org_id', 'name': 'organization_name', 'table': 'Organization'}, - {'id': 'system_id', 'name': 'system_id_friendlyname', 'table': 'Server'}, - {'id': 'software_id', 'name': 'software_name', 'table': 'Software'}, - {'id': 'softwarelicence_id', 'name': 'softwarelicence_name', 'table': 'SoftwareLicence'}, - ] + HasOrganization.foreign_key, + HasSoftware.foreign_key, + HasSoftwareLicence.foreign_key, + HasSystem.foreign_key, + ], + 'list_types': { + 'contacts_list': 'contact_id_finalclass_recall' + }, } @staticmethod @@ -50,13 +57,6 @@ def __init__(self, data=None): ################################## # Properties/General Information # ################################## - # WebServer's organization id. Call findOrganization to get the full information or just - # use org_id_friendlyname and organization_name - self.org_id = None - # WebServer's organization friendly name. Not sure the difference with organization_name - self.org_id_friendlyname = None - # WebServer's organization name - self.organization_name = None # WebServer's status. Values within [implementation, obsolete, production, stock] self.status = None # WebServer's business criticity. Values within [high, medium, low] @@ -66,14 +66,6 @@ def __init__(self, data=None): self.system_id_finalclass_recall = None self.system_id_friendlyname = None self.system_name = None - # Web server's software - self.software_id = None - self.software_id_friendlyname = None - self.software_name = None - # Web server's software licence - self.softwarelicence_id = None - self.softwarelicence_id_friendlyname = None - self.softwarelicence_name = None # Web server's path ? self.path = None # WebServer's move to production date @@ -81,117 +73,34 @@ def __init__(self, data=None): # WebServer's description, as a free text self.description = None - ################################## - # Contacts # - ################################## + ############################### + # Lists # + ############################### # WebServer's contacts list self.contacts_list = {} - - ################################## - # Documents # - ################################## # WebServer's documents list self.documents_list = {} - - ################################## - # Tickets # - ################################## # WebServer's tickets list self.tickets_list = {} - - ################################## - # Application solutions # - ################################## # WebServer's application solutions list self.applicationsolution_list = {} - - ################################## - # Web applications # - ################################## # WebServer's web applications list self.webapp_list = {} - - ################################## - # Network interfaces # - ################################## # WebServer's network interfaces list self.physicalinterface_list = {} - - ################################## - # FC ports # - ################################## # WebServer's FC ports list self.fiberinterfacelist_list = {} - - ################################## - # Network devices # - ################################## # WebServer's network devices list self.networkdevice_list = {} - - ################################## - # SANs # - ################################## # WebServer's SANs list self.san_list = {} - - ################################## - # Logical volumes # - ################################## # WebServer's logical volumes list self.logicalvolumes_list = {} - - ################################## - # Provider contracts # - ################################## # WebServer's provider contracts list self.providercontracts_list = {} - - ################################## - # Services # - ################################## # WebServer's services list self.services_list = {} - def load_from_json_quattor(self, json_quattor): - """ - Create a ItopapiWebServer description based on quattor s JSON output - :param json_quattor: json - """ - pass - - def find_organization(self): - """ - Retrieve the ItopapiOrganization corresponding to this WebServer - """ - if self.org_id is not None: - # TODO define ItopapiOrganization return ItopapiOrganization.find(self.org_id) - raise ItopapiUnimplementedMethod() - return None - - def find_system(self): - """ - Retrieve the ItopapiPowerB corresponding to this WebServer - """ - if self.system_id is not None: - # TODO - raise ItopapiUnimplementedMethod() - return None - - def find_software(self): - """ - Retrieve the ItopapiPowerB corresponding to this WebServer - """ - if self.software_id is not None: - # TODO - raise ItopapiUnimplementedMethod() - return None - def find_software_licence(self): - """ - Retrieve the ItopapiPowerB corresponding to this WebServer - """ - if self.software_licence_id is not None: - # TODO - raise ItopapiUnimplementedMethod() - return None +# Register as a subclass of SoftwareInstance +ItopapiSoftwareInstance.register(ItopapiWebServer) diff --git a/itopcli/itopcliconfig.py b/itopcli/itopcliconfig.py index ca2776d..26d4720 100644 --- a/itopcli/itopcliconfig.py +++ b/itopcli/itopcliconfig.py @@ -61,7 +61,7 @@ def load_configuration_cli(): # CLI specific argument # ######################### cli_group = parser.add_argument_group('cli') - cli_group.add_argument('--config', dest='config_file', default='./itop-cli.cfg', + cli_group.add_argument('--config', dest='config_file', default='./python-itop-api.cfg', help='configuration file CLI must use' ' (default = %(default)s)') cli_group.add_argument('--classes', dest='classes', nargs='*', metavar='ITOP-CLASS', diff --git a/python-itop-api.cfg.example b/python-itop-api.cfg.example new file mode 100644 index 0000000..d3db7b8 --- /dev/null +++ b/python-itop-api.cfg.example @@ -0,0 +1,47 @@ +# This is an example configuration file. copy or rename it to 'python-itop-api.cfg' and edit the values. +# At least hostname, username and password will have to be changed. +# Make sure to leave 'form' as an allowed login type within Itop's configuration. +[main] +hostname: itop.example.com +username: demouser +password: demopass +protocol: https +base_uri: / +api_version: 1.0 +api_suffix: /webservices/rest.php +# If you set this value to true, the api will only pretend deleting objects. +# Useful only for debugging purposes +simulate_deletes: False +# If you set this value to true, the api will check if an object with the same name already exists before saving. +# Checks can take some time because the itop rest api is slow +prevent_duplicates: False +# Default organization when adding servers or VMs +organization: +# Default virtualhost when adding VMs +virtualhost: + +[centreon] +# Centreon CLAPI username +username: admin +# Centreon CLAPI password +password: pass +# Centreon CLAPI executable +clapi_path: /usr/bin/centreon + +[vcenter] +# VCenter host +host: localhost +# VCenter port. HTTPS (443) is the default +port: 443 +# User allowed to log in to the VCenter +username: admin +# Associated password (strongly discouraged ; prefer leaving blank and entering it when promped) +password: +# Allow unsecure HTTPS connections (e.g. with a self-signed certificate). Thanks PEP 466. +unsecure = 0 +# Synchronization modes for Clusters (iTop Farms). The list can only contain add (add Cluster not found in iTop), update and delete +cluster_sync_mode = ["add", "update"] +# Synchronization modes for Hosts (iTop Servers). The list can only contain add (add Hosts not found in iTop), update and delete +host_sync_mode = ["add", "update"] +# Synchronization modes for VMs. The list can only contain add (add VMs not found in iTop), update and delete +vm_sync_mode = ["add", "update"] diff --git a/setup.py b/setup.py old mode 100644 new mode 100755 index ddd68ef..3e7b887 --- a/setup.py +++ b/setup.py @@ -8,11 +8,11 @@ setup(name='python-itop-api', version='1.0', - description='Set of python script to interact with iTop', - author='Guillaume Philippon', - author_email='guillaume.philippon@lal.in2p3.fr', + description='Set of python scripts to interact with iTop', + author='Guillaume Philippon, Julien Nauroy', + author_email='guillaume.philippon@lal.in2p3.fr, julien.nauroy@u-psud.fr', url='https://github.com/guillaume-philippon/python-itop-api', license='FreeBSD License', - data_files=[('/usr/share/itop-cli', ['itop-cli.cfg.example'])], - scripts=["itop-cli"], + data_files=[('/usr/share/itop-cli', ['python-itop-api.cfg.example'])], + scripts=["itop-cli", "vcenter2itop", "itop2centreon"], packages=find_packages()) diff --git a/vcenter2itop.py b/vcenter2itop.py new file mode 100755 index 0000000..c1b2b8f --- /dev/null +++ b/vcenter2itop.py @@ -0,0 +1,556 @@ +#!/usr/bin/env python +# -*- coding: utf8 -*-fr +# pylint: disable=invalid-name +""" +vcenter2itop is a basic CLI interface to export vcenter data into iTop. +requires pyVmomi +""" + +__version__ = '1.0' +__authors__ = ['Julien Nauroy '] + +from itopapi import ItopapiController, ItopapiConfig, UnsupportedImportFormat +from itopcli import load_configuration_cli, ItopcliConfig, NeedMoreArgs +from itopapi.model import * +from pyVim import connect +from pyVmomi import vmodl +from pyVmomi import vim +import ssl +import getpass +import atexit +import json + + +# Helper function to cleanup everything the script is supposed to add +# Do not use it in a mixed configuration +def cleanup(): + print "Deleting all virtual machines" + for x in ItopapiVirtualMachine.find_all(): + x.delete() + print "Deleting all hypervisors" + for x in ItopapiHypervisor.find_all(): + x.delete() + print "Deleting all servers" + for x in ItopapiServer.find_all(): + x.delete() + print "Deleting all models" + for x in ItopapiModel.find_all(): + x.delete() + print "Deleting all brands" + for x in ItopapiBrand.find_all(): + x.delete() + print "Deleting all OS versions" + for x in ItopapiOSVersion.find_all(): + x.delete() + print "Deleting all OS families" + for x in ItopapiOSFamily.find_all(): + x.delete() + print "All done" + + +# Helper function to get read of None values +def xstr(s): + return u'' if s is None else (s if type(s) is unicode else unicode(s, "utf-8")) + + +# Global variables called here and there +itop_os_families = None +itop_os_versions = None +itop_farms = None +itop_hypervisors = None +itop_brands = None +itop_models = None +# Link between a Host in VCenter and a Farm in iTop +host_to_farm = {} + + +# Retrieve the os family or create it if it doesn't exist +def get_os_family(os_family_name): + if xstr(os_family_name) == "": + os_family_name = "Unknown" + + global itop_os_families + os_family = itop_os_families.get(os_family_name) + if os_family is None: + os_family = ItopapiOSFamily() + os_family.name = os_family_name + os_family.save() + itop_os_families[os_family_name] = os_family + return os_family + + +# Retrieve the os version or create it if it doesn't exist +def get_os_version(os_family, os_version_name): + if xstr(os_version_name) == "": + os_version_name = "Unknown" + + global itop_os_versions + os_version = itop_os_versions.get((os_family.instance_id, os_version_name)) + if os_version is None: + os_version = ItopapiOSVersion() + os_version.name = os_version_name + os_version.set_osfamily(os_family) + ret = os_version.save() + itop_os_versions[(os_family.instance_id, os_version.name)] = os_version + # print "Added new OS version %s" % os_version_name + return os_version + + +# Retrieve the brand or create it if it doesn't exist +def get_brand(brand_name): + if xstr(brand_name) == "": + brand_name = "Unknown" + + global itop_brands + itop_brand = itop_brands.get(brand_name) + if itop_brand is None: + itop_brand = ItopapiBrand() + itop_brand.name = brand_name + ret = itop_brand.save() + itop_brands[brand_name] = itop_brand + # print "Added new brand %s" % brand_name + return itop_brand + + +# Retrieve the model or create it if it doesn't exist +def get_model(brand, model_name, model_type): + if xstr(model_name) == "": + model_name = "Unknown" + + global itop_models + itop_model = itop_models.get((brand.instance_id, model_name)) + if itop_model is None: + itop_model = ItopapiModel() + itop_model.name = model_name + itop_model.type = model_type + itop_model.set_brand(brand) + itop_model.save() + itop_models[(brand.instance_id, model_name)] = itop_model + return itop_model + + +# Retrieve the virtualhost (Hypervisor or Farm) or create it if it doesn't exist +def get_virtualhost(virtualhost_name, organization): + if xstr(virtualhost_name) == "": + virtualhost_name = "Unknown" + + global itop_farms, itop_hypervisors + # Check if the virtualhost is a farm (shouldn't be directly) + itop_farm = itop_farms.get(virtualhost_name) + if itop_farm is not None: + return itop_farm + # Check if the virtualhost is an hypervisor + hypervisor = itop_hypervisors.get(virtualhost_name) + if hypervisor is not None: + # If the hypervisor is within a farm, then return the farm + itop_farm = itop_farms.get(hypervisor.farm_name) + if itop_farm is not None: + return itop_farm + else: + return hypervisor + # By default, create a farm and not an hypervisor. + # Maybe add a configuration option somewhere + itop_farm = ItopapiFarm() + itop_farm.name = virtualhost_name + # Set the organization + itop_farm.set_organization(organization) + itop_farm.save() + itop_farms[virtualhost_name] = itop_farm + return itop_farm + + +# Fill data of a VCenter's Cluster into an ItopapiFarm instance +# Return true if anything changed, else return false +def get_farm_params(itop_farm, vcenter_cluster, organization): + # Retrieve the relevant information from the cluster + + # Recall if there was a change in the params + has_changed = False + # Set the organization + if itop_farm.org_id != organization.instance_id: + has_changed = True + itop_farm.set_organization(organization) + # Set other fields + if itop_farm.name != vcenter_cluster.name: + has_changed = True + itop_farm.name = vcenter_cluster.name + # farm.status = "production" + return has_changed + + +# Fill data of a VCenter's Host into an ItopapiServer instance +# Return true if anything changed, else return false +def get_server_params(itop_server, vcenter_host, organization): + # Retrieve the relevant information from the host + summary = vcenter_host.summary + # config = summary.config + hardware = vcenter_host.hardware + product = vcenter_host.config.product + + # Recall if there was a change in the params + has_changed = False + # Set the management IP + management_ip = xstr(summary.managementServerIp) + if itop_server.managementip != management_ip: + has_changed = True + itop_server.managementip = management_ip + # Set the organization + if itop_server.org_id != organization.instance_id: + has_changed = True + itop_server.set_organization(organization) + # Set the OS family + os_family = get_os_family(product.name) + if itop_server.osfamily_id != os_family.instance_id: + has_changed = True + itop_server.set_osfamily(os_family) + # Set the OS version + os_version = get_os_version(os_family, product.fullName) + if itop_server.osversion_id != os_version.instance_id: + has_changed = True + itop_server.set_osversion(os_version) + # Set the brand + itop_brand = get_brand(summary.hardware.vendor) + if itop_server.brand_id != itop_brand.instance_id: + has_changed = True + itop_server.set_brand(itop_brand) + # Set the model + itop_model = get_model(itop_brand, summary.hardware.model, "Server") + if itop_server.model_id != itop_model.instance_id: + has_changed = True + itop_server.set_model(itop_model) + # Set other fields + cpu_count = int(hardware.cpuInfo.numCpuCores * hardware.cpuInfo.numCpuPackages) + if itop_server.name != vcenter_host.name \ + or int(itop_server.cpu) != cpu_count \ + or int(itop_server.ram) != int(hardware.memorySize / 1048576): + has_changed = True + itop_server.name = vcenter_host.name + itop_server.cpu = cpu_count + itop_server.ram = int(hardware.memorySize / 1048576) + + return has_changed + + +# Set params of an ItoapiHypervisor using data from the ItopapiServer. +# By convention, the hypervisor will have the same name. +def get_hypervisor_params(itop_hypervisor, itop_server): + global host_to_farm + # Set the organization. Same at the server's one + itop_hypervisor.org_id = itop_server.org_id + itop_hypervisor.org_id_friendlyname = itop_server.org_id_friendlyname + itop_hypervisor.organization_name = itop_server.organization_name + # Set the server + itop_hypervisor.server_id = itop_server.instance_id + itop_hypervisor.server_id_friendlyname = itop_server.friendlyname + itop_hypervisor.server_name = itop_server.name + # Set the farm if possible + itop_farm = host_to_farm.get(itop_server.name) + if itop_farm is not None: + itop_hypervisor.set_farm(itop_farm) + # Set other fields + itop_hypervisor.name = itop_server.name + + return itop_hypervisor + + +# Fill data of a VCenter's VirtualMachine into an ItopapiVirtualMachine instance +# Return true if anything changed, else return false +def get_vm_params(itop_vm, vcenter_vm, organization): + # Retrieve the relevant information from the virtual_machine + config = vcenter_vm.config + guest = vcenter_vm.guest + + summary_config = vcenter_vm.summary.config + os_family = get_os_family(summary_config.guestId) + os_version = get_os_version(os_family, summary_config.guestFullName) + host_name = vcenter_vm.runtime.host.name + virtualhost = get_virtualhost(host_name, organization) + + # Recall if there was a change in the params + has_changed = itop_vm.org_id != organization.instance_id \ + or itop_vm.osfamily_id != os_family.instance_id \ + or itop_vm.osversion_id != os_version.instance_id \ + or itop_vm.virtualhost_id != virtualhost.instance_id + # Set the organization + itop_vm.set_organization(organization) + # Set the OS family + itop_vm.set_osfamily(os_family) + # Set the OS version + itop_vm.set_osversion(os_version) + # Set the virtual host (Hypervisor or Farm) + itop_vm.set_virtualhost(virtualhost) + + # Set other fields + config_cpu = int(config.hardware.numCPU) + ip_address = xstr(guest.ipAddress) + + if itop_vm.name != vcenter_vm.name \ + or itop_vm.managementip != ip_address \ + or int(itop_vm.cpu) != config_cpu \ + or int(itop_vm.ram) != int(config.hardware.memoryMB): + has_changed = True + itop_vm.name = vcenter_vm.name + itop_vm.managementip = ip_address + itop_vm.cpu = config_cpu + itop_vm.ram = config.hardware.memoryMB + + # Set extra values as a JSON array inside the description field + current_desc = {} + try: + current_desc = json.loads(xstr(itop_vm.description)) + except ValueError as e: + pass + vcenter_hostname = xstr(vcenter_vm.guest.hostName) + if xstr(current_desc.get("hostname")) != vcenter_hostname: + has_changed = True + current_desc['hostname'] = vcenter_hostname + vcenter_annotation = xstr(vcenter_vm.config.annotation) + if xstr(current_desc.get("annotation")) != vcenter_annotation: + has_changed = True + current_desc['annotation'] = vcenter_annotation + + itop_vm.description = json.dumps(current_desc) + + return has_changed + + +def main(): + """ + Main function + """ + + global itop_farms, itop_hypervisors, host_to_farm, itop_brands, itop_models, itop_os_families, itop_os_versions + + ###################################### + # Load Itop & pyvmomi configuration # + ###################################### + try: + load_configuration_cli() + except NeedMoreArgs as e: + print "Error: {}".format(e.message) + exit(1) + + #################### + # Some value check # + #################### + if ItopapiConfig.username is None\ + or ItopapiConfig.password is None: + print "Error: Itop Username/Password missing" + exit(1) + + if ItopapiConfig.vcenter_username is None\ + or ItopapiConfig.vcenter_host is None\ + or ItopapiConfig.vcenter_port is None: + print "Error: VCenter Host/Port/Username missing" + exit(1) + + for m in ItopapiConfig.vcenter_vm_sync_mode: + if m not in ["add", "update", "delete"]: + print "Error: unsupported vm sync mode {}".format(m) + exit(1) + if ItopapiConfig.organization is None or ItopapiConfig.organization == "" \ + and "add" in ItopapiConfig.vcenter_vm_sync_mode: + print "Error: Default organization missing" + exit(1) + # Retrieve the default organization if need be + organization = None + if "add" in ItopapiConfig.vcenter_vm_sync_mode: + organization = ItopapiOrganization.find_by_name(ItopapiConfig.organization) + if organization is None: + print "Error: Default organization \"{}\"not found".format(ItopapiConfig.vcenter_vm_sync_mode) + exit(1) + + ############################### + # Connection to VCenter # + ############################### + ssl_context = None + if ItopapiConfig.vcenter_unsecure: + ssl_context = ssl._create_unverified_context() + + vcenter_content = None + try: + if xstr(ItopapiConfig.vcenter_password) == "": + ItopapiConfig.vcenter_password = getpass.getpass() + service_instance = connect.SmartConnect(sslContext=ssl_context, + host=ItopapiConfig.vcenter_host, + user=ItopapiConfig.vcenter_username, + pwd=ItopapiConfig.vcenter_password, + port=ItopapiConfig.vcenter_port) + atexit.register(connect.Disconnect, service_instance) + vcenter_content = service_instance.RetrieveContent() + except vmodl.MethodFault as error: + print("Caught vmodl fault : " + error.msg) + return -1 + + # cleanup() + + ######################## + # Get data from Itop # + ######################## + print "Retrieving existing data from iTop..." + # Retrieve existing Itop VMs + itop_farms = dict((farm.name, farm) for farm in ItopapiFarm.find_all()) + itop_hypervisors = dict((hypervisor.name, hypervisor) for hypervisor in ItopapiHypervisor.find_all()) + itop_vms = dict((vm.name, vm) for vm in ItopapiVirtualMachine.find_all()) + itop_servers = dict((server.name, server) for server in ItopapiServer.find_all()) + itop_os_families = dict((os_family.name, os_family) for os_family in ItopapiOSFamily.find_all()) + itop_os_versions = dict(((os_version.osfamily_id, os_version.name), os_version) for os_version in ItopapiOSVersion.find_all()) + itop_brands = dict((brand.name, brand) for brand in ItopapiBrand.find_all()) + itop_models = dict(((model.brand_id, model.name), model) for model in ItopapiModel.find({"type": "Server"})) + + ########################## + # Synchronize Clusters # + ########################## + print "Synchronizing VCenter Clusters with Itop Farms..." + # cluster_names will be used for deleting itop farms + cluster_names = set() + + # Get data from VCenter + # vim.ResourcePool, vim.ComputeResource, vim.ClusterComputeResource, vim. + container_view = vcenter_content.viewManager.CreateContainerView( + vcenter_content.rootFolder, [vim.ClusterComputeResource], True) + for vcenter_cluster in container_view.view: + cluster_name = vcenter_cluster.name + cluster_names.add(cluster_name) + itop_farm = itop_farms.get(cluster_name) + if itop_farm is not None: + if "update" in ItopapiConfig.vcenter_cluster_sync_mode: + has_changed = get_farm_params(itop_farm, vcenter_cluster, organization) + if has_changed: + ret = itop_farm.save() + if ret['code'] == 0: + print "Updated cluster %s" % cluster_name + else: + print "ERROR: cluster %s could not be updated. Check the return code below." % cluster_name + print ret + elif "add" in ItopapiConfig.vcenter_cluster_sync_mode: + itop_farm = ItopapiFarm() + get_farm_params(itop_farm, vcenter_cluster, organization) + ret = itop_farm.save() + if ret['code'] == 0: + print "Added cluster %s" % cluster_name + else: + print "ERROR: cluster %s could not be added. Check the return code below." % cluster_name + print ret + + # Fill the host_to_farm dict with this cluster's hosts + for host in vcenter_cluster.host: + host_to_farm[host.name] = itop_farm + if "delete" in ItopapiConfig.vcenter_cluster_sync_mode: + for farm_name in itop_farms.keys(): + if farm_name not in cluster_names: + ret = itop_farms[farm_name].delete() + itop_farms.pop(farm_name) + if ret['code'] == 0: + print "Deleted cluster %s" % farm_name + else: + print "ERROR: cluster %s could not be deleted. Check the return code below." % farm_name + print ret + + ####################### + # Synchronize Hosts # + ####################### + print "Synchronizing VCenter Hosts with Itop Servers..." + # host_names will be used for deleting itop servers + host_names = set() + + # Get data from VCenter + container_view = vcenter_content.viewManager.CreateContainerView( + vcenter_content.rootFolder, [vim.HostSystem], True) + for vcenter_host in container_view.view: + host_name = vcenter_host.name + host_names.add(host_name) + itop_server = itop_servers.get(host_name) + if itop_server is not None: + if "update" in ItopapiConfig.vcenter_host_sync_mode: + has_changed = get_server_params(itop_server, vcenter_host, organization) + if has_changed: + ret = itop_server.save() + if ret['code'] == 0: + print "Updated server %s" % host_name + else: + print "ERROR: server %s could not be updated. Check the return code below." % host_name + print ret + elif "add" in ItopapiConfig.vcenter_host_sync_mode: + # Create the Server and Hypervisor + itop_server = ItopapiServer() + get_server_params(itop_server, vcenter_host, organization) + ret = itop_server.save() + if ret['code'] == 0: + itop_servers[itop_server.name] = itop_server + itop_hypervisor = ItopapiHypervisor() + get_hypervisor_params(itop_hypervisor, itop_server) + ret = itop_hypervisor.save() + if ret['code'] == 0: + itop_hypervisors[itop_hypervisor.name] = itop_hypervisor + print "Added server %s" % host_name + else: + print "ERROR: hypervisor %s could not be created. Check the return code below." % host_name + else: + print "ERROR: server %s could not be created. Check the return code below." % host_name + print ret + if "delete" in ItopapiConfig.vcenter_host_sync_mode: + for server_name in itop_servers.keys(): + if server_name not in host_names: + ret = itop_servers[server_name].delete() + itop_servers.pop(server_name) + if ret['code'] == 0: + print "Deleted server %s" % server_name + else: + print "ERROR: server %s could not be deleted. Check the return code below." % server_name + print ret + + + ##################### + # Synchronize VMS # + ##################### + print "Synchronizing VCenter VMs with Itop..." + # vm_names will be used for deleting itop vms + vm_names = set() + + # Get data from VCenter + container_view = vcenter_content.viewManager.CreateContainerView( + vcenter_content.rootFolder, [vim.VirtualMachine], True) + for vcenter_vm in container_view.view: + # Do not take templates into consideration + if vcenter_vm.config.template: + continue + + vm_name = vcenter_vm.name + vm_names.add(vm_name) + itop_vm = itop_vms.get(vm_name) + if itop_vm is not None: + if "update" in ItopapiConfig.vcenter_vm_sync_mode: + has_changed = get_vm_params(itop_vm, vcenter_vm, organization) + if has_changed: + ret = itop_vm.save() + if ret['code'] == 0: + print "Updated VM %s" % vm_name + else: + print "ERROR: VM %s could not be updated. Check the return code below." % vm_name + print ret + elif "add" in ItopapiConfig.vcenter_vm_sync_mode: + itop_vm = ItopapiVirtualMachine() + get_vm_params(itop_vm, vcenter_vm, organization) + ret = itop_vm.save() + if ret['code'] == 0: + itop_vms[itop_vm.name] = itop_vm + print "Added VM %s" % vm_name + else: + print "ERROR: VM %s could not be created. Check the return code below." % vm_name + print ret + if "delete" in ItopapiConfig.vcenter_vm_sync_mode: + for vm_name in itop_vms.keys(): + if vm_name not in vm_names: + ret = itop_vms[vm_name].delete() + if ret['code'] == 0: + print "Deleted VM %s" % vm_name + else: + print "ERROR: VM %s could not be deleted. Check the return code below." % vm_name + print ret + + return 0 + + +if __name__ == "__main__": + main()