Exemple #1
0
    def test_configured_api_version(self, mock_open, mock_login):
        json_config_content = u"""{
          "ip": "172.16.102.59",
          "api_version": 1000,
          "credentials": {
            "userName": "******",
            "authLoginDomain": "",
            "password": ""
          }
        }"""
        mock_open.return_value = self.__mock_file_open(json_config_content)
        oneview_client = OneViewClient.from_json_file("config.json")

        self.assertEqual(1000, oneview_client.connection._apiVersion)
        self.assertEqual(1000, oneview_client.api_version)
Exemple #2
0
    def setUp(self, mock_login):
        super(OneViewClientTest, self).setUp()

        config = {
            "ip": "172.16.102.59",
            "api_version": 800,
            "proxy": "127.0.0.1:3128",
            "credentials": {
                "authLoginDomain": "",
                "userName": "******",
                "password": ""
            }
        }

        self._oneview = OneViewClient(config)
    def test_raise_error_invalid_proxy(self):
        config = {"ip": "172.16.102.59",
                  "api_version": 800,
                  "proxy": "3128",
                  "credentials": {
                      "authLoginDomain": "",
                      "userName": "******",
                      "password": ""}}

        try:
            OneViewClient(config)
        except ValueError as e:
            self.assertTrue("Proxy" in e.args[0])
        else:
            self.fail()
Exemple #4
0
    def test_from_full_environment_variables_with_sessionID(
            self, mock_set_proxy, mock_login):
        oneview_client = OneViewClient.from_environment_variables()

        mock_login.assert_called_once_with(
            dict(userName='******',
                 password='******',
                 authLoginDomain='',
                 sessionID='123'))
        mock_set_proxy.assert_called_once_with('172.16.100.195', 9999)

        self.assertEqual(201, oneview_client.connection._apiVersion)
        self.assertEqual(
            oneview_client.create_image_streamer_client().connection.get_host(
            ), OS_ENVIRON_CONFIG_FULL_WITH_SESSIONID[
                'ONEVIEWSDK_IMAGE_STREAMER_IP'])
Exemple #5
0
    def test_from_json_file_with_sessionID(self, mock_open, mock_login):
        json_config_content = u"""{
          "ip": "172.16.102.59",
          "api_version": 800,
          "credentials": {
            "userName": "******",
            "authLoginDomain": "",
            "password": "",
            "sessionID": "123"
          }
        }"""
        mock_open.return_value = self.__mock_file_open(json_config_content)
        oneview_client = OneViewClient.from_json_file("config.json")

        self.assertIsInstance(oneview_client, OneViewClient)
        self.assertEqual("172.16.102.59", oneview_client.connection.get_host())
from pprint import pprint
from hpeOneView.oneview_client import OneViewClient
from config_loader import try_load_from_file

config = {
    "ip": "<oneview_ip>",
    "credentials": {
        "userName": "******",
        "password": "******"
    },
    "api_version": "<api_version>"
}

# Try load config from a file (if there is a config file)
config = try_load_from_file(config)
oneview_client = OneViewClient(config)
profile_templates = oneview_client.server_profile_templates

# Dependency resources
hardware_types = oneview_client.server_hardware_types
enclosure_groups = oneview_client.enclosure_groups
scopes = oneview_client.scopes
ethernet_networks = oneview_client.ethernet_networks

# These variables must be defined according with your environment
server_profile_name = "ProfileTemplate-1"
hardware_type_name = "SY 480 Gen9 1"
enclosure_group_name = "EG"
hardware_type_for_transformation = "SY 480 Gen9 2"
enclosure_group_for_transformation = "EG-2"
scope_name = "SampleScope"
Exemple #7
0
def main():
    global smhost, smhead, oneview_client

    if amqp.VERSION < (2, 1, 4):
        print("WARNING: This script has been tested only with amqp 2.1.4, "
              "we cannot guarantee that it will work with a lower version.\n")

    parser = argparse.ArgumentParser(add_help=True, description='Usage')
    parser.add_argument('-a',
                        '--appliance',
                        dest='host',
                        required=True,
                        help='HPE OneView Appliance hostname or IP')
    parser.add_argument('-u',
                        '--user',
                        dest='user',
                        required=False,
                        default='Administrator',
                        help='HPE OneView Username')
    parser.add_argument('-p',
                        '--pass',
                        dest='passwd',
                        required=True,
                        help='HPE OneView Password')
    parser.add_argument('-r',
                        '--route',
                        dest='route',
                        required=False,
                        default='scmb.alerts.#',
                        help='AMQP Routing Key')
    parser.add_argument('-g',
                        '--gen',
                        dest='gen',
                        required=False,
                        action='store_true',
                        help='Generate the Rabbit MQ keypair and exit')
    parser.add_argument('-d',
                        '--download',
                        dest='down',
                        required=False,
                        action='store_true',
                        help='Download the required keys and certs then exit')
    parser.add_argument('-s',
                        '--sm',
                        dest='sm',
                        required=True,
                        help='Service Manager Appliance hostname or IP')
    parser.add_argument('-i',
                        '--id',
                        dest='id',
                        required=True,
                        help='Service Manager Username')
    parser.add_argument('-x',
                        '--spass',
                        dest='spass',
                        required=False,
                        default='',
                        help='Service Manager Password')
    parser.add_argument('-l',
                        '--list',
                        dest='lst',
                        required=False,
                        action='store_true',
                        help='List all Service Manager incidents and exit')
    args = parser.parse_args()
    smcred = args.id + ':' + args.spass
    userAndPass = b64encode(str.encode(smcred)).decode('ascii')
    smhead = {
        'Content-Type': 'application/json;charset=utf-8',
        'Authorization': 'Basic %s' % userAndPass
    }
    smhost = args.sm + ':13080'

    if args.lst:
        get_incidents()
        sys.exit()

    config = {
        "ip": args.host,
        "credentials": {
            "userName": args.user,
            "password": args.passwd
        }
    }

    oneview_client = OneViewClient(config)
    acceptEULA(oneview_client)

    # Generate the RabbitMQ keypair (only needs to be done one time)
    if args.gen:
        genRabbitCa(oneview_client)
        sys.exit()

    if args.down:
        getCertCa(oneview_client)
        getRabbitKp(oneview_client)
        sys.exit()

    recv(args.host, args.route)
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###

import os
from pprint import pprint
from hpeOneView.oneview_client import OneViewClient

EXAMPLE_CONFIG_FILE = os.path.join(os.path.dirname(__file__), '../config.json')

oneview_client = OneViewClient.from_json_file(EXAMPLE_CONFIG_FILE)
image_streamer_client = oneview_client.create_image_streamer_client()
deployment_plans = image_streamer_client.deployment_plans

# To run this example set a valid Build Plan URI
deployment_plan_information = {
    "name": "Demo Deployment Plan",
    "description": "",
    "hpProvided": "false",
    "oeBuildPlanURI": "/rest/build-plans/134b7e3f-4305-47c4-8d15-44d265697bf0",
}

if oneview_client.api_version >= 500:
    deployment_plan_information["type"] = "OEDeploymentPlanV5"

# Create a Deployment Plan
Exemple #9
0
def main():
    if amqp.VERSION < (2, 1, 4):
        print("WARNING: This script has been tested only with amqp 2.1.4, "
              "we cannot guarantee that it will work with a lower version.\n")

    parser = argparse.ArgumentParser(add_help=True, description='Usage')
    parser.add_argument('-a',
                        '--appliance',
                        dest='host',
                        required=True,
                        help='HPE OneView Appliance hostname or IP')
    parser.add_argument('-u',
                        '--user',
                        dest='user',
                        required=False,
                        default='Administrator',
                        help='HPE OneView Username')
    parser.add_argument('-p',
                        '--pass',
                        dest='passwd',
                        required=True,
                        help='HPE OneView Password')
    parser.add_argument('-r',
                        '--route',
                        dest='route',
                        required=False,
                        default='scmb.alerts.#',
                        help='AMQP Routing Key')
    parser.add_argument('-g',
                        '--gen',
                        dest='gen',
                        required=False,
                        action='store_true',
                        help='Generate the Rabbit MQ keypair and exit')
    parser.add_argument('-d',
                        '--download',
                        dest='down',
                        required=False,
                        action='store_true',
                        help='Download the required keys and certs then exit')
    args = parser.parse_args()
    config = {
        "ip": args.host,
        "credentials": {
            "userName": args.user,
            "password": args.passwd
        }
    }

    oneview_client = OneViewClient(config)
    acceptEULA(oneview_client)

    # Generate the RabbitMQ keypair (only needs to be done one time)
    if args.gen:
        genRabbitCa(oneview_client)
        sys.exit()

    if args.down:
        getCertCa(oneview_client)
        getRabbitKp(oneview_client)
        sys.exit()

    recv(args.host, args.route)
Exemple #10
0
from hpeOneView.oneview_client import OneViewClient
from hpeOneView.exceptions import HPEOneViewException
from config_loader import try_load_from_file
from pprint import pprint

config = {
    "ip": "<oneview_ip>",
    "credentials": {
        "userName": "******",
        "password": "******"
    }
}

# Try load config from a file (if there is a config file)
config = try_load_from_file(config)
oneview_client = OneViewClient.from_json_file('config.json')
storage_systems = oneview_client.storage_systems
storage_pools = oneview_client.storage_pools
scopes = oneview_client.scopes

# Find or add storage system
print("Find or add storage system")
s_systems = storage_systems.get_all()
if s_systems:
    s_system_data = s_systems[0]
    s_system = storage_systems.get_by_uri(s_system_data["uri"])
    storage_system_added = False
    print("Found storage system '{}' at uri: {}".format(
        s_system.data['name'], s_system.data['uri']))
else:
    options = {