def set_vlan_and_set_ips(self): '''This function will set the the Vlan''' vlan = "" if self.subnet.split('/')[1] == '29': vlan = "280" for i in range(4): dcim_s_r.sendRecieveDCIM( "iplist.edit", { "sok": "ok", "plid": self.plid, "iptype": "public", "family": "ipv4" }) #clicked_button=ok&domain=free.ds&family=ipv4&func=iplist.edit&ip=&iptype=public&operafake=1503243155750&plid=156&progressid=false&selected_ip_type=public&sfrom=ajax&sok=ok&zoom-ip=' #dcim_s_r.sendRecieveDCIM("iplist",{"elid": self.plid, "sok": "ok", "elname": self.serverName}) elif self.subnet.split('/')[1] == '30': vlan = "282" if vlan != None: dcim_s_r.sendRecieveDCIM("switch.port.edit", { "elid": self.portId, "vlan": vlan, "sok": "ok" })
def add_ipmi(self): #"clicked_button=finish&devtype=dev%5Fipmi&func=server.connection.connwizipmi&hfields=intel%5Famt&ip=68.64.173.125&ipmi=ipmi%5Flanplus&ipmipass=freefromwg40&ipmiproxy=off&ipmiuser=root&operafake=1502880698570&plid=127&progressid=false&service=off&sfrom=ajax&sok=ok&web_u dcim_s_r.sendRecieveDCIM( "server.connection.connwizipmi", { "sok": "ok", "plid": self.plid, "ip": self.ipmiIp, "ipmi": "ipmi_lanplus", "ipmiuser": self.ipmiUser, "ipmipass": self.ipmiPassword, "devtype": "dev_ipmi" })
def get_plid(self): '''we we need it to set connections ''' serverList = dcim_s_r.sendRecieveDCIM("server", {}) for server in serverList: if server["name"] == self.serverName: plid = server["id"] return plid
def add_connections(self): ''' This function will add a connection between the server and the switch ''' switches = dcim_s_r.sendRecieveDCIM("switch", {}) switchId = list( filter((lambda x: x if x['ip'] == self.switchIP else None), switches))[0]['id'] ports = dcim_s_r.sendRecieveDCIM("switch.port", {"elid": switchId}) portId = list( filter((lambda x: x if x['descr'] == self.switchPort else None), ports))[0]['id'] dcim_s_r.sendRecieveDCIM( "server.connection.connwizport", { "plid": self.plid, "port": portId, "devtype": "switch", "switch": switchId, "sok": "ok" }) return switchId, portId
def add_server(self): #pass if self.serverName[-2:-1].isalpha(): unit = self.serverName[-1:] else: unit = self.serverName[-2:] #blade_slot=&chassis_ram=&chassistempl=2&clicked_button=ok&cpu_0=null&cpu_count=1&family=ipv4&forcelock=off&func=server.edit&hdd_0=null&hdd_1=null&hdd_10=null&hdd_11=null&hdd_12=null&hdd_13=null&hdd_14=null&hdd_15=null&hdd_16=null&hdd_17=null&hdd_18=null&hdd_19=null&hdd_2=null&hdd_20=null&hdd_21=null&hdd_22=null&hdd_23=null&hdd_24=null&hdd_25=null&hdd_26=null&hdd_27=null&hdd_28=null&hdd_29=null&hdd_3=null&hdd_4=null&hdd_5=null&hdd_6=null&hdd_7=null&hdd_8=null&hdd_9=null&hostname=free.ds&hwproblem=off&ip_block=public&is_blade2=&is_multinode2=&mac=00%3A26%3A9E%3AB5%3AE7%3A16&name=710A14R10¬es=&operafake=1502736475316&owner=no%5Fowner&parent_chassis=no%5Fowner&pci_0=null&pci_1=null&pci_2=null&pci_3=null&pci_4=null&pci_5=null&pci_6=null&progressid=false&rack=1&sfrom=ajax&sizefromtype2=on&sok=ok&specialip=&srvsize2=&srvtypesize2=1&unit2=10' dcim_s_r.sendRecieveDCIM( "server.edit", { "chassistempl": self.serverTypeId, "family": "ipv4", "hostname": self.hostname, "mac": self.mac, "name": self.serverName, "rack": self.serverRackId, "unit": unit, "unit2": unit, "sok": "ok" }) ''' please be careful with "self.serverName[-2:]" it does not suprt blades '''
def print_server_types(self): '''This function return servers types ids and their descriptions''' serverTypesFull = dcim_s_r.sendRecieveDCIM("chassistempl", {}) serverTypesReduced = [] for s in serverTypesFull: temp = ["", ""] temp[0], temp[1] = s["id"], s["name"] if temp not in serverTypesReduced: serverTypesReduced.append(temp) return serverTypesReduced
def get_cabinet_id(self): racks = dcim_s_r.sendRecieveDCIM("rack", {}) switches = dcim_s_r.sendRecieveDCIM("switch", {}) cabinetId = list( filter((lambda x: x if x['ip'] == self.switchIP else None), switches))[0]['rack_id'] ##FIX ME ''' if re.match(self.sevenThFloor,self.serverName): cabinetName = self.serverName[0:(len(self.serverName) -3)] elif self.serverName[1] == '0' and not self.serverName[2].isalpha(): cabinetName = "510" + self.serverName[0:3] else: cabinetName = "510" + self.serverName[0:2] for rack in racks: if rack["name"] == cabinetName: cabinetId = rack["id"] ''' return cabinetId
def add_subnet(self): ''' This method will add subnet to DCIM''' if re.match(self.cidr, self.subnet): print( dcim_s_r.sendRecieveDCIM( "ipdb.edit", { "range": self.subnet, "netmask": calc(self.subnet)[3], "gateway": calc(self.subnet)[1], "sok": "ok" })) else: print("You didn't enter the propper CIDR") exit()