예제 #1
0
def do_remotelogging_modify(cc, args):
    """Modify Remote Logging attributes."""

    remoteloggings = cc.remotelogging.list()
    remotelogging = remoteloggings[0]

    attributes = []
    if args.ip_address is not None:
        attributes.append('ip_address=%s' % args.ip_address)
    if args.enabled is not None:
        attributes.append('enabled=%s' % args.enabled)
    if args.transport is not None:
        attributes.append('transport=%s' % args.transport)
    if args.port is not None:
        attributes.append('port=%s' % args.port)
    if args.key_file is not None:
        attributes.append('key_file=%s' % args.key_file)
    if len(attributes) > 0:
        attributes.append('action=apply')
    else:
        print("No options provided.")
        return

    patch = utils.args_array_to_patch("replace", attributes)

    try:
        remotelogging = cc.remotelogging.update(remotelogging.uuid, patch)
    except exc.HTTPNotFound:
        raise exc.CommandError('remotelogging not found: %s' %
                               remotelogging.uuid)

    _print_remotelogging_show(remotelogging)
예제 #2
0
def do_ptp_modify(cc, args):
    """Modify PTP attributes."""

    ptps = cc.ptp.list()
    ptp = ptps[0]
    op = "replace"

    attributes = []

    if args.mode is not None:
        attributes.append('mode=%s' % args.mode)
    if args.transport is not None:
        attributes.append('transport=%s' % args.transport)
    if args.mechanism is not None:
        attributes.append('mechanism=%s' % args.mechanism)
    if len(attributes) == 0:
        print("No options provided.")
        return

    patch = utils.args_array_to_patch("replace", attributes)
    try:
        ptp = cc.ptp.update(ptp.uuid, patch)
    except exc.HTTPNotFound:
        raise exc.CommandError('PTP not found: %s' % ptp.uuid)

    _print_ptp_show(ptp)
예제 #3
0
def do_ntp_modify(cc, args):
    """Modify NTP attributes."""

    intps = cc.intp.list()
    intp = intps[0]
    op = "replace"

    if args.enabled is not None:
        args.attributes[0].append('enabled=%s' % args.enabled)

    for attribute in args.attributes:
        if 'ntpservers=' in attribute:
            ntpservers = attribute[0].split('=')[1]
            if not ntpservers.strip():
                args.attributes[0][0] = 'ntpservers=NC'

    # We need to apply the manifests
    if not any('action=' in att for att in args.attributes[0]):
        args.attributes[0].append('action=apply')

    patch = utils.args_array_to_patch(op, args.attributes[0])
    try:
        intp = cc.intp.update(intp.uuid, patch)
    except exc.HTTPNotFound:
        raise exc.CommandError('NTP not found: %s' % intp.uuid)

    _print_intp_show(intp)
def donot_service_modify_lab(cc, args):
    """LAB ONLY Update a service. """
    # JKUNG comment this out prior to delivery
    patch = utils.args_array_to_patch("replace", args.attributes[0])
    try:
        iservice = cc.iservice.update(args.iservice, patch)
    except exc.HTTPNotFound:
        raise exc.CommandError('Service not found: %s' % args.iservice)
    _print_iservice_show(iservice)
예제 #5
0
def do_host_update(cc, args):
    """Update host attributes."""
    patch = utils.args_array_to_patch("replace", args.attributes[0])
    ihost = ihost_utils._find_ihost(cc, args.hostnameorid)
    try:
        ihost = cc.ihost.update(ihost.id, patch)
    except exc.HTTPNotFound:
        raise exc.CommandError('host not found: %s' % args.hostnameorid)
    _print_ihost_show(ihost)
def donot_servicegroup_modify_labonly(cc, args):
    """LAB ONLY Update a servicegroup. """
    # JKUNG comment this out prior to delivery
    patch = utils.args_array_to_patch("replace", args.attributes[0])
    try:
        iservicegroup = cc.smapiClient.iservicegroup.update(
            args.iservicegroup, patch)
    except exc.HTTPNotFound:
        raise exc.CommandError('Service Group not found: %s' %
                               args.iservicegroup)
    _print_iservicegroup_show(iservicegroup)
예제 #7
0
def do_host_power_off(cc, args):
    """Power off a host."""
    attributes = []
    attributes.append('action=power-off')
    patch = utils.args_array_to_patch("replace", attributes)
    ihost = ihost_utils._find_ihost(cc, args.hostnameorid)
    try:
        ihost = cc.ihost.update(ihost.id, patch)
    except exc.HTTPNotFound:
        raise exc.CommandError('host not found: %s' % args.hostnameorid)
    _print_ihost_show(ihost)
예제 #8
0
def donot_user_modify(cc, args):
    """Modify USER attributes."""

    iusers = cc.iuser.list()
    iuser = iusers[0]

    patch = utils.args_array_to_patch("replace", args.attributes[0])
    try:
        iuser = cc.iuser.update(iuser.uuid, patch)
    except exc.HTTPNotFound:
        raise exc.CommandError('USER not found: %s' % iuser.uuid)

    _print_iuser_show(iuser)
예제 #9
0
 def test_args_array_to_patch_remove(self):
     my_args = {
         'attributes': ['/foo', 'extra/bar'],
         'op': 'remove',
     }
     patch = utils.args_array_to_patch(my_args['op'], my_args['attributes'])
     self.assertEqual(patch, [{
         'op': 'remove',
         'path': '/foo'
     }, {
         'op': 'remove',
         'path': '/extra/bar'
     }])
예제 #10
0
 def test_args_array_to_patch(self):
     my_args = {
         'attributes': ['foo=bar', '/extra/bar=baz'],
         'op': 'add',
     }
     patch = utils.args_array_to_patch(my_args['op'], my_args['attributes'])
     self.assertEqual(patch, [{
         'op': 'add',
         'value': 'bar',
         'path': '/foo'
     }, {
         'op': 'add',
         'value': 'baz',
         'path': '/extra/bar'
     }])
def do_host_sensorgroup_modify(cc, args):
    """Modify sensor group of a host."""

    ihost = ihost_utils._find_ihost(cc, args.hostnameorid)

    sensorgroup = _find_sensorgroup(cc, ihost, args.sensorgroup_uuid)

    patch = utils.args_array_to_patch("replace", args.attributes[0])

    try:
        isensorgroup = cc.isensorgroup.update(sensorgroup.uuid, patch)
    except exc.HTTPNotFound:
        raise exc.CommandError(
            "Sensor update failed: host %s sensorgroup %s :"
            " update %s" % (args.hostnameorid, args.sensorgroup_uuid, patch))

    _print_isensorgroup_show(isensorgroup)
예제 #12
0
def do_host_swact(cc, args):
    """Switch activity away from this active host."""
    attributes = []

    if args.force is True:
        # Forced swact operation
        attributes.append('action=force-swact')
    else:
        # Normal swact operation
        attributes.append('action=swact')

    patch = utils.args_array_to_patch("replace", attributes)
    ihost = ihost_utils._find_ihost(cc, args.hostnameorid)
    try:
        ihost = cc.ihost.update(ihost.id, patch)
    except exc.HTTPNotFound:
        raise exc.CommandError('host not found: %s' % args.hostnameorid)
    _print_ihost_show(ihost)
예제 #13
0
def do_host_unlock(cc, args):
    """Unlock a host."""
    attributes = []

    if args.force is True:
        # Forced unlock operation
        attributes.append('action=force-unlock')
    else:
        # Normal unlock operation
        attributes.append('action=unlock')

    patch = utils.args_array_to_patch("replace", attributes)
    ihost = ihost_utils._find_ihost(cc, args.hostnameorid)
    try:
        ihost = cc.ihost.update(ihost.id, patch)
    except exc.HTTPNotFound:
        raise exc.CommandError('host not found: %s' % args.hostnameorid)
    _print_ihost_show(ihost)
예제 #14
0
def do_infra_apply(cc, args):
    infras = cc.iinfra.list()
    if not infras:
        print("Infrastructure network not configured")
        return

    infra = infras[0]

    patch = utils.args_array_to_patch("replace", ['action=apply'])
    try:
        cc.iinfra.update(infra.uuid, patch)
        print("\nApplying infrastructure network configuration to active "
              "controller.\n"
              "Please wait for configuration to be applied before unlocking "
              "additional hosts.\n")
    except exc.HTTPNotFound:
        raise exc.CommandError('Infrastructure network not found: %s' %
                               infra.uuid)
def do_dns_modify(cc, args):
    """Modify DNS attributes."""

    idnss = cc.idns.list()
    idns = idnss[0]
    op = "replace"

    for attribute in args.attributes:
        if 'nameservers=' in attribute:
            nameservers = attribute[0].split('=')[1]
            if not nameservers.strip():
                args.attributes[0][0] = 'nameservers=NC'

    if not any('action=' in att for att in args.attributes[0]):
        args.attributes[0].append('action=apply')

    patch = utils.args_array_to_patch(op, args.attributes[0])
    try:
        idns = cc.idns.update(idns.uuid, patch)
    except exc.HTTPNotFound:
        raise exc.CommandError('DNS not found: %s' % idns.uuid)

    _print_idns_show(idns)
예제 #16
0
def do_oam_modify(cc, args):
    """Modify external OAM attributes."""

    iextoams = cc.iextoam.list()

    iextoam = iextoams[0]

    if cc.isystem.list()[0].system_mode == constants.SYSTEM_MODE_SIMPLEX:
        for i, elem in enumerate(args.attributes[0]):
            path, value = elem.split("=", 1)
            if path == 'oam_ip':
                args.attributes[0][i] = 'oam_floating_ip=' + value
            if path in ['oam_floating_ip', 'oam_c0_ip', 'oam_c1_ip']:
                raise exc.CommandError('%s is not supported on '
                                       'a simplex system' % path)

    patch = utils.args_array_to_patch("replace", args.attributes[0])
    try:
        iextoam = cc.iextoam.update(iextoam.uuid, patch)
    except exc.HTTPNotFound:
        raise exc.CommandError('OAM IP not found: %s' % iextoam.uuid)

    _print_iextoam_show(iextoam, cc)
def do_ceph_mon_modify(cc, args):
    controller = vars(args).get('controller', None)
    patch = utils.args_array_to_patch("replace", args.attributes[0])
    patch.append({'op': 'replace', 'path': '/controller', 'value': controller})

    # Obtain the host whose ceph monitor we want to modify.
    ihost = ihost_utils._find_ihost(cc, controller)
    ceph_mon = cc.ceph_mon.list(ihost.uuid)[0]

    changes = dict(v.split("=", 1) for v in args.attributes[0])
    if changes.get('ceph_mon_gib', None) and \
            changes['ceph_mon_gib'] != getattr(ceph_mon, 'ceph_mon_gib'):

        for ceph_mon in cc.ceph_mon.list():
            cc.ceph_mon.update(ceph_mon.uuid, patch)
        _print_ceph_mon_list(cc)
        print "\nNOTE: ceph_mon_gib for both controllers are changed."
    else:
        ceph_mon = cc.ceph_mon.update(ceph_mon.uuid, patch)
        _print_ceph_mon_show(ceph_mon)

    print "\nSystem configuration has changed.\nplease follow the " \
          "administrator guide to complete configuring system.\n"
예제 #18
0
def do_infra_modify(cc, args):
    """Modify infrastructure network IP attributes."""

    iinfras = cc.iinfra.list()
    if not iinfras:
        print("Infrastructure network not configured")
        return

    iinfra = iinfras[0]

    # caused by the split on parameters without a '='
    for entry in args.attributes[0]:
        if (entry.count("=") != 1):
            raise exc.CommandError('infra-modify parameters must be '
                                   'of the form property=value')

    patch = utils.args_array_to_patch("replace", args.attributes[0])
    try:
        iinfra = cc.iinfra.update(iinfra.uuid, patch)
    except exc.HTTPNotFound:
        raise exc.CommandError('Infrastructure network not found: %s' %
                               iinfra.uuid)

    _print_iinfra_show(iinfra)
예제 #19
0
def do_drbdsync_modify(cc, args):
    """Modify DRBD sync rate parameters."""

    drbdconfigs = cc.drbdconfig.list()
    drbd = drbdconfigs[0]

    attributes = []
    if args.util is not None:
        attributes.append('link_util=%s' % args.util)
    if args.rtt_ms is not None:
        attributes.append('rtt_ms=%s' % args.rtt_ms)
    if len(attributes) > 0:
        attributes.append('action=apply')
    else:
        print "No options provided."
        return

    patch = utils.args_array_to_patch("replace", attributes)
    rwfields = ['link_util', 'rtt_ms', 'action']
    for pa in patch:
        key = pa['path'][1:]
        if key not in rwfields:
            raise exc.CommandError('Invalid or Read-Only attribute: %s' %
                                   pa['path'][1:])

    # Prevent update if controllers are mid-configuration
    personality = 'controller'
    is_config = False
    ihosts = cc.ihost.list_personality(personality=CONTROLLER)
    for ihost in ihosts:
        if ihost.config_target and \
            ihost.config_applied != ihost.config_target:
            is_config = True
            print("host %s is configuring ..." % (ihost.hostname))
    if is_config:
        print "Cannot apply update while controller configuration in progress."
        return

    try:
        drbd = cc.drbdconfig.update(drbd.uuid, patch)
    except exc.HTTPNotFound:
        raise exc.CommandError('DRBD Config not found: %s' % drbd.uuid)

    _print_drbdsync_show(drbd)

    # Wait for configuration to finish.
    wait_interval = 8
    configuration_timeout = 90
    do_wait = True
    LOOP_MAX = int(configuration_timeout / wait_interval)
    for x in range(0, LOOP_MAX):
        ihosts = cc.ihost.list_personality(personality=CONTROLLER)
        do_wait = False
        hosts = []
        for ihost in ihosts:
            if ihost.config_target and \
                ihost.config_applied != ihost.config_target:
                do_wait = True
                hosts.append(ihost.hostname)
        if do_wait:
            if x == 0:
                print("waiting for hosts: %s to finish configuring" %
                      ', '.join(hosts)),
                sys.stdout.flush()
            else:
                print ".",
                sys.stdout.flush()
            time.sleep(wait_interval)
        else:
            print
            print "DRBD configuration finished."
            break
    if do_wait:
        print "DRBD configuration timed out."