예제 #1
0
파일: demoApp.py 프로젝트: halsayed/calm
def main():
    blueprin_obj = compile_blueprint(__file__)
    print('blueprint compiled successfully... ')
    
    client = get_api_client()
    res, _ = create_blueprint(client, blueprin_obj, force_create=True)
    
    bp = res.json()
    bp_uuid = bp['metadata']['uuid']
    bp_name = bp['metadata']['name']
    bp_status = bp.get('status', {})
    bp_state = bp_status.get('state', 'DRAFT')
    print('Blueprint {} has state: {}'.format(bp_name, bp_state))

    if bp_state != 'ACTIVE':
        msg_list = bp_status.get('message_list', [])
        if not msg_list:
            print(f'Blueprint {bp_name} created with errors.')
            print(json.dumps(bp_status))
            sys.exit(-1)

        msgs = []
        for msg_dict in msg_list:
            msgs.append(msg_dict.get('message', ''))

        print(f'Blueprint {bp_name} created with {len(msg_list)} error(s): {msgs}')
        sys.exit(-1)

    print(f'Blueprint {bp_name}, uuid: {bp_uuid} created successfully.')
예제 #2
0
        def compile(cls, name=None, **kwargs):

            cls_substrate = common_helper._walk_to_parent_with_given_type(
                cls, "SubstrateType")
            account_uuid = (cls_substrate.get_referenced_account_uuid()
                            if cls_substrate else "")
            account_uuid = account_uuid or kwargs.get("account_uuid", "")
            if not account_uuid:
                LOG.error("Account uuid not found")
                sys.exit("Account not found for vm recovery point")

            vrs_uuid = kwargs.get("uuid", "")
            payload = {"filter": "account_uuid=={}".format(account_uuid)}
            if vrs_uuid:
                payload["filter"] += ";uuid=={}".format(vrs_uuid)
            else:
                payload["filter"] += ";name=={}".format(name)

            client = get_api_client()
            vrc_map = client.vm_recovery_point.get_name_uuid_map(payload)

            if not vrc_map:
                log_msg = "No recovery point found with " + (
                    "uuid='{}'".format(vrs_uuid)
                    if vrs_uuid else "name='{}'".format(name))
                LOG.error(log_msg)
                sys.exit("No recovery point found")

            # there will be single key
            vrc_name = list(vrc_map.keys())[0]
            vrc_uuid = vrc_map[vrc_name]

            if isinstance(vrc_uuid, list):
                LOG.error(
                    "Multiple recovery points found with name='{}'. Please provide uuid."
                    .format(vrc_name))
                LOG.debug("Found recovery point uuids: {}".format(vrc_uuid))
                sys.exit("Multiple recovery points found")

            return {
                "kind": "vm_recovery_point",
                "name": vrc_name,
                "uuid": vrc_uuid,
            }
예제 #3
0
파일: calm_ref.py 프로젝트: tuxtof/calm-dsl
        def compile(cls, name="", **kwargs):
            """cls = CalmRef object"""

            client = get_api_client()
            account_uuid = ""
            try:
                account_ref = cls.__parent__.attrs.get("account_reference", {})
                account_uuid = account_ref.get("uuid", "")
            except Exception as exp:
                pass

            vm_uuid = kwargs.get("uuid", "")

            if name:
                params = {"filter": "name=={}".format(name), "length": 250}
                res, err = client.account.vms_list(account_uuid, params)
                if err:
                    LOG.error(err)
                    sys.exit(-1)

                res = res.json()
                if res["metadata"]["total_matches"] == 0:
                    LOG.error("No vm with name '{}' found".format(name))
                    sys.exit(-1)

                elif res["metadata"]["total_matches"] > 1 and not vm_uuid:
                    LOG.error(
                        "Multiple vms with same name found. Please provide vm uuid"
                    )
                    sys.exit(-1)

                elif not vm_uuid:
                    vm_uuid = res["entities"][0]["status"]["uuid"]

            # TODO add valdiations on suppiled uuid
            vm_ref = {"uuid": vm_uuid, "kind": "vm"}

            # name is required parameter, else api will fail
            vm_ref["name"] = (name if name else "_VM_NAME_{}".format(
                str(uuid.uuid4())[:10]))

            return vm_ref