Code Monkey home page Code Monkey logo

nifcloud-sdk-python's Introduction

NIFCLOUD SDK for Python

Test Documentation PyPI

The NIFCLOUD SDK for Python is data-driven SDK. It works by feeding AWS-SDK-compatible model JSONs to botocore module.

Features

  • ✔️ Full support for NIFCLOUD Computing / RDB / NAS / ESS / DNS / ObjectStorageService / ServiceActivity / DevOps with GitLab APIs
  • ✔️ The nifcloud package is the foundation for the NIFCLOUD CLI.
  • ✔️ AWS-SDK-compatible data-driven architecture

Requirements

  • Python 3.7 or later

How to Install

pip install nifcloud

Usage

Write your python program:

from nifcloud import session

client = session.get_session().create_client(
    "computing",
    region_name="jp-east-1",
    nifcloud_access_key_id="<Your NIFCLOUD Access Key ID>",
    nifcloud_secret_access_key="<Your NIFCLOUD Secret Access Key>"
)

print(client.describe_instances())

Execute the program:

$ python test.py

Credentials and region name can be also passed via environment variables.

from nifcloud import session

client = session.get_session().create_client("computing")
print(client.describe_instances())
$ export NIFCLOUD_ACCESS_KEY_ID=<Your NIFCLOUD Access Key ID>
$ export NIFCLOUD_SECRET_ACCESS_KEY=<Your NIFCLOUD Secret Access Key>
$ export NIFCLOUD_DEFAULT_REGION=jp-east-1
$ python test.py

See documentation for detail.

License

See LICENSE.txt.

nifcloud-sdk-python's People

Contributors

alice02 avatar aokumasan avatar fujita-hiroki1115 avatar fuku2014 avatar miyuush avatar o108minmin avatar sato-mh avatar sogokato avatar tily avatar tottoto avatar tunakyonn avatar yoshd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nifcloud-sdk-python's Issues

get_bucket_version2をコールするとParamValidationErrorになる

バージョン1.3.0
Python 3.10.2

サンプルコード

from nifcloud import session

client = session.get_session().create_client(
    "storage",
    region_name="jp-east-1",
    endpoint_url="https://jp-east-1.storage.api.nifcloud.com",
    nifcloud_access_key_id="xxx",
    nifcloud_secret_access_key="xxx",
)

result = client.get_bucket_version2(
    Bucket='bucket1'
)

print(result)

エラー内容

Traceback (most recent call last):
  File "/root/work/nifcloud_storage/test.py", line 17, in <module>
    result = client.get_bucket_version2(
  File "/root/.local/share/virtualenvs/nifcloud_storage-pwINQavl/lib/python3.10/site-packages/botocore/client.py", line 386, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/root/.local/share/virtualenvs/nifcloud_storage-pwINQavl/lib/python3.10/site-packages/botocore/client.py", line 677, in _make_api_call
    request_dict = self._convert_to_request_dict(
  File "/root/.local/share/virtualenvs/nifcloud_storage-pwINQavl/lib/python3.10/site-packages/botocore/client.py", line 725, in _convert_to_request_dict
    request_dict = self._serializer.serialize_to_request(
  File "/root/.local/share/virtualenvs/nifcloud_storage-pwINQavl/lib/python3.10/site-packages/botocore/validate.py", line 337, in serialize_to_request
    raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:
Missing required parameter in input: "ListType"

get_bucket は問題ないようです、ただ非推奨っぽいので get_bucket_version2 を使えるようにしていただけると助かります。

Failure: nifcloud-debugcli rdb modify-db-parameter-group (Client.InvalidParameterRequired.ParameterName)

ISSUE TYPE
  • Bug Report
SUMMARY

nifcloud-debugcli を利用して、RDBのmodify-db-parameter-groupを操作すると、 Client.InvalidParameterRequired.ParameterName のエラーになってしまいます。

STEPS TO REPRODUCE
$ nifcloud-debugcli rdb modify-db-parameter-group \
    --db-parameter-group-name test57 \
    --parameters RequestParameter={"ParameterName='general_log', ParameterValue='1', ApplyMethod='immediate'"}

An error occurred (Client.InvalidParameterRequired.ParameterName) when calling the ModifyDBParameterGroup operation: Parameter name cannot be empty

--debug を付けてリクエストを確認してみると、

Making request for OperationModel(name=ModifyDBParameterGroup) (verify_ssl=True) with params: {'url_path': '/', 'query_string': '', 'method': 'POST', 'headers': {'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8', 'User-Agent': 'nifcloud-debugcli/0.1.4 Python/3.6.3 Linux/3.10.0-229.el7.x86_64 botocore/1.9.16'}, 'body': {'Action': 'ModifyDBParameterGroup', 'Version': '2013-05-15N2013-12-16', 'DBParameterGroupName': 'test57', 'Parameters.Parameter.member.1.ParameterName': 'general_log', 'Parameters.Parameter.member.1.ParameterValue': '1', 'Parameters.Parameter.member.1.ApplyMethod': 'immediate'}, 'url': 'https://rdb.jp-east-1.api.cloud.nifty.com/', 'context': {'client_region': 'jp-east-1', 'client_config': <botocore.config.Config object at 0x7fd80704e6a0>, 'has_streaming_input': False, 'auth_type': None}}

となっており、 Parameters.Parameter.member.1.ParameterName のようにリクエストしていることを確認しました。

公式ドキュメントを確認すると、これは Parameters.Parameter.1.ParameterName のようにリクエストするのが正しい認識です。(ApplyMethodやParameterValueも同様)
https://cloud.nifty.com/api/rdb/ModifyDBParameterGroup.htm

RDBのリクエスト生成部分について、ご確認いただけないでしょうか。

オブストの put_object でディレクトリを指定すると SignatureDoesNotMatch

成功

from nifcloud import session

client = session.get_session().create_client(
    "storage",
    region_name="jp-east-1",
    endpoint_url="https://jp-east-1.storage.api.nifcloud.com",
    nifcloud_access_key_id="xxxx",
    nifcloud_secret_access_key="xxxx",
)

result = client.put_object(
    Body='/tmp/test.py',
    Bucket='your-bucket-name',
    Object='test.py',
)

print(result)

失敗 (SignatureDoesNotMatch)

from nifcloud import session

client = session.get_session().create_client(
    "storage",
    region_name="jp-east-1",
    endpoint_url="https://jp-east-1.storage.api.nifcloud.com",
    nifcloud_access_key_id="xxxx",
    nifcloud_secret_access_key="xxxx",
)

result = client.put_object(
    Body='/tmp/test.py',
    Bucket='your-bucket-name',
    Object='dir/test.py',
)

print(result)

対応方法あれば教えて下さい。

また https://nifcloud-sdk-python.readthedocs.io/en/latest/reference/services/storage.html から https://pfs.nifcloud.com/api/object-storage-service/ への各種リンクが NotFound になっているようです。右上の Edit on GitHub の rst へのリンクもないようです。

Failure: nifcloud-debugcli computing upload-ssl-certificate ([Errno 2] No such file or directory)

Issue type

Bug report

Summary

  • nifcloud-debugcli でcomputingのupload-ssl-certificateで --ca オプションを指定すると、証明書バンドルのオプションとして扱われ(おそらく --ca-bundle と同様に扱われる)、CA証明書をアップロードできない

Step to reproduce

$ nifcloud-debugcli computing upload-ssl-certificate --ca <Your CA string> --certificate <Your Certificate string> --key <Your Key string> --debug
※省略
2018-07-22 20:48:57,500 - MainThread - botocore.endpoint - DEBUG - Making request for OperationModel(name=UploadSslCertificate) (verify_ssl=<Your CA string>) with params: ※省略
[Errno 2] No such file or directory
  • --debug オプションを指定して確認すると、 verify_ssl に --ca で指定した文字列が指定されていることがわかり、 --ca-bundle オプションを指定した場合と同様になる
  • おそらく --ca-bundle と同様に指定された値をファイルパスとして探すため [Errno 2] No such file or directory となっている

Expected behavior

  • --ca オプションで指定したCA証明書がアップロードされる
$ nifcloud-debugcli computing upload-ssl-certificate --ca <Your CA string> --certificate <Your Certificate string> --key <Your Key string>
{
    "Fqdn": "hoge.example.com",
    "FqdnId": "0000",
    "RequestId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}

RDB と NAS の日付フォーマットが SDK と異なる

概要

  • RDB と NAS の日付フォーマットが SDK のものと異なるため、正常にリクエストできない
    • SDK: %Y-%m-%dT%H:%M:%SZ
    • RDB/NAS: %Y-%m-%d %H:%M

暫定対処方法

  • RDB/NAS へのリクエスト前に下記を指定する
import botocore


botocore.serialize.ISO8601 = '%Y-%m-%d %H:%M'
botocore.serialize.ISO8601_MICRO = '%Y-%m-%d %H:%M:%S.%fZ'

Failure: nifcloud-debugcli nas get-metric-statistics (invalid literal for int() with base 10)

Issue type

  • Bug report

Summary

  • nifcloud-debugcli でnasのget-metric-statisticsを実行するとエラーになる
  • 恐らく想定している型(Integer)と返ってきている型(Double)が異なると思われる

Step to reproduce

$ nifcloud-debugcli nas get-metric-statistics --start-time 2021-08-24T16:25:00Z --dimensions Name=NASInstanceIdentifier,Value=jpe12maeda03 --metric-name FreeStorageSpace

invalid literal for int() with base 10: '1038077673472.0'

Expected behavior

  • 指定したNASの残り容量が返ってくる

Details

  • get-metric-statistics に関しては以下の定義がマッチしてないように見える
  • "shape": "Integer" -> "shape": "Double" にしたら動作するようになった
    • 自分のケースでしか見ていないので、もしかしたら他のメトリックを指定するとIntergerが返ってくるのかもしれないが未確認
$ nifcloud-debugcli nas get-metric-statistics --start-time 2021-08-24T16:25:00Z --dimensions Name=NASInstanceIdentifier,Value=jpe12maeda03 --metric-name FreeStorageSpace
{
    "Datapoints": [
        {
            "SampleCount": 1,
            "Sum": 1033608298496.0,
            "TargetName": "jpe12maeda03",
            "Timestamp": "2021-08-24T16:25:52+09:00"
        }
    ],
    "Label": "FreeStorageSpace"
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.