def __init__(self, **kwargs): """ :param kwargs: *region_name = region name of NeutronClient """ super().__init__(**kwargs) self._connection = NeutronClient(session=self.authentication.session, region_name=self.region_name)
def __init__(self, lease, key='default', image=DEFAULT_IMAGE, **extra): self.lease = lease self.session = self.lease.session self.neutron = NeutronClient( session=self.session, region_name=os.environ.get('OS_REGION_NAME')) self.nova = NovaClient('2', session=self.session, region_name=os.environ.get('OS_REGION_NAME')) self.glance = GlanceClient( '2', session=self.session, region_name=os.environ.get('OS_REGION_NAME')) self.ip = None self._fip = None self.image = resolve_image_idname(self.glance, image) net_ids = extra.pop('net_ids', None) net_name = extra.pop('net_name', None) if net_ids is None and net_name is not None: net_ids = [get_networkid_byname(self.neutron, net_name)] self.server_kwargs = instance_create_args(self.lease.reservation, key=key, image=self.image, net_ids=net_ids, **extra) self.server = self.nova.servers.create(**self.server_kwargs) self.id = self.server.id self.name = self.server.name
def _client(self) -> NeutronClient: if self._cached_client is None: keystone = KeystoneClient( auth_url=self.openstack_connector.auth_url, username=self.openstack_connector.username, password=self.openstack_connector.password, tenant_name=self.openstack_connector.tenant) neutron_endpoint = keystone.service_catalog.url_for( service_type="network", endpoint_type="publicURL") self._cached_client = NeutronClient(endpoint_url=neutron_endpoint, token=keystone.auth_token) return self._cached_client
def __init__(self, session, id=None, lease=None, key='default', image=DEFAULT_IMAGE, **extra): self.session = session self.neutron = NeutronClient( session=self.session, region_name=os.environ.get('OS_REGION_NAME')) self.nova = NovaClient('2', session=self.session, region_name=os.environ.get('OS_REGION_NAME')) self.glance = GlanceClient( '2', session=self.session, region_name=os.environ.get('OS_REGION_NAME')) self.image = resolve_image_idname(self.glance, image) self.ip = None self._fip = None self._fip_created = False self._preexisting = False extra.setdefault('_no_clean', False) self._noclean = extra.pop('_no_clean') net_ids = extra.pop('net_ids', None) net_name = extra.pop('net_name', None) if net_ids is None and net_name is not None: net_ids = [get_networkid_byname(self.neutron, net_name)] if id is not None: self._preexisting = True self.server = self.nova.servers.get(id) elif lease is not None: server_kwargs = instance_create_args(lease.reservations[0]['id'], key=key, image=self.image, net_ids=net_ids, **extra) self.server = self.nova.servers.create(**server_kwargs) # print('created instance {}'.format(self.server.id)) else: raise ValueError( "Missing required argument: 'id' or 'lease' required.") self.id = self.server.id self.name = self.server.name
def __init__(self, id=None, lease=None, key=None, image=DEFAULT_IMAGE, **kwargs): kwargs.setdefault("session", context.session()) self.session = kwargs.pop("session") self.neutron = NeutronClient(session=self.session) self.nova = NovaClient("2", session=self.session) self.glance = GlanceClient("2", session=self.session) self.image = resolve_image_idname(self.glance, image) self.flavor = resolve_flavor(self.nova, "baremetal") self.ip = None self._fip = None self._fip_created = False self._preexisting = False kwargs.setdefault("_no_clean", False) self._noclean = kwargs.pop("_no_clean") net_ids = kwargs.pop("net_ids", None) net_name = kwargs.pop("net_name", "sharednet1") if net_ids is None and net_name is not None: net_ids = [get_networkid_byname(self.neutron, net_name)] if id is not None: self._preexisting = True self.server = self.nova.servers.get(id) elif lease is not None: if key is None: key = Keypair().key_name server_kwargs = instance_create_args(lease.node_reservation, image=self.image, flavor=self.flavor, key=key, net_ids=net_ids, **kwargs) self.server = self.nova.servers.create(**server_kwargs) else: raise ValueError( "Missing required argument: 'id' or 'lease' required.") self.id = self.server.id self.name = self.server.name
def __init__(self, **kwargs): kwargs.setdefault("session", context.session()) self.session = kwargs.pop("session") self.blazar = BlazarClient("1", service_type="reservation", session=self.session) self.neutron = NeutronClient(session=self.session) self.lease = None self._servers = {} self._sequester = kwargs.pop("sequester", False) kwargs.setdefault("_preexisting", False) self._preexisting = kwargs.pop("_preexisting") kwargs.setdefault("_no_clean", False) self._noclean = kwargs.pop("_no_clean") prefix = kwargs.pop("prefix", "") rand = random_base32(6) self.prefix = f"{prefix}-{rand}" if prefix else rand kwargs.setdefault("name", self.prefix) if self._preexisting: self.id = kwargs["_id"] self.refresh() else: kwargs.setdefault("node_type", DEFAULT_NODE_TYPE) self._lease_kwargs = lease_create_nodetype(self.neutron, **kwargs) self.lease = self.blazar.lease.create(**self._lease_kwargs) self.id = self.lease["id"] self.name = self.lease["name"] self.reservations = self.lease["reservations"]
def init_session(): """Initialization of keystone session, glance, nova and neutron clients. Returns: tuple: glance_client, nova_client, neutron_client """ AUTH_URL = os.environ.get('OS_AUTH_URL') if not AUTH_URL: print("AUTH_URL must be set") sys.exit(1) PROJECT_DOMAIN_NAME = os.environ.get('OS_PROJECT_DOMAIN_NAME', 'default') USER_DOMAIN_NAME = os.environ.get('OS_USER_DOMAIN_NAME', 'default') PROJECT_NAME = os.environ.get('OS_PROJECT_NAME', 'admin') USERNAME = os.environ.get('OS_USERNAME', 'admin') PASSWORD = os.environ.get('OS_PASSWORD', 'password') auth = identity.v3.Password(auth_url=AUTH_URL, username=USERNAME, user_domain_name=USER_DOMAIN_NAME, password=PASSWORD, project_name=PROJECT_NAME, project_domain_name=PROJECT_DOMAIN_NAME) session = _session.Session(auth=auth) glance_client = GlanceClient(session=session) images = list(glance_client.images.list()) if not images: print("At least one image must exist") sys.exit(1) nova_client = NovaClient(version=2, session=session) neutron_client = NeutronClient(session=session, project_name=session.get_project_id()) return glance_client, nova_client, neutron_client
def _get_neutron_client(): sess = op_utils.get_session() neutron_client = NeutronClient(session=sess) return neutron_client
def _neutron(self) -> NeutronClient: return NeutronClient(session=self._os_session, insecure=True)
def neutron_client(self): return NeutronClient( session=self.keystone_session, connect_retries=2, )
def neutron(): return NeutronClient(session=session())
def neutron(self): endpoint = self.__make_endpoint( self._get_url_for_svc(service_type='network')) return NeutronClient(session=self.keystone_session, endpoint_override=endpoint)