def test_getid(self): self.assertEqual(base.getid(4), 4) class TmpObject(object): id = 4 self.assertEqual(base.getid(TmpObject), 4)
def _handle_vlan(self, server, vlan_id, vlan_type, nics=[], unset=False, **kwargs): """ Set/Unset tagged/untagged vlan id for the server. :param server: The :class:`Server` (or its ID) to power on. :param vlan_id: The tagged vlan id for the server. :param vlan_type: tagged-vlan or untagged-vlan type. :param unset: Boolean flag to unset the vlan_id for the server. """ if vlan_id is not None: action_params = {} if unset: action_params.update({'remove': vlan_id}) else: action_params.update({'add': vlan_id}) self.run_hooks('modify_body_for_action', action_params, **kwargs) if nics: for nic in nics: url = '/servers/%s/nic/%s/%s' % (base.getid(server), nic[3:], vlan_type) self.api.client.put(url, body=action_params) return else: u = '/servers/%s/nic' % (base.getid(server)) nics = self._list(u) for nic in nics: url = '/servers/%s/nic/%s/%s' % (base.getid(server), nic.id, vlan_type) self.api.client.put(url, body=action_params) return
def get(self, scard, **kwargs): """ Get a specific scard. :rtype: Instance of :class:`Scard` """ return self._get(base.getid(scard), '/chassis/scard/%s' % base.getid(scard))
def get(self, server): """ Get a server. :param server: ID of the :class:`Server` to get. :rtype: :class:`Server` """ return self._get(base.getid(server), "/servers/%s" % base.getid(server))
def get(self, fantray): """ Get a fantray. :param fantray: ID of the :class:`FanTray` to get. :rtype: :class:`FanTray` """ return self._get(base.getid(fantray), "/chassis/fanTray/%s" % base.getid(fantray))
def get(self, interface): """ Get a interface. :param interface: ID of the :class:`Interface` to get. :rtype: :class:`Interface` """ return self._get(base.getid(interface), "/interfaces/%s" % base.getid(interface))
def get(self, pool): """ Get a pool. :param pool: ID of the :class:`Pool` to get. :rtype: :class:`Pool` """ return self._get(base.getid(pool), "/storage/pools/%s" % base.getid(pool))
def get(self, powersupply): """ Get a powersupply. :param powersupply: ID of the :class:`PowerSupply` to get. :rtype: :class:`PowerSupply` """ return self._get(base.getid(powersupply), "/chassis/powersupply/%s" % base.getid(powersupply))
def get(self, disk): """ Get a disk. :param disk: ID of the :class:`Disk` to get. :rtype: :class:`Disk` """ return self._get(base.getid(disk), "/storage/disks/%s" % base.getid(disk))
def get(self, smcard): """ Get a smcard. :param smcard: ID of the :class:`SMCard` to get. :rtype: :class:`SMCard` """ return self._get(base.getid(smcard), "/chassis/smcard/%s" % base.getid(smcard))
def get(self, volume): """ Get a volume. :param volume: ID of the :class:`Volume` to get. :rtype: :class:`Volume` """ return self._get(base.getid(volume), "/storage/volumes/%s" % base.getid(volume))
def set_management_mode(self, scard, mode, force=False, **kwargs): """ Set management mode of the specified scard """ url = "/chassis/scard/%s/mgmtMode" % base.getid(scard) body = {'value': mode} return self.api.client.put(url, body=body)
def deactivate_led(self, disk, **kwargs): """ De-activate LED of the specified Disk """ url = "/storage/disks/%s" % base.getid(disk) body = {'action': 'deactivate-led'} return self.api.client.put(url, body=body)
def power_on(self, disk, **kwargs): """ Power on the specified Disk """ url = "/storage/disks/%s" % base.getid(disk) body = {'action': 'power-on'} return self.api.client.put(url, body=body)
def add_untagged_vlan(self, interface, vlan_id, **kwargs): """ Add untagged vlan for the given Interface """ url = '/interfaces/%s/vlans/untaggedVlans' % base.getid(interface) body = {'add': str(vlan_id)} return self.api.client.put(url, body=body)
def remove_tagged_vlan(self, interface, vlan_id, **kwargs): """ Remove tagged vlan for the given Interface """ url = '/interfaces/%s/vlans/taggedVlans' % base.getid(interface) body = {'remove': str(vlan_id)} return self.api.client.put(url, body=body)
def no_shutdown(self, interface, **kwargs): """ Start the specified network Interface """ url = "/interfaces/%s/shutdown" % base.getid(interface) body = {'value': False} return self.api.client.put(url, body=body)
def _action(self, action, pool, info=None, **kwargs): """ Perform a pool "action" -- . """ body = {"action": action} self.run_hooks('modify_body_for_action', body, **kwargs) url = '/storage/pools/%s' % base.getid(pool) return self.api.client.put(url, body=body)
def _action(self, action, server, info=None, **kwargs): """ Perform a server "action" -- power-on/power-off/reset/etc. """ body = {"action": action} body.update(info) self.run_hooks('modify_body_for_action', body, **kwargs) url = '/servers/%s' % base.getid(server) return self.api.client.put(url, body=body)
def _action(self, action, volume, info=None, **kwargs): """ Perform a volume "action" -- . """ body = {"action": action} body.update(info) self.run_hooks('modify_body_for_action', body, **kwargs) url = '/storage/volumes/%s' % base.getid(volume) return self.api.client.put(url, body=body)
def create(self, slot, pool_name, disks, raid_level=0, **kwargs): """ Create a pool on the given scard slot using disks of that slot. :rtype: Instance of :class:`Pool` """ disks = map(lambda x: str(x), disks) body = {'disks': ','.join(disks), 'raidLevel': raid_level} url = '/storage/pools/%s/%s' % (base.getid(slot), pool_name) return self.api.client.put(url, body=body)
def detach_volume(self, server, vdisk=0, **kwargs): """ Detach volume attached to vdisk # of given server :param server: The :class:`Server` (or its ID) to power on. :param vdisk: The vdisk number of the server to detach volume to. : """ url = '/servers/%s/vdisk/%s' % (base.getid(server), vdisk) return self._delete(url)
def add_tagged_vlan(self, interface, vlan_id, **kwargs): """ Add tagged vlan for the given Interface """ url = '/interfaces/%s/vlans/taggedVlans' % base.getid(interface) if isinstance(vlan_id, list): vlan_id = map(lambda x: str(x), vlan_id) body = {'add': ','.join(vlan_id)} else: body = {'add': str(vlan_id)} return self.api.client.put(url, body=body)
def power_off(self, server, force=False, **kwargs): """ Power off a server. :param server: The :class:`Server` (or its ID) to power off. :param force: force the server to power off. """ action = 'power-off' url = '/servers/%s?action=%s' % (base.getid(server), action) if force: url = '%s&force=true' % url return self.api.client.put(url, body={})
def attach_volume(self, server, volume, vdisk=0, **kwargs): """ Attach volume to vdisk # to given server :param server: The :class:`Server` (or its ID) to power on. :param volume: The :class:`Volume` (or its ID) that is to be attached. :param vdisk: The vdisk number of the server to attach volume to. : """ body = {"value": volume} self.run_hooks('modify_body_for_action', body, **kwargs) url = '/servers/%s/vdisk/%s' % (base.getid(server), vdisk) return self.api.client.put(url, body=body)
def create(self, size, pool, volume_id=None, **kwargs): """ Create a volume of the given size in the given pool. :param volume_id: ID of the :class: `Volume` to create :param pool: Object of the :class: `Pool` in which the volume will be created. :param size: Size of the new volume in GB. """ create_params = {} if volume_id is None: volume_id = str(binascii.b2a_hex(os.urandom(6))) if pool and volume_id and size: create_params = {'volume-size': str(size)} resource_url = "%s/%s" % (base.getid(pool), volume_id) return self._create(resource_url, create_params)
def delete(self, volume): self._delete("/storage/volume/%s" % base.getid(volume))
def delete(self, pool, **kwargs): """ Delete the specified pool. """ url = '/storage/pools/%s' % base.getid(pool) return self.api.client.delete(url)
def get_boot_order(self, server): url = '/server/%s/bios/bootOrder' % base.getid(server) ret,val = self.api.client.get(url) return (ret , val.split(" ")[0])