Пример #1
0
 def build_entity(self):
     return otypes.Agent(
         address=self._module.params['address'],
         encrypt_options=self._module.params['encrypt_options'],
         options=[
             otypes.Option(
                 name=name,
                 value=value,
             ) for name, value in self._module.params['options'].items()
         ] if self._module.params['options'] else None,
         password=self._module.params['password'],
         port=self._module.params['port'],
         type=self._module.params['type'],
         username=self._module.params['username'],
         order=self._module.params.get('order', 100),
     )
Пример #2
0
 def build_entity(self):
     last = next((s for s in sorted([a.order for a in self._service.list()])), 0)
     order = self.param('order') if self.param('order') is not None else self.entity.order if self.entity else last + 1
     return otypes.Agent(
         address=self._module.params['address'],
         encrypt_options=self._module.params['encrypt_options'],
         options=[
             otypes.Option(
                 name=name,
                 value=value,
             ) for name, value in self._module.params['options'].items()
         ] if self._module.params['options'] else None,
         password=self._module.params['password'],
         port=self._module.params['port'],
         type=self._module.params['type'],
         username=self._module.params['username'],
         order=order,
     )
# The host may have multiple fencing agents, so we need to locate the
# first of type 'ipmilan':
agents = agents_service.list()
agent = next(x for x in agents if x.type == 'ipmilan')

# Get the options of the fencing agent. There may be no options, in that
# case we need to use an empty list:
original = agent.options
if original is None:
    original = []

# Create a list of modified options, containing all the original options
# except the one with the name that we want to modify, as we will add that
# with the right value later:
modified = [x for x in original if x.name != name]

# Add the modified option to the list of modified options:
option = types.Option(name=name, value=value)
modified.append(option)

# Find the service that manages the fence agent:
agent_service = agents_service.agent_service(agent.id)

# Send the update request containg the original list of options plus the
# modifications that we did:
agent_service.update(agent=types.Agent(options=modified))

# Close the connection to the server:
connection.close()
Пример #4
0
# Find the host:
hosts_service = connection.system_service().hosts_service()
host = hosts_service.list(search='name=myhost')[0]
host_service = hosts_service.host_service(host.id)

# Using fence agent service of the host, add ipmilan fence
# agent:
fence_agents_service = host_service.fence_agents_service()
fence_agents_service.add(
    types.Agent(
        address='1.2.3.4',
        type='ipmilan',
        username='******',
        password='******',
        options=[
            types.Option(
                name='myname',
                value='myvalue',
            ),
        ],
        order=0,
    ))

# Prepare the update host object:
host_update = types.Host()

# If power management isn't enabled, enable it. Note that
# power management can be enabled only if at least one fence
# agent exists for host:
if not host.power_management.enabled:
    host_update.power_management = types.PowerManagement(enabled=True)