Exemplo n.º 1
0
def service_modify(args, manager, managernative):

    if args.servicedata is not None:
        service_description = json.loads(args.servicedata)
        if isinstance(service_description, dict):
            if service_description.has_key('properties'):
                if isinstance(service_description['properties'], dict):
                    service_properties = service_description['properties']
                else:
                    raise InputError("Invalid format of properties argument.")
            else:
                raise InputError(
                    "properties is required argument for this action")
        else:
            raise InputError("Invalid format of service argument.")
    else:
        raise InputError("service is required argument for this action.")

    current_service = find_service_by_arguments(manager, args.account,
                                                args.service, args.path)
    if current_service is None:
        raise Exception("Could not find service to be modified.")

    if current_service.properties is not None and len(
            current_service.properties) > 0:
        non_existing_props_list = list(
            set(service_properties.keys()) -
            set(map(lambda x: x.name, current_service.properties)))
        if len(non_existing_props_list) > 0:
            raise Exception("Non-existing property: " +
                            non_existing_props_list[0])
        else:
            for list_count in current_service.properties:
                if (service_properties.has_key(list_count.name)):
                    list_count.prop_string_value = service_properties[
                        list_count.name]

        if args.noresource:
            modify_service_result = managernative.modify_service_native(
                [current_service.to_xml_friendly_object()], False)
        else:
            modify_service_result = manager.modify_service(
                [current_service.to_xml_friendly_object()], args.account)

        if modify_service_result.has_key("ModifyServiceResult") and len(
                modify_service_result["ModifyServiceResult"]) == 1:
            for k in modify_service_result["ModifyServiceResult"]:
                modified_service = AtomiaService()
                modified_service.from_simplexml(k)
                modified_service.print_me(False, True)
                return modified_service
        else:
            raise Exception("Could not modify service: " +
                            current_service.name)
Exemplo n.º 2
0
def service_modify(args, manager, managernative):
    
    if args.servicedata is not None:
        service_description = json.loads(args.servicedata)
        if isinstance(service_description, dict):
            if service_description.has_key('properties'):
                if isinstance(service_description['properties'], dict):
                    service_properties = service_description['properties']
                else:
                    raise InputError("Invalid format of properties argument.")
            else:
                raise InputError("properties is required argument for this action")
        else:
            raise InputError("Invalid format of service argument.")
    else:
        raise InputError("service is required argument for this action.")
    
    current_service = find_service_by_arguments(manager, args.account, args.service, args.path)
    if current_service is None:
        raise Exception("Could not find service to be modified.")
    
    
    
    if current_service.properties is not None and len(current_service.properties) > 0:
        non_existing_props_list = list(set(service_properties.keys())-set(map(lambda x: x.name, current_service.properties)))
        if len(non_existing_props_list) > 0:
            raise Exception("Non-existing property: " + non_existing_props_list[0])
        else:
            for list_count in current_service.properties:
                if (service_properties.has_key(list_count.name)):
                    list_count.prop_string_value = service_properties[list_count.name]

        if args.noresource:
            modify_service_result = managernative.modify_service_native([current_service.to_xml_friendly_object()], False)
        else:
            modify_service_result = manager.modify_service([current_service.to_xml_friendly_object()], args.account)
        
        if modify_service_result.has_key("ModifyServiceResult") and len(modify_service_result["ModifyServiceResult"]) == 1:
            for k in modify_service_result["ModifyServiceResult"]:
                modified_service = AtomiaService()
                modified_service.from_simplexml(k)
                modified_service.print_me(False, True)
                return modified_service
        else:
            raise Exception("Could not modify service: " + current_service.name)
Exemplo n.º 3
0
def service_add(args, manager, managernative):
    if args.accountdata is not None:
        account_data = json.loads(args.accountdata)
    else:
        account_data = None

    if args.servicedata is not None:
        service_description = json.loads(args.servicedata)
        if isinstance(service_description, dict):
            if service_description.has_key('name'):
                service_name = service_description['name']
            else:
                raise InputError("service argument must contain key name")
            
            if service_description.has_key('properties'):
                if isinstance(service_description['properties'], dict):
                    service_properties = service_description['properties']
                else:
                    service_properties = None
            else:
                service_properties = None
        else:
            raise InputError("Invalid format of find_options argument.")
    else:
        raise InputError("service is required argument for this action.")
    
    parent_service = find_service_by_arguments(manager, args.account, args.parent, args.path)
    
    if parent_service is not None:
        created_service_result = manager.create_service(service_name, [parent_service.to_xml_friendly_object()], args.account)
    else:
        created_service_result = manager.create_service(service_name, None, args.account)
    
    if created_service_result.has_key("CreateServiceResult") and len(created_service_result["CreateServiceResult"]) == 1:
        for j in created_service_result["CreateServiceResult"]:
            created_service = AtomiaService()
            created_service.from_simplexml(j)
            
            if service_properties is not None and created_service.properties is not None and len(created_service.properties) > 0:
                for list_count in created_service.properties:
                    if (service_properties.has_key(list_count.name)):
                        if (service_properties[list_count.name] == 'null' or service_properties[list_count.name] == 'NULL'):
                            list_count.prop_string_value = None
                        else:
                            list_count.prop_string_value = service_properties[list_count.name] 

            if args.noresource:
                if args.packagedata is not None:
                    package_data = json.loads(args.packagedata)
                    if isinstance(package_data, dict) and package_data.has_key('package_id') and package_data.has_key('package_name'):
                            package_arg = [ AtomiaPackage(package_id=package_data['package_id'], package_name=package_data['package_name']).to_xml_friendly_object() ]
                    else:
                        raise InputError("packagedata argument must contain key package_id and package_name")
                else:
                    package_arg = None

                if args.resourcename is None:
                    raise Exception("When specifying --noresource you have to specify --resourcename as well")
                elif parent_service is not None:
                    add_service_result = managernative.add_service_native([created_service.to_xml_friendly_object()], [parent_service.to_xml_friendly_object()], args.resourcename, None, args.account, package_arg, False)
                else:
                    add_service_result = managernative.add_service_native([created_service.to_xml_friendly_object()], None, args.resourcename, None, args.account, package_arg, False)
            else:
                if parent_service is not None:
                    add_service_result = manager.add_service([created_service.to_xml_friendly_object()], [parent_service.to_xml_friendly_object()], args.account)
                else:
                    add_service_result = manager.add_service([created_service.to_xml_friendly_object()], None, args.account)
            
            if add_service_result.has_key("AddServiceResult") and len(add_service_result["AddServiceResult"]) == 1:
                for k in add_service_result["AddServiceResult"]:
                    added_service = AtomiaService()
                    added_service.from_simplexml(k)
                    added_service.print_me(args.filter, args.first, False, True)
                    return added_service
            else:
                raise Exception("Could not add service: " + created_service.name)
            
    else:
        raise Exception("Could not create service: " + service_name)
Exemplo n.º 4
0
def service_add(args, manager, managernative):
    if args.accountdata is not None:
        account_data = json.loads(args.accountdata)
    else:
        account_data = None

    if args.servicedata is not None:
        service_description = json.loads(args.servicedata)
        if isinstance(service_description, dict):
            if service_description.has_key('name'):
                service_name = service_description['name']
            else:
                raise InputError("service argument must contain key name")

            if service_description.has_key('properties'):
                if isinstance(service_description['properties'], dict):
                    service_properties = service_description['properties']
                else:
                    service_properties = None
            else:
                service_properties = None
        else:
            raise InputError("Invalid format of find_options argument.")
    else:
        raise InputError("service is required argument for this action.")

    parent_service = find_service_by_arguments(manager, args.account,
                                               args.parent, args.path)

    if parent_service is not None:
        created_service_result = manager.create_service(
            service_name, [parent_service.to_xml_friendly_object()],
            args.account)
    else:
        created_service_result = manager.create_service(
            service_name, None, args.account)

    if created_service_result.has_key("CreateServiceResult") and len(
            created_service_result["CreateServiceResult"]) == 1:
        for j in created_service_result["CreateServiceResult"]:
            created_service = AtomiaService()
            created_service.from_simplexml(j)

            if service_properties is not None and created_service.properties is not None and len(
                    created_service.properties) > 0:
                for list_count in created_service.properties:
                    if (service_properties.has_key(list_count.name)):
                        if (service_properties[list_count.name] == 'null' or
                                service_properties[list_count.name] == 'NULL'):
                            list_count.prop_string_value = None
                        else:
                            list_count.prop_string_value = service_properties[
                                list_count.name]

            if args.noresource:
                if args.packagedata is not None:
                    package_data = json.loads(args.packagedata)
                    if isinstance(package_data, dict) and package_data.has_key(
                            'package_id') and package_data.has_key(
                                'package_name'):
                        package_arg = [
                            AtomiaPackage(
                                package_id=package_data['package_id'],
                                package_name=package_data['package_name']).
                            to_xml_friendly_object()
                        ]
                    else:
                        raise InputError(
                            "packagedata argument must contain key package_id and package_name"
                        )
                else:
                    package_arg = None

                if args.resourcename is None:
                    raise Exception(
                        "When specifying --noresource you have to specify --resourcename as well"
                    )
                elif parent_service is not None:
                    add_service_result = managernative.add_service_native(
                        [created_service.to_xml_friendly_object()],
                        [parent_service.to_xml_friendly_object()],
                        args.resourcename, None, args.account, package_arg,
                        False)
                else:
                    add_service_result = managernative.add_service_native(
                        [created_service.to_xml_friendly_object()], None,
                        args.resourcename, None, args.account, package_arg,
                        False)
            else:
                if parent_service is not None:
                    add_service_result = manager.add_service(
                        [created_service.to_xml_friendly_object()],
                        [parent_service.to_xml_friendly_object()],
                        args.account)
                else:
                    add_service_result = manager.add_service(
                        [created_service.to_xml_friendly_object()], None,
                        args.account)

            if add_service_result.has_key("AddServiceResult") and len(
                    add_service_result["AddServiceResult"]) == 1:
                for k in add_service_result["AddServiceResult"]:
                    added_service = AtomiaService()
                    added_service.from_simplexml(k)
                    added_service.print_me(args.filter, args.first, False,
                                           True)
                    return added_service
            else:
                raise Exception("Could not add service: " +
                                created_service.name)

    else:
        raise Exception("Could not create service: " + service_name)