{"id":20282539,"url":"https://github.com/veops/cmdb-sdk-python","last_synced_at":"2025-04-11T08:07:32.881Z","repository":{"id":189855235,"uuid":"681444865","full_name":"veops/cmdb-sdk-python","owner":"veops","description":"python sdk  for veops cmdb","archived":false,"fork":false,"pushed_at":"2024-07-17T02:57:01.000Z","size":33,"stargazers_count":8,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-07-17T05:47:56.985Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/veops.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-22T03:12:26.000Z","updated_at":"2024-07-17T02:57:04.000Z","dependencies_parsed_at":"2024-07-17T05:54:59.547Z","dependency_job_id":null,"html_url":"https://github.com/veops/cmdb-sdk-python","commit_stats":null,"previous_names":["veops/cmdb-sdk-python"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/veops%2Fcmdb-sdk-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/veops%2Fcmdb-sdk-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/veops%2Fcmdb-sdk-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/veops%2Fcmdb-sdk-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/veops","download_url":"https://codeload.github.com/veops/cmdb-sdk-python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224632812,"owners_count":17343926,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T14:10:14.879Z","updated_at":"2024-11-14T14:10:15.638Z","avatar_url":"https://github.com/veops.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CMDB sdk for Python\n\n[中文](README_cn.md) / [English](READMEn.md)\n\n## build\n\nbuild and install\n\n```shell\n\u003e git clone https://github.com/veops/cmdb-sdk-python.git\n\u003e cd cmdb-sdk-python\n\n\u003e pip install build wheel setuptools  # requirements\n\u003e python -m build -n\n```\n\n**veops_cmdb-0.0.1-py3-none-any.whl** will be created at *cmdb-sdk-python/dist/*\n\n## tests\n\nbefore running tests, please make sure you have created the ci model book and rank,\nthey may looks like:\n\n```plain\nbook\n    id: int, unique\n    book_id: int, unique, not null\n    book_name: string, not null,\n    author: string\n\nrank:\n    id: int, unique\n    rank_id: int, unique, not null\n    rank: int, not null,\n```\n\nand you alse need to form relationship between book and rank, and then you can run tests.\n\n```shell\n\u003e pytest -s\n```\n\n## usage\n\nIf you can ensure the security of your account, you can set the following parameters to environment variables,\nthis way, you won't need to manually pass the initial parameters every time to set up the client.\n\n```plain\nCMDB_HOST=[your host]\nCMDB_KEY=[your_key]\nCMDB_SECRET=[your secret]\n```\n\n### 1.CI\n\n```python3\n\"\"\"\nsuppose a ci model is Book(id, book_id, book_name, author)\n\"\"\"\n\nimport os\n\nfrom cmdb.core.ci import CIClient, Option\n\n\nclass TestCI:\n\n    def setup_method(self) -\u003e None:\n        opt = Option(\n            os.environ[\"CMDB_HOST\"],\n            os.environ[\"CMDB_KEY\"],\n            os.environ[\"CMDB_SECRET\"],\n        )\n        self.client = CIClient(opt=opt)\n\n    def test_get(self):\n        resp = self.client.get_ci(q=\"_type:book\").result\n        print(\"get\")\n        print(resp)\n\n    def find_by_name(self, book_name: str):\n        q = f\"_type:book,book_name:{book_name}\"\n        resp = self.client.get_ci(q=q).result\n        if not resp:\n            return\n        return resp[0]\n\n    def test_add(self):\n        ci = {\n            \"id\": 1,\n            \"book_id\": 1,\n            \"book_name\": \"平凡的世界\",\n            \"author\": \"路遥\",\n        }\n        if self.find_by_name(\"平凡的世界\"):\n            return\n        resp = self.client.add_ci(\"book\", ci)\n        print(\"add\")\n        print(resp)\n\n    def test_update(self):\n        ci = self.find_by_name(\"平凡的世界\")\n        resp = self.client.update_ci(\"book\", ci_id=ci[\"_id\"], attrs={\"author\": \"yao.lu\"})\n        print(\"update\")\n        print(resp)\n\n    def test_delete(self):\n        ci = self.find_by_name(\"平凡的世界\")\n        resp = self.client.delete_ci(ci[\"_id\"])\n        print(\"delete\")\n        print(resp)\n\n```\n\n### 2.CIRelation\n\n```python3\n\"\"\"\nsuppose a CI model book with field id, name and author,\nsuppose a CI model rank with field rank_id, book_id, rank\n\"\"\"\n\n\nimport os\n\nfrom cmdb.core.ci import CIClient, Option\nfrom cmdb.core.ci_relations import CIRelationClient\n\n\nclass TestCI:\n\n    def setup_method(self) -\u003e None:\n        opt = Option(\n            os.environ[\"CMDB_HOST\"],\n            os.environ[\"CMDB_KEY\"],\n            os.environ[\"CMDB_SECRET\"],\n        )\n        self.ci_client = CIClient(opt=opt)\n        self.client = CIRelationClient(opt=opt)\n        self.add_ci()\n    \n    def add_ci(self):\n        book = {\n            \"id\": 1,\n            \"book_id\": 1,\n            \"book_name\": \"平凡的世界\",\n            \"author\": \"路遥\",\n        }\n        rank = {\n            \"id\": 1,\n            \"rank_id\": 1,\n            \"rank\": 5,\n        }\n        if not self.find_ci(q=\"_type:book,book_id:1\"):\n            self.ci_client.add_ci(\"book\", book)\n        if not self.find_ci(q=\"_type:rank,rank_id:1\"):\n            self.ci_client.add_ci(\"rank\", rank)\n\n    def find_ci(self, q: str):\n        resp = self.ci_client.get_ci(q=q).result\n        if not resp:\n            return\n        return resp[0]\n\n    def test_add_ci_relation(self):\n        book = self.find_ci(q=\"_type:book,book_id:1\")\n        rank = self.find_ci(q=\"_type:rank,rank_id:1\")\n        resp = self.client.add_ci_relation(book[\"_id\"], rank[\"_id\"])\n        print(\"add result\", resp)\n\n    def test_get_cli_relation(self):\n        book = self.find_ci(q=\"_type:book,book_id:1\")\n        resp = self.client.get_ci_relation(root_id=book[\"_id\"]).result\n        print(\"get result\", resp)\n\n    def test_delete_relation(self):\n        book = self.find_ci(q=\"_type:book,book_id:1\")\n        rank = self.find_ci(q=\"_type:rank,rank_id:1\")\n        resp = self.client.delete_ci_relation(src_ci_id=book[\"_id\"], dst_ci_id=rank[\"_id\"])\n        print(\"delete result\", resp)\n\n```\n\n## examples\n\nfor full usage examples, please visit [exmaples](./exmaples/) .\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fveops%2Fcmdb-sdk-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fveops%2Fcmdb-sdk-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fveops%2Fcmdb-sdk-python/lists"}