def luna_otherdev_present(data): data.pop('state') name = data.pop('name') changed = False ret = True if not data['connected']: err_msg = ("Need to specify at least one IP and network " + "device is connected to") return True, changed, err_msg if 'network' not in data['connected'][0]: err_msg = ("Network to which device is connected " + "needs to be specified") return True, changed, err_msg if 'ip' not in data['connected'][0]: err_msg = ("IP of the device " + "needs to be specified") return True, changed, err_msg try: otherdev = luna.OtherDev(name=name) except RuntimeError: args = { 'name': name, 'create': True, 'network': data['connected'][0]['network'], 'ip': data['connected'][0]['ip'], } otherdev = luna.OtherDev(**args) changed = True if (data['comment'] is not None and data['comment'] != otherdev.get('comment')): otherdev.set('comment', data['comment']) changed = True ansible_nets = {} for elem in data['connected']: if elem['network'] in ansible_nets: err_msg = ('Network {} specified multiple times'.format( elem[elem['network']])) return True, changed, err_msg ansible_nets[elem['network']] = elem['ip'] configured_nets = otherdev.list_nets() del_nets = [n for n in configured_nets if n not in ansible_nets] for net in del_nets: ret &= otherdev.del_net(net) changed = True for net in ansible_nets: ip = ansible_nets[net] if otherdev.get_ip(net) != ip: ret &= otherdev.set_ip(net, ip) changed = True return not ret, changed, str(otherdev)
def luna_otherdev_absent(data): name = data['name'] try: otherdev = luna.OtherDev(name=name) except RuntimeError: return False, False, name return not otherdev.delete(), True, name
def setUp( self, mock_rpm_addmacro, mock_rpm_transactionset, ): print packages = [ { 'VERSION': '3.10', 'RELEASE': '999-el0', 'ARCH': 'x86_64' }, ] mock_rpm_transactionset.return_value.dbMatch.return_value = packages self.sandbox = Sandbox() self.db = self.sandbox.db self.path = self.sandbox.path self.cluster = luna.Cluster(mongo_db=self.db, create=True, path=self.path, user=getpass.getuser()) self.osimage = luna.OsImage(name='testosimage', path=self.path, mongo_db=self.db, create=True) self.group = luna.Group(name='testgroup', osimage=self.osimage.name, mongo_db=self.db, interfaces=['eth0'], create=True) self.net11 = luna.Network(name='net11', NETWORK='10.11.0.0', PREFIX=16, mongo_db=self.db, create=True) self.net11.set('ns_hostname', 'master') self.net61 = luna.Network(name='net61', NETWORK='fe90::', PREFIX=64, mongo_db=self.db, create=True) self.net61.set('ns_hostname', 'master') self.group.set_net_to_if('eth0', self.net11.name) self.group.set_net_to_if('eth0', self.net61.name) self.group = luna.Group(name=self.group.name, mongo_db=self.db) self.node = luna.Node(group=self.group.name, mongo_db=self.db, create=True) self.switch = luna.Switch(name='sw01', network=self.net11.name, mongo_db=self.db, create=True) self.switch.set('ip', '10.11.1.1') self.otherdev = luna.OtherDev(name='pdu01', network=self.net11.name, ip="10.11.2.1", mongo_db=self.db, create=True) self.net11 = luna.Network(name=self.net11.name, mongo_db=self.db) self.node = luna.Node(name=self.node.name, mongo_db=self.db) self.group = luna.Group(name=self.group.name, mongo_db=self.db)
#!/usr/bin/env python import luna od = luna.OtherDev(name="testdev01", create=True, network='ipmi', ip='10.31.0.10') #od = luna.OtherDev(name = "testdev01", create = True) #od = luna.OtherDev(name = "testdev01") print od.get_ip('ipmi') od.set_ip('ipmi', '10.31.0.20') print od.get_ip('ipmi') od.set_ip('ipmi') od.set_ip('ipmi', '10.31.0.30') print od.get_ip('ipmi') #od.del_net('ipmi') #od.delete()